I'm trying to have the following configuration Arduino uno + Easy VR ( on a shield ) + motomama Shield ( for DC motor and Xbee ) : mounted in the same order.
The problem that I'm facing is :
The existing Rx/Tx pins of arduino are used for communication between Arduino and Easy VR.
Hence I', forced to have a new serial connection , so that I can send info ( I'm not trying to receive ) over Xbee in the top most shield.
I'm trying to use software serial to do it. I'm modyfying the code generated by easyVR commander:
Whenever I putin the statement to open one more software serial connection It doesn't seem to work. This is my code :
Anyhelp would be greatly appreciated.
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#include "SoftwareSerial.h"
SoftwareSerial port(12,13);
SoftwareSerial mySerialtx(4,5);
#else // Arduino 0022 - use modified NewSoftSerial
#include "WProgram.h"
#include "NewSoftSerial.h"
NewSoftSerial port(12,13);
NewSoftSerial mySerialtx(4,5);
#endif
//SoftwareSerial mySerial(2, 3); // for x bee.
#include "EasyVR.h"
EasyVR easyvr(port);
//Groups and Commands
enum Groups
{
GROUP_0 = 0,
GROUP_1 = 1,
};
enum Group0
{
G0_POOPOO = 0,
};
enum Group1
{
G1_SING = 0,
G1_STOP = 1,
G1_JOY = 2,
G1_DANCE = 3,
G1_COME = 4,
G1_GO = 5,
G1_LEFT = 6,
G1_RIGHT = 7,
G1_TURN = 8,
G1_WAGGLE = 9,
};
EasyVRBridge bridge;
int8_t group, idx;
//int sensorPin = A2; // Pin to read IR sensor input
void setup()
{
// Setting pin modes
// Motor 1
pinMode(8,OUTPUT); //line 1
pinMode(9,OUTPUT); //line 2
pinMode(10,OUTPUT); //EnA
// Motor 2
pinMode(11,OUTPUT); //line 1
pinMode(6,OUTPUT); //line 2
pinMode(7,OUTPUT); //EnA
// bridge mode?
if (bridge.check())
{
cli();
bridge.loop(0, 1, 12, 13);
}
// run normally
Serial.begin(9600);
port.begin(9600);
mySerialtx.begin(9600); // THE CODE HANGS HERE >>>)
if (!easyvr.detect())
{
Serial.println("EasyVR not detected!");
for (;;);
}
easyvr.setPinOutput(EasyVR::IO1, LOW);
Serial.println("EasyVR detected!");
easyvr.setTimeout(5);
easyvr.setLanguage(0);
group = EasyVR::TRIGGER; //<-- start group (customize)
}
void action();
void loop()
{
mySerialtx.println('H'); //xbee
delay(500);
mySerialtx.println('L'); //xbee
int i = 0;
easyvr.setPinOutput(EasyVR::IO1, HIGH); // LED on (listening)
Serial.print("Say a command in Group ");
Serial.println(group);
easyvr.recognizeCommand(group);
//Serial.println(analogRead(sensorPin));
do
{
// Serial.println(analogRead(sensorPin));// can do some processing while waiting for a spoken command
}
while (!(i=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
Serial.print("idx ");
Serial.println(idx);
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);
}
}
}
void action()
{
switch (group)
{
case GROUP_0:
switch (idx)
{
case G0_POOPOO:
// 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_SING:
// write your action code here
// group = GROUP_X; <-- or jump to another group X for composite commands
break;
case G1_STOP:
digitalWrite(10,LOW);
digitalWrite(8,HIGH);
digitalWrite(9,LOW);
digitalWrite(11,LOW);
digitalWrite(6,LOW);
digitalWrite(7,HIGH);
// write your action code here
// group = GROUP_X; <-- or jump to another group X for composite commands
break;
case G1_JOY:
// write your action code here
// group = GROUP_X; <-- or jump to another group X for composite commands
break;
case G1_DANCE:
// write your action code here
// group = GROUP_X; <-- or jump to another group X for composite commands
break;
case G1_COME:
// write your action code here
// group = GROUP_X; <-- or jump to another group X for composite commands
break;
case G1_GO:
digitalWrite(10,HIGH);
digitalWrite(8,HIGH);
digitalWrite(9,LOW);
digitalWrite(11,HIGH);
digitalWrite(6,HIGH);
digitalWrite(7,LOW);
// write your action code here
// group = GROUP_X; <-- or jump to another group X for composite commands
break;
case G1_LEFT:
// write your action code here
// group = GROUP_X; <-- or jump to another group X for composite commands
break;
case G1_RIGHT:
// write your action code here
// group = GROUP_X; <-- or jump to another group X for composite commands
break;
case G1_TURN:
// write your action code here
// group = GROUP_X; <-- or jump to another group X for composite commands
break;
case G1_WAGGLE:
// write your action code here
// group = GROUP_X; <-- or jump to another group X for composite commands
break;
}
break;
}
}
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.