Can't put another VR command into my code!

For starter, I use an ESP32 Dev Module to control VR V3. I did my research and I do find a way to control VR with some help from someone named Frank (VR is not very much compatible with ESP32 since it use SoftwareSerial library, which is not useable for ESP).
Here is the link to Frank blog :ESP32 Support for Elechouse Voice Recognition Module V3 – Frank's Random Wanderings

Now the problem is VR can hold lots of voice command, but only 7 of them can be use at the same time. I need at least 15 - 20 commands to be use on my project, but I can't get others vr_sample_bridge response number after the first 7, and I need to load tons of it into my project.

My test code start by receiving first command which is "Hey Grand", then it leads to another.

->Hey Grand --> Turn On / Power Off / Mode On / Off Mode
->Turn On --> AC / Light / Fan
->Power Off --> AC / Light / Fan
->Mode On --> Silent / Turbo / Eco
->Off Mode --> Silent / Turbo / Eco

After receiving commands, assigned LED for each of the will light on and off as a response.

Here is my test code before I put it into my project:

#include "VoiceRecognitionV3.h"
#include <Wire.h>
#include <SPI.h>

#define RED_1       23
#define RED_2       25
#define RED_3       13
#define YELLOW_1    32
#define YELLOW_2    26
#define YELLOW_3    18
#define GREEN_1     33
#define GREEN_2     27
#define GREEN_3     33
#define UNKNOWN     19

bool powerUp            = false;
bool poweringOn         = false;
bool poweringOff        = false;
bool modeOn             = false;
bool modeOff            = false;

  // Declaration for the Elechouse VR3
VR myVR (16, 17);   // the (2,3) are ignored for ESP32 - kept only for easier backwards compatibility

  // The following arrays used for the Elechouse VR3 module
uint8_t vr3_check_recog_cmd[]             = {0x01};
uint8_t vr3_clear_recog_cmd[]             = {0x31};
//uint8_t vr3_load_records_cmd[]            = {0x30, 0x00, 0x01, 0x02};
//uint8_t vr3_load_records_cmd[]            = {0x30, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10};
uint8_t vr3_load_records_cmd[]            = {0x30, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06};
uint8_t vr3_load_response[]               = {0xAA, 0x09, 0x30, 0x03, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x0A};
uint8_t vr3_hey_grand_message[]           = {0xAA, 0x10, 0x0D, 0x00, 0xFF, 0x00, 0x00, 0x09, 0x68, 0x65, 0x79, 0x5F, 0x67, 0x72, 0x61, 0x6E, 0x64, 0x0A};
uint8_t vr3_turn_on_message[]             = {0xAA, 0x0F, 0x0D, 0x00, 0xFF, 0x02, 0x02, 0x08, 0x74, 0x75, 0x72, 0x6E, 0x5F, 0x6F, 0x66, 0x66, 0x0A};
uint8_t vr3_power_off_message[]           = {0xAA, 0x0F, 0x0D, 0x00, 0xFF, 0x01, 0x01, 0x08, 0x70, 0x6F, 0x77, 0x65, 0x72, 0x5F, 0x6F, 0x6E, 0x0A};
uint8_t vr3_ac_mode_on_message[]          = {0xAA, 0x0E, 0x0D, 0x00, 0xFF, 0x03, 0x03, 0x07, 0x6D, 0x6F, 0x64, 0x65, 0x5F, 0x6F, 0x6E, 0x0A};
uint8_t vr3_power_off_ac_mode_message[]   = {0xAA, 0x0F, 0x0D, 0x00, 0xFF, 0x01, 0x01, 0x08, 0x70, 0x6F, 0x77, 0x65, 0x72, 0x5F, 0x6F, 0x6E, 0x0A};
uint8_t vr3_ac_message[]                  = {0xAA, 0x09, 0x0D, 0x00, 0xFF, 0x05, 0x05, 0x02, 0x61, 0x63, 0x0A};
uint8_t vr3_light_message[]               = {0xAA, 0x0C, 0x0D, 0x00, 0xFF, 0x06, 0x06, 0x05, 0x6C, 0x69, 0x67, 0x68, 0x74, 0x0A};

