Forum >SEN0539-EN Gravity Offline Voice Recognition Crashes Arduino Nano!!!

SEN0539-EN Gravity Offline Voice Recognition Crashes Arduino Nano!!!

userHead TrickyZXR 2025-03-17 19:20:47 56 Views1 Replies

Hi, I have the below code which I have stripped back to try and fault find so apologies for lots of rem's. I'm using I2C. Basically the dfrobot code uint8_t CMDID = asr.getCMDID(); seems to be the cause of the Nano crashing after about 10 secs of the loop. If I remove all the df CMDID code and switch code it loops no problem 

 

Listening for CMDID, Switch CMDID, End of loop, Start of loop, DigitalRead, Listening for CMDID

 

I have tried watchdog and pragma fix but still crashes. Has anyone else had this problem or knows a fix please? Thanks.

 

 

#include "DFRobot_DF2301Q.h"

#include <Wire.h>

//#include <LiquidCrystal_I2C.h>

#include <Servo.h>

//LiquidCrystal_I2C lcd(0x27, 16, 2);

 

// SO WatchDog ================================

//#include <avr/wdt.h>

//int time = 0;

//wdt_enable(WDTO_2S);

// EO WatchDog ================================

 

// SO Define Servo Variables ==================================================//

Servo myservoA;  // create servo object to control a servo

int posA = 90;  // variable to store the servo position

int homePos = 90;

const int button1Pin = 6;

const int button2Pin = 7;

//const int LED_BUILTIN = 13;

int button1State = 0;  // variable for reading the pushbutton status

int button2State = 0;

int x = 0;

int y = 0;

// EO Define Servo Variables ==================================================//


//I2C communication

DFRobot_DF2301Q_I2C asr;

int vol = 5;

 

void setup() {

  Wire.begin();

  Serial.begin(115200);

  pinMode(LED_BUILTIN, OUTPUT);

  pinMode(button1Pin, INPUT);

  pinMode(button2Pin, INPUT);

  myservoA.attach(5);  //attaches the servo on pin 5

 

  //wdt_disable();

  //Wire.setClock(100000);

   while (!Serial) {

    ;  // wait for serial port to connect. Needed for native USB port only

  }

  delay(20);

  Serial.println("Serial Ready");

  Serial.println("Nano booting up!!!");

  digitalWrite(LED_BUILTIN, HIGH);

   

  posA = 80;

  myservoA.write(posA);

  Serial.println("Running SetUp");

  Serial.print("Set servo at ");

  Serial.println(posA);

  delay(2000);

  posA = 100;

  myservoA.write(posA);

  Serial.print ("Set servo at ");

  Serial.println(posA);

  delay(2000);

  myservoA.write(homePos);

  Serial.print("Setup complete servo at pos ");

  Serial.println(homePos);

  delay(1000);

 

  // Init the sensor

  Serial.println("Looking for DfRobot");

  while (!(asr.begin())) {

  Serial.println("Communication with device failed, please check connection");

  digitalWrite(LED_BUILTIN, HIGH);

  delay(3000);

 }

  digitalWrite(LED_BUILTIN, LOW);

  Serial.println("Found DfRobot");

 

  /**

   * @brief Set voice volume

   * @param voc - Volume value(1~7)

   */

  asr.setVolume(vol);

 

  /**

     @brief Set mute mode

     @param mode - Mute mode; set value 1: mute, 0: unmute

  */

  //asr.setMuteMode(0);

 

  /**

     @brief Set wake-up duration

     @param wakeTime - Wake-up duration (0-255)

  */

  asr.setWakeTime(40);

 

  /**

     @brief Get wake-up duration

     @return The currently-set wake-up period

  */

  //uint8_t wakeTime = 0;

  //wakeTime = asr.getWakeTime();

  //Serial.print("wakeTime = ");

  //Serial.println(wakeTime);

 

  /**

     @brief Play the corresponding reply audio according to the ID

     @param CMDID - command word ID

  */

 // asr.playByCMDID(5);  // Command word ID

 

  delay(2000);

  Serial.println("Mercedes Ready! vr2");

 

}

// wake word = 2 custom words id 5 - 21

// command id's https://wiki.dfrobot.com/SKU_SEN0539-EN_Gravity_Voice_Recognition_Module_I2C_UART#target_9

 

void loop() {

  digitalWrite(LED_BUILTIN, LOW);

  delay(20);

  Serial.println("Start of loop");


 /**if(millis()/1000 > 15) {

     Serial.println("Forced Reboot");

    wdt_enable(WDTO_15MS);  

   }

*/

  button1State = digitalRead(button1Pin);  // read the state of the pushbutton

  button2State = digitalRead(button2Pin);

  Serial.println("DigitalRead");

 

  /**

     @brief Get the ID corresponding to the command word

     @return Return the obtained command word ID, returning 0 means no valid ID is obtained

  */


  Serial.println("Listening for CMDID");

 

/**

     @brief Get the ID corresponding to the command word

     @return Return the obtained command word ID, returning 0 means no valid ID is obtained

  */

  uint8_t CMDID = asr.getCMDID();

  Serial.println("Switch CMDID");

  switch (CMDID) {

    case 103:                                                  //If the command is “Turn on the light”

     // digitalWrite(Led, HIGH);                                 //Turn on the LED

      Serial.println("received'Turn on the light',command flag'103'");  //Serial transmits "received"Turn on the light",command flag"103

      break;


    case 104:                                                  //If the command is “Turn off the light”

      //digitalWrite(Led, LOW);                                  //Turn off the LED

      Serial.println("received'Turn off the light',command flag'104'");  //The serial transmits "received"Turn off the light",command flag"104""

      break;

 

    default:

      if (CMDID != 0) {

        Serial.print("CMDID = ");  //Printing command ID

        Serial.println(CMDID);

      }

  }

  delay(300);

}

2025-03-27 19:18:33

Solved: It appears to be the clone nano I was using so bought genuine Nano ESP32 and now working. Was having false activations to caused by using ribbon cable which i2c didnt like so used CAT5e cable and split power and i2c over different pairs.

userHeadPic TrickyZXR