Issuu on Google+

/** EasyVR Tester

Dump contents of attached EasyVR module and exercise it with playback and recognition.

Serial monitor can be used to send a few basic commands: 'c' - cycles through available command groups 'b' - cycles through built-in word sets 's123.' - play back sound 123 if available (or beep)

With EasyVR Shield, the green LED is ON while the module is listening (using pin IO1 of EasyVR). Successful recognition is acknowledged with a beep. Details are displayed on the serial monitor window.

** Example code for the EasyVR library v1.0 Written in 2011 by RoboTech srl for VeeaR <http:://www.veear.eu>

To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.

You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>. */


#if defined(ARDUINO) && ARDUINO >= 100 #include "Arduino.h" #include "SoftwareSerial.h" SoftwareSerial port(12,13); #else // Arduino 0022 - use modified NewSoftSerial #include "WProgram.h" #include "NewSoftSerial.h" NewSoftSerial port(12,13); #endif

#include "EasyVR.h"

EasyVR easyvr(port);

int8_t set = 0; int8_t group = 0; uint32_t mask = 0; uint8_t train = 0; char name[32]; bool useCommands = true;

EasyVRBridge bridge;

void setup() { // bridge mode? if (bridge.check()) { cli();


bridge.loop(0, 1, 12, 13); } // run normally Serial.begin(9600); port.begin(9600);

if (!easyvr.detect()) { Serial.println("EasyVR not detected!"); for (;;); }

easyvr.setPinOutput(EasyVR::IO1, LOW); Serial.println("EasyVR detected!"); easyvr.setTimeout(5); easyvr.setLanguage(EasyVR::ITALIAN);

int16_t count = 0;

Serial.print("Sound table: "); if (easyvr.dumpSoundTable(name, count)) { Serial.println(name); Serial.print("Sound entries: "); Serial.println(count); } else Serial.println("n/a");


if (easyvr.getGroupMask(mask)) { uint32_t msk = mask; for (group = 0; group <= EasyVR::PASSWORD; ++group, msk >>= 1) { if (!(msk & 1)) continue; if (group == EasyVR::TRIGGER) Serial.print("Trigger: "); else if (group == EasyVR::PASSWORD) Serial.print("Password: "); else { Serial.print("Group "); Serial.print(group); Serial.print(": "); } count = easyvr.getCommandCount(group); Serial.println(count); for (int8_t idx = 0; idx < count; ++idx) { if (easyvr.dumpCommand(group, idx, name, train)) { Serial.print(idx); Serial.print(" = "); Serial.print(name); Serial.print(", Trained "); Serial.print(train, DEC); if (!easyvr.isConflict()) Serial.println(" times, OK");


else { int8_t confl = easyvr.getWord(); if (confl >= 0) Serial.print(" times, Similar to Word "); else { confl = easyvr.getCommand(); Serial.print(" times, Similar to Command "); } Serial.println(confl); } } } } } group = 0; mask |= 1; // force to use trigger useCommands = (mask != 1); }

const char* ws0[] = { "ROBOT", }; const char* ws1[] = { "ACTION", "MOVE",


"TURN", "RUN", "LOOK", "ATTACK", "STOP", "HELLO", }; const char* ws2[] = { "LEFT", "RIGHT", "UP", "DOWN", "FORWARD", "BACKWARD", }; const char* ws3[] = { "ZERO", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE", "TEN",


}; const char** ws[] = { ws0, ws1, ws2, ws3 };

bool checkMonitorInput() { if (Serial.available() <= 0) return false;

// check console commands int16_t rx = Serial.read(); if (rx == 'b') { useCommands = false; set++; if (set > 3) set = 0; } if (rx == 'c') { useCommands = true; do { group++; if (group > EasyVR::PASSWORD) group = 0; } while (!((mask >> group) & 1)); } if (rx == 's') {


int16_t num = 0; delay(5); while ((rx = Serial.read()) >= 0) { if (isdigit(rx)) num = num * 10 + (rx - '0'); else break; delay(5); } if (rx == '.') { easyvr.stop(); easyvr.playSound(num, EasyVR::VOL_DOUBLE); } } if (rx >= 0) { easyvr.stop(); Serial.flush(); return true; } return false; }