//Sample Bridge respond ends here since I can't get another after the first seven
uint8_t vr3_fan_message[]                 = {0xAA, 0x0C, 0x0D, 0x00, 0xFF, 0x04, 0x02, 0x05, 0x67, 0x72, 0x65, 0x65, 0x6E, 0x0A};

uint8_t vr3_silent_message[]              = {0xAA, 0x0C, 0x0D, 0x00, 0xFF, 0x04, 0x02, 0x05, 0x67, 0x72, 0x65, 0x65, 0x6E, 0x0A};
uint8_t vr3_turbo_message[]               = {0xAA, 0x0C, 0x0D, 0x00, 0xFF, 0x04, 0x02, 0x05, 0x67, 0x72, 0x65, 0x65, 0x6E, 0x0A};
uint8_t vr3_eco_message[]                 = {0xAA, 0x0C, 0x0D, 0x00, 0xFF, 0x04, 0x02, 0x05, 0x67, 0x72, 0x65, 0x65, 0x6E, 0x0A};
uint8_t vr3_buf[50];

void setup(void) {
  Serial.begin(115200);
  Serial.println("Voice Recognition MultiCommand Test Run");

  pinMode(RED_1, OUTPUT);
  pinMode(RED_2, OUTPUT);
  pinMode(RED_3, OUTPUT);
  pinMode(YELLOW_1, OUTPUT);
  pinMode(YELLOW_2, OUTPUT);
  pinMode(YELLOW_3, OUTPUT);
  pinMode(GREEN_1, OUTPUT);
  pinMode(GREEN_2, OUTPUT);
  pinMode(GREEN_3, OUTPUT);
  pinMode(UNKNOWN, OUTPUT);

  start_vr3_running();
}

