How to selectGravity

dfrobot voice recognition UART wakeup

userHead cdb0ewm 2026-08-01 23:34:32 10 Views0 Replies

I'm trying to get this module to wake up - blue light - and stay on once the XIAO EP32 C3 is powered up. I've tried several suggestions from other sites but no luck.

 

 

`#include "DFRobot_DF2301Q.h"

#include <esp_now.h>

#include <WiFi.h>

uint8_t broadcastAddress[] = { 0x14, 0x08, 0x08, 0xa5, 0xd7, 0x68 };

DFRobot_DF2301Q_UART DF2301Q(/*hardSerial =*/&Serial1, /*rx =*/D7, /*tx =*/D6);

#define Rgt D0

#define Lft D1


 

int RbuttonPin = D9;

int RbuttonPushCounter = 0;  // counter for the number of button presses

int RbuttonState = 0;        // current state of the button

int RlastButtonState = 0;


 

int LbuttonPin = 29;

int LbuttonPushCounter = 0;  // counter for the number of button presses

int LbuttonState = 0;        // current state of the button

int LlastButtonState = 0;


 

typedef struct struct_message {

  int b;

} struct_message;

struct_message myData;

esp_now_peer_info_t peerInfo;

DFRobot_DF2301Q_I2C asr;

void OnDataSent(const esp_now_send_info_t *tx_info, esp_now_send_status_t status) {

  if (status == ESP_NOW_SEND_SUCCESS) {

    Serial.println("Send Success");

  } else {

    Serial.println("Send Fail");

  }

}


 

void setup() {

  Serial.begin(115200);

  myData.b = 0;

  WiFi.mode(WIFI_STA);

  if (esp_now_init() != ESP_OK) {

    Serial.println("Error initializing ESP-NOW");

    return;

  }

  esp_now_register_send_cb(OnDataSent);

  memcpy(peerInfo.peer_addr, broadcastAddress, 6);

  peerInfo.channel = 0;

  peerInfo.encrypt = false;

  if (esp_now_add_peer(&peerInfo) != ESP_OK) {

    Serial.println("Failed to add peer");

    return;

  }

  pinMode(Rgt, OUTPUT);

  pinMode(Lft, OUTPUT);

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

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

    delay(3000);

  }

  Serial.println("Begin ok!");

  asr.setVolume(7);

  asr.setMuteMode(0);

  asr.setWakeTime(255);


 

  uint8_t wakeTime = 0;

  wakeTime = asr.getWakeTime();

  Serial.print("wakeTime 4= ");

  Serial.println(wakeTime);


 

  // asr.playByCMDID(1);   // Wake-up command


 

  /**

     @brief Play the corresponding reply audio according to the ID

     @param CMDID - command word ID

  */


 

  pinMode(RbuttonPin, INPUT);

  pinMode(LbuttonPin, INPUT);

  RbuttonPin = HIGH;

  LbuttonPin = HIGH;

}


 

void loop() {


 

  LbuttonState = digitalRead(LbuttonPin);

  if (LbuttonState != LlastButtonState) {

    LbuttonPushCounter++;

  }

  if (LbuttonPushCounter >= 2) {

  }

  uint8_t CMDID = 0;

  CMDID = DF2301Q.getCMDID();

  Serial.print("CMDID = ");

  Serial.println(CMDID);

  if (CMDID == 5) {

    digitalWrite(Lft, LOW);

    while ((RbuttonPushCounter < 2)) {

      digitalWrite(Rgt, HIGH);

      delay(1000);

      digitalWrite(Rgt, LOW);

      delay(1000);

      RbuttonState = digitalRead(RbuttonPin);

      Serial.print("now ");

      Serial.println(RbuttonState);

      Serial.print("last ");

      Serial.println(RlastButtonState);

      if (RbuttonState != RlastButtonState) {

        RbuttonPushCounter++;

        (RlastButtonState = RbuttonState);

        Serial.print("CNT = ");

        Serial.println(RbuttonPushCounter);

      }

     if ((RbuttonPushCounter >= 2)) {

        RbuttonPushCounter = 0;

        digitalWrite(Rgt, LOW);

        break;

      }

   

    }

  }


 

  if (CMDID == 7) {

    digitalWrite(Rgt, LOW);  // Turn Relay OFF

    digitalWrite(Lft, LOW);

    Serial.println("Relay Deactivated");

  }

  delay(500);

  //GREEN = 8, WHITE = 9, RED = 10, CRUISE ON = 11, CRUISE SET = 12, ADAPT ON = 13, NEAR = 14, FAR = 15

  if (CMDID == 0 || CMDID == 8 || CMDID == 9 || CMDID == 10 || CMDID == 11 || CMDID == 12 || CMDID == 13 || CMDID == 14 || CMDID == 15 || CMDID == 16) {

    (myData.b = CMDID);

    (CMDID == 0);

    Serial.println(myData.b);

    uint8_t data[sizeof(myData)];

    memcpy(data, &myData, sizeof(myData));

    esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *)&myData, sizeof(myData));

    //       esp_now_send(peerAddress, data, sizeof(data));

    if (result == ESP_OK) {

      Serial.println("Sent with success");

    } else {

      Serial.println("Error sending the data");

    }

  }

  delay(1000);

}