Environment setup: Follow the Arduino IDE Getting Started Tutorial to install the IDE, and install the corresponding board manager and required libraries for your development board.
Required libraries:
Add basic command display functions based on M5Unified and M5GFX, and add turn on
and turn off
command callback functions to simulate a light control scene.
#include <M5Unified.h>#include <unit_asr.hpp> ASRUnit asr; void turnOnHandler(){ Serial.println("turn on command received!"); M5.Display.setCursor(0, 0); M5.Display.fillRect(0, 0, 320, 60, BLACK); M5.Display.println("turn on!");} void turnOffHandler(){ Serial.println("turn off command received!"); M5.Display.setCursor(0, 0); M5.Display.fillRect(0, 0, 320, 60, BLACK); M5.Display.println("turn off!");} void wakeupHandler(){ Serial.println("Hi, M Five command received!"); M5.Display.setCursor(0, 0); M5.Display.fillRect(0, 0, 320, 60, BLACK); M5.Display.println("wakeup!");} void setup(){ M5.begin(); M5.Display.setFont(&fonts::FreeMonoBold12pt7b); Serial.begin(115200); asr.begin(&Serial1, 115200, 18, 17); asr.addCommandWord(0x14, "turn on", turnOnHandler); asr.addCommandWord(0x15, "turn off", turnOffHandler); asr.addCommandWord(0xFF, "Hi, M Five", wakeupHandler); M5.Display.setCursor(0, 0); M5.Display.fillRect(0, 0, 320, 60, BLACK); M5.Display.println("Say \"Hi, M Five\"\nto wake up!");} void loop(){ M5.update(); if (asr.update()) { Serial.println(asr.getCurrentCommandWord()); Serial.println(asr.getCurrentCommandNum()); Serial.println(asr.getCurrentRawMessage()); Serial.println((asr.checkCurrentCommandHandler())); }}
For CoreS3, press and hold the reset button (for about 2 seconds) until the internal green LED lights up, then release it. The device will enter download mode, waiting for the firmware to be burned.
Hi M Five
command to wake up.I'm here
.Turn on
command, respond with OK
.Turn off
command, respond with OK
.AA 55 46 55 AA
with a command code of 0x46
. You can refer to the example program below for adding and registering commands and callback functions.#include <M5Unified.h>#include <unit_asr.hpp> ASRUnit asr; void JustHandler(){ Serial.println("Just command received!");} void setup(){ M5.begin(); Serial.begin(115200); asr.begin(&Serial1, 115200, 22, 21); asr.addCommandWord(0x46, "Just", JustHandler);} void loop(){ M5.update(); if (asr.checkMessage()) { Serial.println(asr.getCurrentCommandWord()); Serial.println(asr.getCurrentCommandNum()); Serial.println(asr.getCurrentRawMessage()); Serial.println((asr.checkCurrentCommandHandler())); }}
Hi M Five
command to wake up, respond with I'm here
.Just
command, respond with Do it
.JustHandler
function is called normally.Just command received!
Just
0x46
0xAA 0x55 0x46 0x55 0xAA
1