void loop(void) {
  int ret_len;

  // Check for received voice messages from the VR3. If there's a voice message, check what it is, 
  // display word on Serial Monitor and send command to modules as appropriate. 
  ret_len = myVR.receive_pkt(vr3_buf, 50);
  if (ret_len > 0) {
    if (byte_array_cmp(vr3_buf, vr3_hey_grand_message, ret_len, sizeof(vr3_hey_grand_message))) {
      Serial.println("Heard: Hey Grand  ");
      digitalWrite(RED_1, HIGH);
      powerUp = true;
    }
    /*else {
      Serial.println("Unrecognizeable Command");
      unknownCommand();
    }*/

    if (powerUp) {
      if (byte_array_cmp(vr3_buf, vr3_turn_on_message, ret_len, sizeof(vr3_turn_on_message))) {
        Serial.println("Heard: Turn On ");
        digitalWrite(YELLOW_1, HIGH);
        poweringOn = true;
      }
      else if (byte_array_cmp(vr3_buf, vr3_power_off_message, ret_len, sizeof(vr3_power_off_message))) {
        Serial.println("Heard: Power Off ");
        digitalWrite(YELLOW_1, HIGH);
        poweringOff = true;
      }
      else if (byte_array_cmp(vr3_buf, vr3_ac_mode_on_message, ret_len, sizeof(vr3_ac_mode_on_message))) {
        Serial.println("Heard: AC Mode On ");
        digitalWrite(YELLOW_1, HIGH);
        modeOn = true;
      }
      else if (byte_array_cmp(vr3_buf, vr3_power_off_ac_mode_message, ret_len, sizeof(vr3_power_off_ac_mode_message))) {
        Serial.println("Heard: Power Off AC Mode");
        digitalWrite(YELLOW_1, HIGH);
        modeOff = true;
      }
      /*else {
        Serial.println("Unrecognizeable Command");
        unknownCommand();
        deviceReset();
      }*/
    }

    if (poweringOn) {
      if (byte_array_cmp(vr3_buf, vr3_ac_message, ret_len, sizeof(vr3_ac_message))) {
        Serial.println("Heard: AC (ON) ");
        digitalWrite(GREEN_1, HIGH);
        deviceReset();
        lightReset();
      }
      else if (byte_array_cmp(vr3_buf, vr3_light_message, ret_len, sizeof(vr3_light_message))) {
        Serial.println("Heard: Light (ON) ");
        digitalWrite(RED_2, HIGH);
        deviceReset();
        lightReset();
      }
      else if (byte_array_cmp(vr3_buf, vr3_fan_message, ret_len, sizeof(vr3_fan_message))) {
        Serial.println("Heard: Fan (ON) ");
        digitalWrite(YELLOW_2, HIGH);
        deviceReset();
        lightReset();
      }
      /*else {
        Serial.println("Unrecognizeable Command");
        unknownCommand();
        deviceReset();
      }*/
    }

    if (poweringOff) {
      if (byte_array_cmp(vr3_buf, vr3_ac_message, ret_len, sizeof(vr3_ac_message))) {
        Serial.println("Heard: AC (OFF) ");
        digitalWrite(GREEN_1, LOW);
        deviceReset();
        lightReset();
      }
      else if (byte_array_cmp(vr3_buf, vr3_light_message, ret_len, sizeof(vr3_light_message))) {
        Serial.println("Heard: Light (OFF) ");
        digitalWrite(RED_2, LOW);
        deviceReset();
        lightReset();
      }
      else if (byte_array_cmp(vr3_buf, vr3_fan_message, ret_len, sizeof(vr3_fan_message))) {
        Serial.println("Heard: Fan (OFF) ");
        digitalWrite(YELLOW_2, LOW);
        deviceReset();
        lightReset();
      }
      /*else {
        Serial.println("Unrecognizeable Command");
        unknownCommand();
        deviceReset();
      }*/
    }

    if (modeOn) {
      if (byte_array_cmp(vr3_buf, vr3_silent_message, ret_len, sizeof(vr3_silent_message))) {
        Serial.println("Heard: Silent (ON) ");
        digitalWrite(GREEN_2, HIGH);
        deviceReset();
        lightReset();
      }
      else if (byte_array_cmp(vr3_buf, vr3_turbo_message, ret_len, sizeof(vr3_turbo_message))) {
        Serial.println("Heard: Turbo (ON) ");
        digitalWrite(RED_3, HIGH);
        deviceReset();
        lightReset();
      }
      else if (byte_array_cmp(vr3_buf, vr3_eco_message, ret_len, sizeof(vr3_eco_message))) {
        Serial.println("Heard: Eco (ON) ");
        digitalWrite(YELLOW_3, HIGH);
        deviceReset();
        lightReset();
      }
      /*else {
        Serial.println("Unrecognizeable Command");
        unknownCommand();
        deviceReset();
      }*/
    }

    if (modeOff) {
      if (byte_array_cmp(vr3_buf, vr3_silent_message, ret_len, sizeof(vr3_silent_message))) {
        Serial.println("Heard: Silent (OFF) ");
        digitalWrite(GREEN_2, LOW);
        deviceReset();
        lightReset();
      }
      else if (byte_array_cmp(vr3_buf, vr3_turbo_message, ret_len, sizeof(vr3_turbo_message))) {
        Serial.println("Heard: Turbo (OFF) ");
        digitalWrite(RED_3, LOW);
        deviceReset();
        lightReset();
      }
      else if (byte_array_cmp(vr3_buf, vr3_eco_message, ret_len, sizeof(vr3_eco_message))) {
        Serial.println("Heard: Eco (OFF) ");
        digitalWrite(YELLOW_3, LOW);
        deviceReset();
        lightReset();
      }
      /*else {
        Serial.println("Unrecognizeable Command");
        unknownCommand();
        deviceReset();
      }*/
    }
  }
}

  // Starts the VR3 module running, by loading the records into the recognizer and reporting the
  // result on the Serial Monitor.

