Example Code for Arduino - ESP32-S3 native UART interface

Last revision 2026/02/05

Function Description

In the DMX512 controller, the ESP32-S3 native UART is exposed, as shown in the diagram:
Native GPIO pins of ESP32-S3

The mapping of UART pins is as follows:

Pins Pins function
TXD IO6
RXD IO8

Example: Voice Control of Lights

The following example demonstrates using offline voice recognition via the UART interface to control DMX512 lights. Product link: UART driver library download link: DFRobot_RTU

Wiring diagram

Voice Recognition Light

When using, please switch the communication mode switch of the voice recognition module to the I2C side.

Programming

#include "DFRobot_DF2301Q.h"

#define Led 21

DFRobot_DF2301Q_UART asr(/*hardSerial =*/&Serial2, /*rx =*/8, /*tx =*/6);


void setup() {
  Serial.begin(115200);

  pinMode(Led, OUTPUT);    //Initialize the LED pin as output mode.
  digitalWrite(Led, LOW);  //Set the LED pin to low level.

  while (!(asr.begin())) {
    Serial.println("Communication with device failed, please check connection");
    delay(3000);
  }
  Serial.println("Begin ok!");


  asr.settingCMD(DF2301Q_UART_MSG_CMD_SET_MUTE, 0);
  asr.settingCMD(DF2301Q_UART_MSG_CMD_SET_VOLUME, 7);
  asr.settingCMD(DF2301Q_UART_MSG_CMD_SET_WAKE_TIME, 20);

  asr.playByCMDID(23);
}

void loop() {

  uint8_t CMDID = asr.getCMDID();
  switch (CMDID) {
    case 117:                                                  //If the command is "turn on the light"
      digitalWrite(Led, HIGH);                                 //Turn on the LED.
      Serial.println("received'turn on the light',command flag'117'");  //Serial send received "turn on the light", command flag "117".
      break;

    case 118:                                                  //If the command is "turn off the light"
      digitalWrite(Led, LOW);                                  //turn off the light
      Serial.println("received'turn off the light',command flag'118'");  //Serial port sends received "turn off the light", command flag "118"
      break;

    default:
      if (CMDID != 0) {
        Serial.print("CMDID = ");  
        Serial.println(CMDID);
      }
  }
  delay(300);
}

Was this article helpful?

ON THIS PAGE

TOP