void loop() { checkMonitorInput();


easyvr.setPinOutput(EasyVR::IO1, HIGH); // LED on (listening) if (useCommands) { Serial.print("Say a command in Group "); Serial.println(group); easyvr.recognizeCommand(group); } else { Serial.print("Say a word in Wordset "); Serial.println(set); easyvr.recognizeWord(set); }

do { if (checkMonitorInput()) return; } while (!easyvr.hasFinished());

easyvr.setPinOutput(EasyVR::IO1, LOW); // LED off

int16_t idx = easyvr.getWord(); if (idx >= 0) { Serial.print("Word: "); Serial.print(easyvr.getWord()); Serial.print(" = ");


if (useCommands) Serial.println(ws[group][idx]); else Serial.println(ws[set][idx]); // ok, let's try another set set++; if (set > 3) set = 0; easyvr.playSound(0, EasyVR::VOL_FULL); } else { idx = easyvr.getCommand(); if (idx >= 0) { Serial.print("Command: "); Serial.print(easyvr.getCommand()); if (easyvr.dumpCommand(group, idx, name, train)) { Serial.print(" = "); Serial.println(name); } else Serial.println(); // ok, let's try another group do { group++; if (group > EasyVR::PASSWORD)


group = 0; } while (!((mask >> group) & 1)); easyvr.playSound(0, EasyVR::VOL_FULL); } else // errors or timeout { if (easyvr.isTimeout()) Serial.println("Timed out, try again..."); int16_t err = easyvr.getError(); if (err >= 0) { Serial.print("Error "); Serial.println(err, HEX); } } } }


Using the GPS module: To use, simply create an instance of an object like this: #include "TinyGPS.h" TinyGPS gps; /*Feed the object serial NMEA data one character at a time using the encode() method. (TinyGPS does not handle retrieving serial data from a GPS unit.) When encode() returns “true”, a valid sentence has just changed the TinyGPS object’s internal state. For example: */ #define RXPIN 3 #define TXPIN 2 SoftwareSerial nss(RXPIN, TXPIN); void loop() { while (nss.available()) { int c = nss.read(); if (gps.encode(c)) { // process new gps info here } } } /* You can then query the object to get various tidbits of data. To test whether the data returned is stale, examine the (optional) parameter “fix_age” which returns the number of milliseconds since the data was encoded. long lat, lon; unsigned long fix_age, time, date, speed, course; unsigned long chars; unsigned short sentences, failed_checksum; */ // retrieves +/- lat/long in 100000ths of a degree gps.get_position(&lat, &lon, &fix_age); // time in hhmmsscc, date in ddmmyy gps.get_datetime(&date, &time, &fix_age); // returns speed in 100ths of a knot speed = gps.speed(); // course in 100ths of a degree course = gps.course();


/* Filename: GSM_HTTP.ino * Author: Sam Albuquerque * Description: Sketch to periodically upload GPS data over GPRS * to remote Server via HTTP connection * used with Arduino Mega */ #include "GM862.h" #include <SPI.h> #define GSMPin 7 #define baud 9600

//Pin 7 is the Power Pin for our shield

//Class to handle the GPS part of the shield. class GPS { public: GPS(int ledPin); char coordinate[23]; //DDMM.SSSSN,DDDMM.SSSSW boolean gpsState; void getGPS(); long time; private: int gpsLed;

//HHMMSS

UTC time

//PIN Number for GPS LED

};