void start_vr3_running(void) {
  myVR.begin(9600);
  // Check the recognizer and clear the recognizer. Get the resulting responses but ignore them, we don't
  // care, it's only to get the VR3 started in a known clear state
  myVR.receive_pkt(vr3_buf, 50);  // start with a read in case there's any junk data in the receive fifo
  myVR.send_pkt(vr3_check_recog_cmd, sizeof(vr3_check_recog_cmd));
  myVR.receive_pkt(vr3_buf, 50);
  myVR.send_pkt(vr3_clear_recog_cmd, sizeof(vr3_clear_recog_cmd));
  myVR.receive_pkt(vr3_buf, 50);

  // Now tell the VR3 recognizer to load the word recognition records
  // Check the response to ensure the VR3 did load the recognizer correctly.
  myVR.send_pkt(vr3_load_records_cmd, sizeof(vr3_load_records_cmd));

  if (check_for_vr3_load_response(50))
    Serial.println("Listening...");
  else
    Serial.println("VR3 Not Started");
}

  // Returns true if the VR3 module returns the expected reponse to the "load records"
  // command within the specified milliseconds timeout.
boolean check_for_vr3_load_response(int timeout)
{
  int ret_len;
  
  ret_len = myVR.receive_pkt(vr3_buf, timeout);
  if (ret_len <= 0)
    return false;

  if (byte_array_cmp(vr3_buf, vr3_load_response, ret_len, sizeof(vr3_load_response)))
    return true;
   
  return false;
}

  // Compares two arrays, returns true if they're identical
  // Copied from https://forum.arduino.cc/t/comparing-two-arrays/5211
boolean byte_array_cmp(uint8_t *a, uint8_t *b, int len_a, int len_b){
      int n;

      // if their lengths are different, return false
      if (len_a != len_b) return false;

      // test each element to be the same. if not, return false
      for (n=0;n<len_a;n++) if (a[n]!=b[n]) return false;

      //ok, if we have not returned yet, they are equal :)
      return true;
}

void deviceReset() {
  powerUp            = false;
  poweringOn         = false;
  poweringOff        = false;
  modeOn             = false;
  modeOff            = false;
}

void lightReset() {
  digitalWrite(RED_1, LOW);
  digitalWrite(YELLOW_1, LOW);
}
/*
void unknownCommand() {
  digitalWrite(UNKNOWN, HIGH);
  delay(200);
  digitalWrite(UNKNOWN, LOW);
  delay(200);
  digitalWrite(UNKNOWN, HIGH);
  delay(200);
  digitalWrite(UNKNOWN, LOW);
  delay(200);
  digitalWrite(UNKNOWN, HIGH);
  delay(200);
  digitalWrite(UNKNOWN, LOW);
  delay(200);
}
*/

Sorry since I newly created this acc, I can't attach INO file.

Welcome to the forum

To post images etc. you need trust level 1, you can get there by:

  • Entering at least 5 topics
  • Reading at least 30 posts
  • Spend a total of 10 minutes reading posts

Users at trust level 1 can...

  • Use all core Discourse functions; all new user restrictions are removed
  • Send PMs
  • Upload images and attachments

It is actually much better to post your code into a reply, using code tags when you do, rather than attaching files

Why do you say that ?

ESP32 Dev Module is not part of Arduino, more like a third-party microcontroller board I guess.
Since it's not part of Arduino, the SoftwareSerial doesn't work.

Sorry I might say something different, its actually VR3 vr_sample_train.ino and vr_sample_bridge.ino is not compatible with SoftwareSerial, results in a build error.

That's why I did my reseach and founded Frank blog, which lead me to a new prob

Please post the two sketches that you say produce an error and the full error messages

If you are looking for an alternative SR module, Espressif provides their own off-line SR. I have not tried it but the demos look good. This code is for esp-idf, so is off-topic for this forum.

Thanks I'll try it.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.