Product Introduction
DMX512 Digital Dimming Protocol
DMX512 is a digital dimming protocol capable of digitally controlling dimmers and other control devices in venues such as stages, theaters, and studios. Its simple wiring and high reliability make it the most widely used system, with a large number of DMX512 lighting drivers, spotlights, and consoles available on the market. They are commonly used for stage lighting control and park lighting effects control.
EDGE102-DMX512 Controller
The EDGE102-DMX512 controller allows you to build programmable interactive lighting effects at a low cost. It employs a dual-core architecture with the ESP32-S3 and DMX512 protocol processing chips. The ESP32-S3 is used for user programming and supports WiFi and Bluetooth wireless networks. Another independent chip integrates the DMX512 protocol, and the two communicate internally via I2C, significantly improving the system's stability and reliability. This also greatly simplifies user programming, requiring only basic instructions to control lighting without understanding the complex DMX512 underlying communication protocol.
Features and Ports
The EDGE102-DMX512 adopts the standard DMX512 protocol and interface, which can be directly connected to almost all DMX512 light strip drivers and lamps on the market. It is equipped with a variety of peripheral interfaces:
- 8 fully isolated industrial switch inputs
- 1 industrial relay output
- 1 RS485 port
- 1 ESP32-S3 I2C port
- 1 ESP32-S3 UART port
- 2 ESP32-S3 GPIOs
- 1 DMX512 XLR port
The rich ports allow the controller to connect directly to standard industrial infrared sensors, laser sensors, sound level meters, inverters, lamps, and other equipment. It also supports a wide range of open-source hardware sensor modules. Sensor-based interactive lighting effects can decorate your living room, garden, parties, bars, and can also be used for lighting interaction projects in parks and shopping malls.
Product Features
- Standard DMX512 Protocol and Ports: Can be directly connected to DMX512 drivers and lighting fixtures.
- 8 Optocoupler-Isolated Switch Inputs: Can be directly connected to standard PNP switch sensors.
- 1 Relay Output Port
- 1 RS485 Ports: Supports both master and slave modes.
- 1 I2C Interface, 1 UART Port, and 2 GPIO Ports: Compatible with a wide range of open-source sensors.
- Built-in Clock Chip: Allows designing different functions and effects based on time points and holidays.
- ESP32-S3 Main Chip: Supports WiFi and Bluetooth, and is compatible with Arduino programming for easy and quick setup.
- Dedicated Chip for DMX512 Protocol: Ensures reliable program operation.
- Metal Enclosure: Supports both ear mount and rail mount installations.
Product Size Diagram
Function Indicator Diagram
Rear Panel
Feature Name | Function Description |
---|---|
12V~24V Power IN | Power Input, Voltage Range: 12V to 24V, Terminal Blocks or DC 2.1 Interface (choose one) |
WIFI/Bluetooth | WIFI and Bluetooth antenna (SMA female interface) |
PWR | Power Indicator Light |
IO21 | Test light connected to the ESP32-S3's IO21 port. |
USB | Type-C USB Download Program Interface |
RST | Reset Button |
120R RS485 | RS485 120Ω switch |
DMX512 OUT | Lighting control program output interface, used for connecting to DMX512 driver. |
Front Interface
Feature Name | Ports Name | Function Description |
---|---|---|
RS485 | ||
1 RS485 port | ||
A | RS485 A | |
B | RS485 B | |
Relay OUT | ||
*1 Relay Output Port (relay coil controlled by IO46 of ESP32-S3) * | ||
COM | Relay Common Terminal | |
NO | Relay Normally Open Terminal | |
Digital IN | ||
8 optically isolated digital input ports | ||
DGND | Ground terminal for digital input (fully isolated, separate ground for digital input, not connected to system ground) | |
DI1 | Channel 1 digital input port, connected to IO6 of ESP32-S3 | |
DI2 | Channel 2 digital input port, connected to IO7 of ESP32-S3 | |
DI3 | Channel 3 digital input port, connected to IO18 of ESP32-S3 | |
DI4 | Channel 4 digital input port, connected to IO35 of ESP32-S3 | |
DI5 | Channel 5 digital input port, connected to IO36 of ESP32-S3 | |
DI6 | Channel 6 digital input port, connected to IO37 of ESP32-S3 | |
DI7 | Channel 7 digital input port, connected to IO38 of ESP32-S3 | |
DI8 | Channel 8 digital input port, connected to IO39 of ESP32-S3 | |
GPIO/I2C/UART | ||
ESP32-S3 native GPIO/I2C/UART (non-isolated) | ||
IO4 | ESP32-S3 native IO4, supports digital and analog signals | |
IO5 | ESP32-S3 native IO5, supports digital and analog signals | |
SCL | I2C SDA, ESP32-S3 IO2 | |
SDA | I2C SDA, ESP32-S3 IO1 | |
TXD | UART TX, ESP32-S3 IO6 | |
RXD | UART RX , ESP32-S3 IO8 | |
POWER | ||
Power Output | ||
3V3 | 3.3V Output | |
5V | 5V Output | |
GND | Negative terminal of the power supply (system ground) | |
GND | Negative terminal of the power supply (system ground) |
Specifications
System Parameters
Power Supply Voltage: 12V~24V Power Supply Interface: DC2.1 / Terminal Blocks Main Core Chip: ESP32-S3 Program Download Interface: USB-Type C RTC Error: ±3 seconds in 30 days RTC Backup Power: Maintains clock for 12 hours after power failure Reset Button: 1
Input and Output Interfaces
DMX512 Output Interface: Three-pin XLR female connector Relay Output Interface: 1 Optically Isolated Digital Input Interfaces: 8 Polarity Support for Digital Sensors: PNP I2C Interface: 1 UART Interface: 1 GPIO: 2 BLINK-LED: 1
Physical Parameters
Mounting Options: Rail mount, ear mount Enclosure: Alloy steel Product Weight: 400g Product Size: 158mm×83mm×37mm (see product dimension size for details)
Downloading and Installing the Programming Platform
Downloading and Installing Arduino IDE
Downloading Arduino IDE
Click to visit the Arduino official website to download Arduino IDE.
Choose the appropriate IDE installation package based on your computer's operating system.
Downloading and Installing the SDK
Import ESP32 JSON Link
Click on the menu: File-Preferences, and the Preferences dialog box will pop up. Then click on the location shown in the figure below to open the link filling window.
Copy the following link address to the newly opened dialog box, then click the "OK" button.
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
Installing the SDK
Click on the menu: Tools-Board-Board Manager. Enter the board manager, as shown in the figure below:
Enter "esp32" in the search box, select "esp32" in the search results, and click install. As shown in the figure below:
Light up the blink light.
Function Description
On the DMX512 controller, there is a blue LED onboard, internally connected to IO21 of the ESP32-S3. This LED is used for quickly verifying code and facilitating program debugging. As shown in the figure below:
Testing Steps
ArduinoIDE
- Use a Type-C USB cable to connect the USB interface on the back of the controller to the computer.
- Open Arduino IDE.
- From the IDE menu, select: Tools > Board > ESP32S3 Dev Module.
- From the IDE menu, select: Tools > Port > The port corresponding to the development board (e.g., COM3 in the figure, the port number may vary on different computers).
Copy the following code to the editor:
#include "DFRobot_DMX512.h"
DFRobot_DMX512 dmx512;
void setup() {
Serial.begin(115200);
while(dmx512.begin() != 0){ //Initialize DMX512.
Serial.println("init error");
delay(1000);
}
Serial.println("init OK");
pinMode(21, OUTPUT);//Set pin 21 as output mode.
}
void loop() {
digitalWrite(21, HIGH); //Write high level to the port.
delay(1000); // Delay one second.
digitalWrite(21, LOW); //Write low level to the port.
delay(1000); //Delay one second.
}
Compile and download the program to the controller.
After the program download is complete, you will see the blue LED on the controller blinking at a frequency of one second.
Control the light strip
Function Description
Controlling the light strip requires the use of a DMX512 driver. The main function of the driver is to drive the light strip to emit light. DMX512 can be cascaded to form light strips with more channels. Furthermore, multiple drivers can be controlled by a single DMX512 programming controller.
DMX512 driver instructions and settings
The driver used in this WIKI example is a 24-channel LED light strip or 8-channel RGB light strip driver. You can also cascade multiple drivers using the RJ45 port or XLR port, with a maximum of 21 drivers cascaded to form 512 LED light strips or 170 RGB light strips.
This device can be connected to a DMX512 programming controller via a three-pin XLR port to receive DMX512 control signals, thereby controlling the lighting effects.
The use of other drivers is similar to the example in the routine. For specific usage, please refer to the corresponding driver manual.
Functional Indicator Diagram
Hardware Connection and Set
Controller to Driver Wiring Diagram
The DMX512 interface internally uses an RS485 bus. Whether the interface is connected to IN or OUT, the effect is the same, and there is no need to distinguish between them. You can choose to plug the male or female head based on the connectors of your connecting cable.
The driver needs to be powered separately to function properly. The operating voltage of the driver is between 5V and 24V. It is important to note that the power supply voltage must match the rated voltage of the light strip. For example, if the light strip is 12V, the power supply voltage of the driver must be 12V.
LED Light Strip Wiring Diagram
RGB Light Strip Wiring Diagram
The driver used in this example supports common anode RGB light strips. RGB light strips are divided into common anode and common cathode types, depending on whether the common pole is the positive pole (common anode) or the negative pole (common cathode). Pay attention to this distinction when purchasing light strips.
Driver Address Setting
RGB light strips consist of three different colored lights: red, green, and blue. Each color is connected to a separate channel on the driver, so one RGB light strip occupies three channel addresses.
Since the drivers can be cascaded, each channel has its own channel address. After setting the address for the first channel, the addresses for the subsequent channels are incremented by 1.
The channel address setting method is as follows:
- Press and hold the "A: Address" button or the "H: Mode" button. The brightness of the digital tube will increase.
- Press "-" to decrease the address or "+" to increase it. The address range is 1-512.
- Set the starting address to A001.
Complete the starting address setting.
** As shown in the figure: **
Example: Turn On and Off the Light Strip
First, download and import the DMX512 library. Here is the link to the library:
https://github.com/DFRobot/DFRobot_DMX512
Below are three methods to turn on and off the light strip, demonstrating the functionality and usage of three APIs.
Write Data to a Specified Address
API Prototype: dmx512.write(DMX512 Address, Data to be Written)
API Description: This is the most basic command for writing data to a DMX512 address. Based on this command, almost all DMX512 control functions can be achieved.
Data Range:
- DMX512 Address:1-512
- Data to be Written:0-255
Arduino Code
Code Function: Turn on the first LED light strip and blink at intervals of 1 second.
#include "DFRobot_DMX512.h"
DFRobot_DMX512 dmx512;
void setup() {
Serial.begin(115200);
while(dmx512.begin() != 0){ //Initialize DMX512
Serial.println("init error");
delay(1000);
}
Serial.println("init OK");
}
void loop() {
dmx512.write(1,255); //Assign a value of 255 to channel 1.
delay(1000); //Delay one second.
dmx512.write(1,0); //Assign a value of 255 to channel 0.
delay(1000); //Delay one second.
}
LED Light Control
API Prototype: dmx512.LEDLight( Starting Address, The number of LED lights, Brightness)
API Description: This command is specifically for controlling LED light strips. Based on this command, it is very convenient to control the LED light strips.
Data Range:
- Start Address: 1-512
- Number of LED Lights: 1-512
- Brightness: 0-255
Arduino Code
Light up the first to the eighth LED light strips and make them blink at 1-second intervals.
#include "DFRobot_DMX512.h"
DFRobot_DMX512 dmx512;
void setup() {
Serial.begin(115200);
while(dmx512.begin() != 0){ //Initialize DMX512.
Serial.println("init error");
delay(1000);
}
Serial.println("init OK");
}
void loop() {
dmx512.LEDLight(1,8,255); //Starting from channel 1, light up a total of 8 channels of LEDs with maximum brightness.
delay(1000); //delay 1s
dmx512.LEDLight(1,8,0); //Turn off the first to the eighth LED light strips.
delay(1000); //delay 1s
}
RGB Light Control
API Prototype: dmx512.RGBLight(Start Address, Number of RGB Lights, Red Channel, Green Channel, Blue Channel)
API Description: Each RGB light strip will occupy 3 channels, which is inconvenient for calculation. To facilitate use, a command specifically designed to control RGB light strips has been developed. Based on this command, it is very convenient to control RGB light strips.
Data Range:
- Start Address: 1-512
- Number of RGB Light Strips: 1-170
- RGB Channel Value: 0-255
Arduino Code
Light up the first to the eighth RGB light strips, displaying the color blue, and make them blink at 1-second intervals.
#include "DFRobot_DMX512.h"
DFRobot_DMX512 dmx512;
void setup() {
Serial.begin(115200);
while(dmx512.begin() != 0){ //Initialize DMX512
Serial.println("init error");
delay(1000);
}
Serial.println("init OK");
}
void loop() {
dmx512.RGBLight(1,8,0,0,255); //Starting from address 1, light up a total of 8 RGB light strips, with the RGB light strips displaying blue.
delay(1000); //Delay 1s
dmx512.RGBLight(1,8,0,0,0); //Turn off a total of 8 RGB light strips starting from address 1.
delay(1000); //Delay 1s
}
moving head beam light
The "moving head beam light" is a common type of stage lighting fixture that uses the DMX512 protocol and can rotate 360 degrees in both the X and Y directions. While the specific instructions for different manufacturers' moving head beam lights may vary, the overall method of use is consistent. The example below will illustrate how to control a moving head beam light.
Control Commands for Moving Head Beam Light
The following is an example illustrating the control commands for moving head beam lights, as shown in the table below:
Channel/Address | Data | Function Description |
---|---|---|
1 | 0-255 | X-Axis Rotation |
2 | 0-255 | Y-Axis Rotation |
3 | 0-7 | Turn Off Light |
8-134 | Overall Dimmer | |
135-239 | Strobe | |
240-255 | Turn On Light | |
4 | 0-255 | Red Light Value |
5 | 0-255 | Green Light Value |
6 | 0-255 | Blue Light Value |
Different moving head beam lights have different functions and control commands. It is essential to refer to the moving head beam light's function description for proper operation and control.
Hardware Connection
Both the DMX512 controller and the moving head beam lights require independent power supplies. They only need one XLR connection cable for communication. Additionally, the moving head beam lights can be cascaded with light strip controllers or other DMX512 devices for simultaneous control.
Program Writing
If you have not yet downloaded and imported the DMX512 library, please download it from this link and import it:
https://github.com/DFRobot/DFRobot_DMX512
Arduino Code
The following program demonstrates how to control the light and angle of the moving head beam lights. The program changes the angle and color of the light projection every second.
#include "DFRobot_DMX512.h"
DFRobot_DMX512 dmx512;
void setup() {
Serial.begin(115200);
while(dmx512.begin() != 0){ //Initialize DMX512
Serial.println("init error");
delay(1000);
}
Serial.println("init OK");
dmx512.write(3,255); //Turn On the Light
}
void loop() {
dmx512.write(1,255); //Assign a value of 120 to channel 1, adjusting the angle on the X-axis.
dmx512.write(2,50); //Assign a value of 50 to channel 2, adjusting the angle on the Y-axis.
dmx512.write(4,200); //Assign a value of 200 to channel 4, adjusting the red value of the light.
dmx512.write(5,100); //Assign a value of 100 to channel 5, adjusting the green value of the light.
dmx512.write(6,120); //Assign a value of 120 to channel 6, adjusting the blue value of the light.
delay(1000);
dmx512.write(1,120); //Assign a value of 30 to channel 1 to adjust the X-axis angle.
dmx512.write(2,150); //Assign a value of 150 to channel 2 to adjust the Y-axis angle.
dmx512.write(4,50); //Assign a value of 50 to channel 4 to adjust the red value of the light.
dmx512.write(5,160); //Assign a value of 160 to channel 5 to adjust the green value of the light.
dmx512.write(6,40); //Assign a value of 40 to channel 6 to adjust the blue value of the light.
delay(1000);
}
Light Up WS2812 Light Strip
Function Description
WS2812 is a type of single-wire controlled light strip. Each LED chip is integrated with a control chip, allowing independent control of each LED's on/off state and color. This enables the creation of cool lighting effects. The DMX512 controller has reserved two IO ports, IO4 and IO5, which can be used to drive WS2812 light strips.
Note: WS2812 light strips have a relatively high power consumption and require external 5V power supply. If only the controller is powered, it may cause insufficient power supply and even damage the controller's power chip.
Hardware Connection
Example 1: WS2812 Rainbow Light
WS2812 Light Strip Library Download Link:
https://github.com/adafruit/Adafruit_NeoPixel
Program Function: The light strip displays in rainbow colors.
#include <Adafruit_NeoPixel.h>
#define LED_PIN 4 //Set the pin number for connection.
#define LED_COUNT 137 //Set the total number of LEDs.
#define BRIGHTNESS 255 //Set the brightness, maximum 255.
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRBW + NEO_KHZ800);
void setup() {
strip.begin();
strip.show();
strip.setBrightness(BRIGHTNESS);
for(int i=0; i<strip.numPixels(); i++) {
uint32_t pixelHue = 40 + (i * 65536L / strip.numPixels());
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue, 255,255 )));
}
strip.show();
}
void loop() {
delay(1);
}
Example 2: WS2812 Flowing Light
Program Function: The light strip flows dynamically like water.
#include <Adafruit_NeoPixel.h>
#define LED_PIN 4
#define LED_COUNT 137
#define BRIGHTNESS 255
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRBW + NEO_KHZ800);
void setup() {
strip.begin();
strip.show();
strip.setBrightness(BRIGHTNESS);
}
void loop() {
for(uint32_t firstPixelHue = 0; firstPixelHue < 3*65536;
firstPixelHue += 256) {
for(int i=0; i<strip.numPixels(); i++) {
uint32_t pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue, 255,
255)));
}
strip.show();
delay(3);
}
}
Example 3: WS2812 Breathing Light
Program Function: The light strip fades in and out like breathing.
#include <Adafruit_NeoPixel.h>
#define LED_PIN 4
#define LED_COUNT 137
#define BRIGHTNESS 255
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRBW + NEO_KHZ800);
void setup() {
strip.begin();
strip.show();
strip.setBrightness(BRIGHTNESS);
}
void loop() {
for(int j=0; j<256; j++) {
strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
strip.show();
delay(5);
}
for(int j=255; j>=0; j--) {
strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
strip.show();
delay(5);
}
}
Example 4: WS2812 Running Light
Program Function: The light strip cycles dynamically like a racetrack.
#include <Adafruit_NeoPixel.h>
#define LED_PIN 4
#define LED_COUNT 137
#define BRIGHTNESS 255
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRBW + NEO_KHZ800);
int head = 10 - 1;
int tail = 0;
uint32_t lastTime = millis();
uint32_t firstPixelHue = 0;
int whiteSpeed = 20;
void setup() {
strip.begin();
strip.show();
strip.setBrightness(BRIGHTNESS);
}
void loop() {
for(int i=0; i<strip.numPixels(); i++) {
if(((i >= tail) && (i <= head)) ||
((tail > head) && ((i >= tail) || (i <= head)))) {
strip.setPixelColor(i, strip.Color(0, 0, 0, 255));
} else {
int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
}
}
strip.show();
firstPixelHue += 40;
if((millis() - lastTime) > whiteSpeed) {
if(++head >= strip.numPixels()) {
head = 0;
}
if(++tail >= strip.numPixels()) {
tail = 0;
}
lastTime = millis();
}
if(firstPixelHue > 3 * 65536)
firstPixelHue = 0;
}
Relay OUT
Function Description
DMX512 provides 1 channel relay output port, which is controlled by IO46 and can be used to drive intermediate relays, control the on/off of motors, audio devices, etc. The functional ports are shown in the figure below:
Port numbering | Port description |
---|---|
COM | Relay common pole |
NO | Relay normally open pole |
Note: This controller is built-in with low-power, low-voltage relay, only suitable for switching operations of DC power supply below 30V and 2A. For high-current devices, an external intermediate relay should be used to avoid damaging the built-in relay.
Wiring Diagram
Function Description: The following wiring diagram will illustrate the internal switching principle of the relay and the connection method for external devices.
Example: Controlling the Relay
The following program demonstrates how to drive the relay to cyclically close and open every second through programming. When the program runs, you can hear the relay being activated every second. Measuring the COM and NO terminals with a multimeter in continuity mode will show that they connect every second. If there is an external device, you will see it operate every second.
#include "DFRobot_DMX512.h"
DFRobot_DMX512 dmx512;
void setup() {
Serial.begin(115200);
while(dmx512.begin() != 0){ //Initialize DMX512
Serial.println("init error");
delay(1000);
}
Serial.println("init OK");
}
void loop() {
dmx512.relayOUT(1);
delay(1000);
dmx512.relayOUT(0);
delay(1000);
}
DI1-DI8 Industrial Digital Input Interfaces (Fully Isolated)
Function Description
The DMX512 controller is equipped with 8 channels of fully isolated digital input ports, supporting PNP sensor connection. The voltage level supports 12V-24V. As shown below:
Port numbering | ESP32-S3 pins | Port description |
---|---|---|
DGND | Digital input ground | |
DI1 | IO6 | Digital input port 1 |
DI2 | IO7 | Digital input port 2 |
DI3 | IO8 | Digital input port 3 |
DI4 | IO35 | Digital input port 4 |
DI5 | IO36 | Digital input port 5 |
DI6 | IO37 | Digital input port 6 |
DI7 | IO38 | Digital input port 7 |
DI8 | IO39 | Digital input port 8 |
Example: Infrared switch controls the on/off of the light strip
Below, we will connect a PNP infrared switch sensor to pin D1. When the infrared switch detects an obstruction, the LED strip will light up; otherwise, it will turn off.
Wiring diagram
Programming
If you haven't downloaded and imported the DMX512 library yet, please download it from the following link and import it:
https://github.com/DFRobot/DFRobot_DMX512
This program demonstrates using an infrared switch to control the on/off of DMX512 lighting. When the infrared switch is blocked, the light is on; otherwise, it is off.
#include "DFRobot_DMX512.h"
DFRobot_DMX512 dmx512;
void setup() {
Serial.begin(115200);
while(dmx512.begin() != 0){ //Initialize DMX512
Serial.println("init error");
delay(1000);
}
Serial.println("init OK");
}
void loop() {
if (dmx512.digitalIN(DI1) == HIGH) { //The infrared switch is connected to the DI1 interface.
dmx512.RGBLight(1,8,0,0,0); //Turn off the first to eighth LED strips.
} else {
dmx512.RGBLight(1,8,0,0,255); //Light up the first to eighth LED strips, displaying them in blue.
}
}
RS485 Port
Function Description
The product features a fully isolated RS485 interface that supports both RS485 master and slave modes, as well as the standard Modbus protocol.
In RS485 master mode, it can be connected to devices such as industrial sensors, relays, data loggers, and motor drives, providing strong practicality for project deployment.
In RS485 slave mode, it can be used for controller cascading communication, light synchronization, and other functions.
RS485 is connected to pins IO12 and IO13, mapped as follows: IO12: TX, IO13: RX, mapped to Serial1. The RS485 send/receive control pin is IO11.
Wiring diagram
This example will demonstrate how to use the RS485 interface to read distance values from a laser ranging sensor and print them to the serial port. With this example, you can use the RS485 interface to connect more industrial devices, such as ADC acquisition, multi-channel switch quantity acquisition, etc., to achieve more interactive lighting effects. RS485 laser ranging sensor datasheet link:
https://wiki.dfrobot.com/Laser_Ranging_Sensor_RS485_4m_SKU_SEN0492
Programming
The following example demonstrates reading the distance measured by a laser sensor using the RS485 interface and printing the distance value in millimeters (mm) to the serial port.
#include "DFRobot_RTU.h"
DFRobot_RTU modbus(&Serial1,11); //Set the data channel for RS485 to Serial1 and the receive/transmit control pin to IO11.
void setup() {
Serial.begin(115200);
Serial1.begin(115200, SERIAL_8N1, /*rx =*/13, /*tx =*/12); //Baud rate 115200, data bits 8, stop bits 1, RX pin IO13, TX pin IO12.
delay(1000);
}
void loop() {
int ret = modbus.readHoldingRegister(/*485 address*/0x50, /*Register address*/ 0x0034); //Read the holding register, reading one register.
Serial.println(ret);
delay(1000);
}
RTC
Function Description
The DMX512 controller is equipped with an RTC clock chip, which can maintain the system clock running in offline state. The backup power supply can save the clock for about 12 hours in case of power failure.
You can set and read the date and time of the RTC clock, including year, month, day, hour, minute, second, and alarm settings.
The addition of clock function will greatly facilitate various timing controls, such as timed switch lights, color or pattern changes of lights in different time periods, and so on.
Example: Setting and Reading Clock
If you haven't downloaded and imported the DMX512 library yet, please download it from this link and import it:
https://github.com/DFRobot/DFRobot_DMX512
In the following example, we will demonstrate how to set and read the RTC, and print it in the serial monitor. If you only need to read the clock the second time, you can delete the part of the code in "Setup" that sets the clock.
#include "DFRobot_Peripheral.h"
DFRobot_RTC rtc;
void setup() {
Serial.begin(115200);
while(rtc.begin() != 0){
Serial.println("init error");
delay(1000);
}
Serial.println("init succeed");
rtc.stopClock();
rtc.setYear(24);
rtc.setMonth(rtc.eFeb);
rtc.setDay(19);
rtc.setWeek(rtc.eWed);
rtc.setHour(9);
rtc.setMinute(10);
rtc.setSecond(30);
rtc.startClock();
}
void loop(){
sTime_t time;
time = rtc.getTime();
Serial.print("year:20");
Serial.println(time.year);
Serial.print("month:");
Serial.println(time.month);
Serial.print("day:");
Serial.println(time.day);
Serial.print("weekday:");
Serial.println(time.week);
Serial.print("hour:");
Serial.println(time.hour);
Serial.print("minute:");
Serial.println(time.minute);
Serial.print("second:");
Serial.println(time.second);
Serial.println("--------------------------------------------------------");
delay(100);
}
Native GPIO pins of ESP32-S3
Function Description
The DMX512 controller features two GPIOs, IO4 and IO5, supporting digital input/output and analog input. They can be used for connecting digital sensors, driving two servos, two analog inputs, or driving WS2812 LED strips, among other applications. Its usage is identical to the conventional ESP32.
Example: Music Spectrum Light
Wiring diagram
The following code demonstrates using IO4 to connect an analog sound level meter module and driving the number of RGB light strips with the sound intensity, creating a simple music spectrum light effect.
#include "DFRobot_DMX512.h"
DFRobot_DMX512 dmx512;
void setup() {
Serial.begin(115200);
while(dmx512.begin() != 0){ //Initialize DMX512.
Serial.println("init error");
delay(1000);
}
Serial.println("init OK");
}
void loop() {
int datasound = analogRead(4);
Serial.println(datasound);
int leddata = map(datasound, 1000, 2500, 0, 8);
dmx512.RGBLight(1,leddata,0,0,255);
delay(30);
dmx512.RGBLight(leddata*3+1,8,0,0,0);
delay(30);
}
ESP32-S3 native I2C interface
Function Description
The DMX512 controller provides an I2C interface, which can be used to connect a large number of open-source hardware sensors and actuators, greatly expanding the controller's application scenarios.
The mapping of I2C pins is as follows:
Pins | Pins function |
---|---|
SDA | ESP32-S3 IO1 |
SCL | ESP32-S3 IO2 |
Example 1: Light Sensing LED
The program will demonstrate how to read the value from the LTR390 light sensor using the I2C interface. The sensor supports power supply from 3.3V to 5V, and it can communicate via UART and I2C. Additionally, there is an Arduino library available for direct use.
Product Link:
https://www.dfrobot.com/product-2650.html
Download Arduino Library:
https://github.com/DFROBOT/DFRobot_LTR390UV
Wiring diagram
Please switch the communication mode switch of the sensor to the I2C side before use.
Arduino Code
Program Function: The following example demonstrates reading the values of the LTR390 light sensor using the I2C interface.
#include "DFRobot_LTR390UV.h"
#include "DFRobot_DMX512.h"
DFRobot_LTR390UV ltr390(/*addr = */LTR390UV_DEVICE_ADDR, /*pWire = */&Wire);
DFRobot_DMX512 dmx512;
void setup()
{
Serial.begin(115200);
while(dmx512.begin() != 0){ //Initialize DMX512.
Serial.println("init error");
delay(1000);
}
Serial.println("init OK");
while(ltr390.begin() != 0){
Serial.println(" Sensor initialize failed!!");
delay(1000);
}
Serial.println(" Sensor initialize success!!");
ltr390.setALSOrUVSMeasRate(ltr390.e18bit,ltr390.e100ms);//18-bit data, sampling time 100ms.
ltr390.setALSOrUVSGain(ltr390.eGain3);//3x gain
ltr390.setMode(ltr390.eALSMode); //Set ambient light mode
}
void loop()
{
float als = 0;
als = ltr390.readALSTransformData();//Get ambient light data
Serial.println(als);
int dataals = map(als,0,14500,1,8);
Serial.println(dataals);
dmx512.RGBLight(1,dataals,0,0,255);
delay(30);
dmx512.RGBLight(dataals*3+1,8,0,0,0);
delay(30);
}
Example 2: Voice Recognition Light
This example demonstrates controlling DMX512 lighting using offline voice recognition. You'll need to connect an I2C interface offline voice recognition module. Here is the product link:
https://www.dfrobot.com/product-2665.html
Arduino Library Download Link:
https://github.com/DFRobot/DFRobot_DF2301Q
Wiring diagram
When using, please switch the communication mode switch of the voice recognition module to the I2C side.
Arduino Code
The program functions as follows:
- Wake up: "Hello,Robot."
- Say: "Turn on the lights" // lights turn on
- Say: "Set to red" // lights set to red
- Say: "Set to blue" // lights set to blue
- Say: "Set to green" // lights set to green
- Say: "Turn off the lights" // lights turn off
#include "DFRobot_DF2301Q.h"
#include "DFRobot_DMX512.h"
DFRobot_DMX512 dmx512;
DFRobot_DF2301Q_I2C asr;
uint8_t state = 0;
void setup() {
Serial.begin(115200);
while(dmx512.begin() != 0){ //Initialize DMX512.
Serial.println("init error");
delay(1000);
}
Serial.println("init OK");
while (!(asr.begin())) {
Serial.println("Communication with device failed, please check connection");
delay(3000);
}
Serial.println("Begin ok!");
asr.setVolume(4);
asr.setMuteMode(0);
asr.setWakeTime(20);
uint8_t wakeTime = 0;
wakeTime = asr.getWakeTime();
Serial.print("wakeTime = ");
Serial.println(wakeTime);
}
void loop() {
uint8_t CMDID = asr.getCMDID();
switch (CMDID) {
case 117: //Command 'Turn on the lights
state = 1;
dmx512.RGBLight(1,8,255,255,255);
break;
case 118: //Command 'Turn off the lights
state = 0;
dmx512.RGBLight(1,8,0,0,0);
break;
case 130: //Command 'Set to Red
if(state == 1)
dmx512.RGBLight(1,8,100,0,0);
break;
case 133: //Command 'Set to Green
if(state == 1)
dmx512.RGBLight(1,8,0,100,0);
break;
case 135: //Command 'Set to Blue
if(state == 1)
dmx512.RGBLight(1,8,0,0,100);
break;
default:
if (CMDID != 0) {
Serial.print("CMDID = ");
Serial.println(CMDID);
}
}
delay(300);
}
ESP32-S3 native UART interface
Function Description
In the DMX512 controller, the ESP32-S3 native UART is exposed, as shown in the diagram:
The UART pin configuration on the exposed terminals is as follows:
Ports | ESP32-S3 Pins |
---|---|
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
When using, please switch the sensor's communication mode switch to the UART side.
Arduino Code
#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);
}
ESP32-S3 Wi-Fi and Bluetooth
DMX512 utilizes the ESP32-S3 module, which features built-in WIFI and Bluetooth 5.0 connectivity, utilizing an SMA rod antenna for wireless communication. The addition of WIFI and Bluetooth functionality enables various lighting effects such as remote light control and networking. The development process for WIFI and Bluetooth is consistent with the standard ESP32-S3, as detailed in the documentation:
https://wiki.dfrobot.com/SKU_DFR0975_FireBeetle_2_Board_ESP32_S3_Advanced_Tutorial#target_0