Greetings,
I'm actually new to arduino and yet trying to find my away along. What I'm trying to do here is using an EASYVR shield mounted on arduino uno to recieve the sound command.
Then I want this command be transfered to another arduino serially to be actioned with the other arduino. I know this might be redundunt but the idea is through using an xBee modules to link both arduinos but I want to ensure that they can serially work in case xBees are down.
So for the first part, thanks to EasyVR I got things running: I made this little change to the code so it appears like this:
#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);
//Groups and Commands
enum Groups
{
GROUP_0 = 0,
GROUP_1 = 1,
};
enum Group0
{
G0_GO_SMART = 0,
};
enum Group1
{
G1_LED_ON = 0,
G1_LED_OFF = 1,
G1_LED_DIMMER = 2,
};
EasyVRBridge bridge;
int8_t group, idx;
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(3);
group = EasyVR::TRIGGER; //<-- start group (customize)
pinMode(11, OUTPUT);
digitalWrite(11, LOW); // set the LED off
}
void action();
void loop()
{
easyvr.setPinOutput(EasyVR::IO1, HIGH); // LED on (listening)
Serial.print("Say a command in Group ");
Serial.println(group);
easyvr.recognizeCommand(group);
do
{
// can do some processing while waiting for a spoken command
}
while (!easyvr.hasFinished());
easyvr.setPinOutput(EasyVR::IO1, LOW); // LED off
idx = easyvr.getWord();
if (idx >= 0)
{
// built-in trigger (ROBOT)
// group = GROUP_X; <-- jump to another group X
return;
}
idx = easyvr.getCommand();
if (idx >= 0)
{
// print debug message
uint8_t train = 0;
char name[32];
Serial.print("Command: ");
Serial.print(idx);
if (easyvr.dumpCommand(group, idx, name, train))
{
Serial.print(" = ");
Serial.println(name);
}
else
Serial.println();
easyvr.playSound(0, EasyVR::VOL_FULL);
// perform some action
action();
}
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);
}
group = GROUP_0;
}
}
void action()
{
switch (group)
{
case GROUP_0:
switch (idx)
{
case G0_GO_SMART:
// write your action code here
group = GROUP_1; //<-- or jump to another group X for composite commands
break;
}
break;
case GROUP_1:
switch (idx)
{
case G1_LED_ON:
// write your action code here
group = GROUP_0; //<-- or jump to another group X for composite commands
Serial.print('a');
digitalWrite(11, HIGH);
break;
case G1_LED_OFF:
// write your action code here
group = GROUP_0; //<-- or jump to another group X for composite commands
Serial.print('b');
digitalWrite(11, LOW);
break;
case G1_LED_DIMMER:
// write your action code here
group = GROUP_0; //<-- or jump to another group X for composite commands
Serial.print('c');
digitalWrite(11, HIGH);
break;
}
break;
}
}
My main problem appears with the other one, I'm not sure if things are okay: I have done this sketch below which I'm not sure about:
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
int ledPin = 13;
char ser = Serial.read();
void setup(){
Serial.begin(9600);
lcd.begin(16, 2);
lcd.print("hHllo World!");
pinMode(13, OUTPUT);
pinMode(9, OUTPUT);
analogWrite(9, 15);
}
void loop (){
lcd.setCursor(0, 1);
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
if (Serial.available()) {
if(ser == 'a'){
analogWrite(ledPin, 0);
lcd.print("LED ON");
}
if(ser == 'b'){
analogWrite(ledPin, 255);
lcd.print("LED OFF");
}
if(ser == 'c'){
analogWrite(ledPin, 150);
lcd.print("LED Fade");}
}
}
}
By the way, can someone tell please what pins I use to wire the easy VR to the second arduino so serial communication can be established.?
Regards,