I am attempting to use the EasyVR shield(Manual) to trigger the MP3 Trigger (Manual).
I have a working code for the EasyVR so that it recognizes the commands. I have implemented the MP3 Trigger code into the EasyVR sketch but it spits out garbled letters on the IDE monitor. I know that it has to the Serial communication that is screwing things up, but I do not know how to solve it.
This first sketch is for the MP3 Trigger, and it works.
#include <SoftwareSerial.h>
#include <MP3Trigger.h>
SoftwareSerial trigSerial = SoftwareSerial(2, 3);
MP3Trigger trigger;
void setup ()
{
trigger.setup(&trigSerial); //This also starts the serial for this device
Serial.begin( MP3Trigger::serialRate() );
}
void loop()
{
trigger.update();
if (Serial.available())
{
char LETTER_FROM_COMPUTER = Serial.read();
if (LETTER_FROM_COMPUTER == 1)
{
trigger.play(2);
}
}
}
This sketch is for the EasyVR, which also works at recognizing my commands.
#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_MICA = 0,
};
enum Group1
{
G1_HELLO = 0,
G1_HOW_ARE_YOU = 1,
};
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(0);
group = EasyVR::TRIGGER; //<-- start group (customize)
}
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);
}
}
}
void action()
{
switch (group)
{
case GROUP_0:
switch (idx)
{
case G0_MICA:
// write your action code here
// group = GROUP_X; <-- or jump to another group X for composite commands
break;
}
break;
case GROUP_1:
switch (idx)
{
case G1_HELLO:
// write your action code here
// group = GROUP_X; <-- or jump to another group X for composite commands
break;
case G1_HOW_ARE_YOU:
// write your action code here
// group = GROUP_X; <-- or jump to another group X for composite commands
break;
}
break;
}
}
Now, as I have said earlier, I have tried to incorporate the MP3 Trigger sketch into the EasyVR sketch so that when I say a command, it triggers a track from the MP3 Trigger. This sketch compiles and uploads but it spits out garbled characters on the Monitor and, of course, doesn't work. (i.e. it doesn't trigger a sound). Below is the combined sketches, which, I am sure, is totally wrong. I believe it has to do with the Serial communication, but don't know enough to make this work.
#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 <MP3Trigger.h>
#include "EasyVR.h"
EasyVR easyvr(port);
SoftwareSerial trigSerial = SoftwareSerial(12, 13);
MP3Trigger trigger;
//Groups and Commands
enum Groups
{
GROUP_0 = 0,
GROUP_1 = 1,
};
enum Group0
{
G0_MICA = 0,
};
enum Group1
{
G1_HELLO = 0,
G1_HOW_ARE_YOU = 1,
};
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(0);
group = EasyVR::TRIGGER; //<-- start group (customize)
trigger.setup(&trigSerial); //This also starts the serial for this device
Serial.begin( MP3Trigger::serialRate() );
}
void action();
void loop()
{
trigger.update();
if (Serial.available())
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);
}
}
}
void action()
{
switch (group)
{
case GROUP_0:
switch (idx)
{
case G0_MICA:
// 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_HELLO:
trigger.play(2);// write your action code here
// group = GROUP_X; <-- or jump to another group X for composite commands
break;
case G1_HOW_ARE_YOU:
// write your action code here
// group = GROUP_X; <-- or jump to another group X for composite commands
break;
}
break;
}
}
EasyVRBridge.cpp (3.26 KB)
EasyVRBridge.h (1.77 KB)
MP3Trigger.cpp (2.66 KB)
MP3Trigger.h (1.32 KB)