Hey, so I'm using the geeetech voice recognition module shown in this video . I want it to tell me in the serial moniter that it knows which commands I'm giving it (I'll add in functions later), but even though I use the same basis of code they use on the website, I still can't manage to get any results. Here's my code can you find any problems with it?
#include <SoftwareSerial.h>
/**#define SmallCurtains (0x11) /Group 1/
#define BigCurtain (0x12) /Group 1/
#define Lights (0x13) /Group 1/
#define Door (0x14) /Group 1/
#define PowerOff (0x15) /Group 1/
#define Up (0x16) /Group 2/
#define Down (0x17) /Group 2/
#define Stop (0x18) /Group 2/
#define Left (0x19) /Group 2/
#define Right (0x20) /Group 2/
#define Off (0x21) /Group 3/
#define Next (0x22) /Group 3/
#define Shoot (0x23) /Group 3/
#define Unlock (0x24) /Group 3/
#define PermaLock (0x25) /Group 3**/
byte com = 0; // reply from vr
// Delay times//
unsigned long previousMillis;
unsigned long currentMillis;
int counter = 0; /** 0 = idle, 1 = counting**/
int gstatus = 0; /** says what group its in**/
void setup()
{
Serial.begin(9600);
delay(2000);
Serial.write(0xAA);
Serial.write(0x37);
delay(1000);
Serial.write(0xAA);
Serial.write(0x21);
gstatus = 1;
}
void loop() {
Serial.println(gstatus);
currentMillis = millis();
while (counter == 1 && currentMillis - previousMillis > timeoutTime) {
Serial.write(0xAA);
Serial.write(0x00);
Serial.write(0xAA);
Serial.write(0x21); /** Timed out **/
gstatus = 1;
counter = 0;
}
while (Serial.available()) {
com = Serial.read();
switch (com)
{
case 11: // Small curtains, Up, or Off
counter = 0;
if (gstatus == 1) {
Serial.println("Small curtains instructions recieved");
}
else if (gstatus == 2) {
Serial.println("Up instructions recieved");
}
else if (gstatus == 3) {
Serial.println("Off instructions recieved");
}
Serial.write(0xAA);
Serial.write(0x00);
Serial.write(0xAA);
Serial.write(0x21); /**Go back to command group 1**/
gstatus = 1;
previousMillis = currentMillis;
counter = 1;
break;
case 12: // Big curtain, Down, or Next
counter = 0;
if (gstatus == 1) {
Serial.println("Bigcurtain instructions recieved");
}
else if (gstatus == 2) {
Serial.println("Down instructions recieved");
}
else if (gstatus == 3) {
Serial.println("Next instructions recieved");
}
Serial.write(0xAA);
Serial.write(0x00);
Serial.write(0xAA);
Serial.write(0x21); /**Go back to command group 1**/
gstatus = 1;
previousMillis = currentMillis;
counter = 1;
break;
case 13: // Lights, Stop, or Shoot
if (gstatus == 1) {
Serial.println("Lights instructions recieved");
}
else if (gstatus == 2) {
Serial.println("Stop instructions recieved");
}
else if (gstatus == 3) {
Serial.println("Shoot instructions recieved");
}
Serial.write(0xAA);
Serial.write(0x00);
Serial.write(0xAA);
Serial.write(0x21); /**Go back to command group 1**/
gstatus = 1;
previousMillis = currentMillis;
counter = 1;
break;
case 14: // Door, Left, or Unlock
if (gstatus == 1) {
Serial.println("Door instructions recieved");
}
else if (gstatus == 2) {
Serial.println("Left instructions recieved");
}
else if (gstatus == 3) {
Serial.println("Unlock instructions recieved");
}
Serial.write(0xAA);
Serial.write(0x00);
Serial.write(0xAA);
Serial.write(0x21); /**Go back to command group 1**/
gstatus = 1;
previousMillis = currentMillis;
counter = 1;
break;
case 15: // PowerOff, Right, or Permalock
if (gstatus == 1) {
Serial.println("PowerOff instructions recieved");
}
else if (gstatus == 2) {
Serial.println("Right instructions recieved");
}
else if (gstatus == 3) {
Serial.println("Permalock instructions recieved");
}
Serial.write(0xAA);
Serial.write(0x00);
Serial.write(0xAA);
Serial.write(0x21); /**Go back to command group 1**/
gstatus = 1;
previousMillis = currentMillis;
counter = 1;
break;
default:
Serial.println("Unknown command");
break;
}
}
}
Also, I do receive the "unknown command" sometimes (this is the default response), but it is not reliable. I do have the commands uploaded correctly and on the software I uploaded them on from my computer, it recognizes my commands. I've been working on this for ages, but can't seem to spot the problem so any help would be appreciated.