GPS::GPS(int ledPin){ gpsLed=ledPin; pinMode(ledPin, OUTPUT); digitalWrite(ledPin,LOW); gpsState = false; time=0; } void GPS::getGPS(){ char gps_data_buffer[7]; char command_result; byte high_Byte; int i; byte GPGGA; SPI.begin(); SPI.setDataMode((0<<CPOL) | (1 << CPHA) |(1<<SPI2X)); delay(1000); GPGGA=0; i=0; do { digitalWrite(SS, LOW); if(high_Byte == 1){ command_result=SPI.transfer(0xA7);


high_Byte = 0; } else { command_result=SPI.transfer(0xB4); high_Byte = 1; } for(int index=0; index<6; index++){ gps_data_buffer[index] = gps_data_buffer[index + 1]; } gps_data_buffer[6] = command_result; if((gps_data_buffer[0] == '$') && (gps_data_buffer[1] == 'G') && (gps_data_buffer[2] == 'P') && (gps_data_buffer[3] == 'G') && (gps_data_buffer[4] =='G') && (gps_data_buffer[5] == 'A')) { GPGGA = 1; //We found a $GPGGA Sentence } if((GPGGA == 1) && (i < 80 )) { if(gps_data_buffer[0] == 0x0D) { //Sentence ends with 0x0D(Return) Character i = 80; GPGGA = 0; } else { if(i>=7 && i<13){ //Characters 7-12 are UTC Time String time = ((time*10) + (int(gps_data_buffer[0]) - 48))%1000000; } if(i>=18 && i<27){ //Characters 18-26 are Latitude coordinate[i-18]=gps_data_buffer[0]; } if(i==28) coordinate[9]=gps_data_buffer[0]; N or S Hemisphere

//Character 28 is either

if(i==29) coordinate[10]=','; if(i>=30 && i<40){ //Characters 30 to 39 are Longitude coordinate[i-19]=gps_data_buffer[0]; } if(i==41) coordinate[21]=gps_data_buffer[0]; i++; }

//Character 41 is either E or W Hemisphere

} digitalWrite(SS, HIGH); } while (i<80); if((coordinate[0]) == ','){ gpsState=false; //GPS Position Not Found } else { gpsState=true; //GPS Position Found coordinate[22]='\0'; //Valid String ends with Null Character. } digitalWrite(gpsLed, gpsState); return; } GPS gps(9);

//Pin 9 is used to control the GPS LED.


char PIN[5] = "0000"; GM862 modem(&Serial, GSMPin, PIN);

// replace this with your SIM PIN // Our shield communicates over default

Serial char cmd; long lastTime=0;

// command read from terminal

void setup() { Serial.begin(9600); Serial.println("GM862 monitor"); modem.switchOn(); delay(4000); modem.init(); modem.version(); while (!modem.isRegistered()) { delay(1000); modem.checkNetwork(); }

// // // //

switch the modem on wait for the modem to boot initialize the GSM part of Module request modem version info

// check the network availability

}

void requestHTTP() { char buf[100]; byte i = 0; modem.initGPRS(); modem.enableGPRS(); modem.openHTTP("IP.AD.RE.SS"); target's IP

// setup of GPRS context // switch GPRS on // Replace IP.AD.RE.SS with your

// or domain name modem.send("GET /location.php?time="); //Connects to location.php on Server Serial.print(gps.time); //Passes UTC Time modem.send("&loc="); // and modem.send(gps.coordinate); //GPS coordinates modem.send(" HTTP/1.1\r\n"); //Completes HTTP GET Request modem.send("HOST: IP.AD.RE.SS \r\n"); //write on the socket modem.send("\r\n"); //Completes the HTTP Connection delay(1000); while (i++ < 10) { // try to read for 10s modem.receive(buf); // read from the socket, timeout 1s if (strlen(buf) > 0) { // we received something i--; // reset the timeout } } modem.disableGPRS(); // switch GPRS off }

void loop() { gps.getGPS(); if(gps.gpsState==true){ if(gps.time-lastTime > 100){

//if posted more than a minute ago


requestHTTP(); lastTime=gps.time; delay(5000); } } else { Serial.println("0"); } }

// do a HTTP request //Store the last update time

//Prints 0 if GPS fix not received.


// SpeakJetTTS Hello World sketch // a demo showing a minimal sketch for the SpeakJet/TTS Shield // written by Galen Raben / www.droidbuilder.com

// set up a new software serial port #include <SoftwareSerial.h> //rxPin: the pin on which to receive serial data //txPin: the pin on which to transmit serial data //busyPin: the pin used to monitor SpeakJet Busy line // SpeakJet Shield v1.0-1.2 uses these pins: //#define txPin 2 //#define rxPin 3 // SpeakJet Shield v1.3 or later uses these pins: #define rxPin 5 #define txPin 6 SoftwareSerial sjSerial = SoftwareSerial(rxPin, txPin); void setup(){ // initialize the serial communications with the SpeakJet-TTS256 pinMode(rxPin, INPUT); pinMode(txPin, OUTPUT); sjSerial.begin(9600);// set the data rate for the SoftwareSerial port delay(1000); // wait a second for the Arduino resets to finish (speaks "ready") sjSerial.println("Hello world!"); // send it to the SpeakJet } void loop() {}


gpscode