A Universal, Event-Driven, and Non-Blocking library for DWIN DGUS II T5L Displays.
Designed for industrial reliability, this library supports ESP32, STM32, and Arduino Mega platforms via the standard Stream interface. It simplifies complex HMI tasks like 32-bit data transfer, dynamic text updates, and system controls without blocking your main loop.
This library has been developed and strictly tested with the following industrial hardware setup:
| Component | Model / Spec | Description |
|---|---|---|
| HMI Display | DMG48270C043_03WTR | 4.3", 480x272, Resistive Touch, T5L ASIC |
| Controller | ESP32 Dev Kit V1 | 240MHz Dual Core, WiFi/BT, 3.3V Logic |
| Protocol | UART (TTL) | 8N1, 115200 Baud Rate |
Note: While tested on the 4.3" resistive model, this library is compatible with ALL DWIN DGUS II (T5L) displays regardless of size or touch type (Capacitive/Resistive).
Warning: DWIN T5L Displays typically require 5V power. Do not power large screens directly from the ESP32's 5V pin if the USB current is insufficient; use an external 5V source if needed.
| ESP32 Pin | DWIN Pin | Function |
|---|---|---|
| GPIO 16 (RX2) | TX | Receive Data from Display |
| GPIO 17 (TX2) | RX | Send Commands to Display |
| GND | GND | Common Ground (Required) |
| 5V / 3.3V | VCC | Power Supply |
- Universal Compatibility: Works with
HardwareSerial,SoftwareSerial, or any class implementing the ArduinoStreaminterface. - Event-Driven Architecture: Stop polling registers! Use
attachCallback()to handle button presses, slider movements, and data returns instantly. - Non-Blocking Parser: The
listen()function uses an asynchronous Finite State Machine (FSM), keeping yourloop()running fast for other tasks (sensors, WiFi, etc.). - Comprehensive Data Support:
- β
16-bit Integers (
writeVP) - β
32-bit Longs (
writeVP32) - β
Float Numbers (
writeVPoverload) - Essential for sensors! - β
Dynamic Text (
setText) - Send strings easily.
- β
16-bit Integers (
- Full System Control:
- Change Pages, Adjust Brightness, Trigger Buzzer (Beep).
- Read/Set RTC (Real Time Clock).
- Multi-language support via Page Offset engine.
- Open Arduino IDE.
- Go to
Sketch->Include Library->Manage Libraries.... - Search for "DWIN_UNI_HMI".
- Click Install on the latest version.
- Download the latest release from this repository as a ZIP file.
- In Arduino IDE, go to
Sketch->Include Library->Add .ZIP Library. - Select the downloaded file.
Compatible with PlatformIO (drop into lib folder) and Arduino IDE.
We provide a Complete DWIN Project to help you test the library immediately, ruling out any GUI design errors.
Navigate to the extras/DWIN_DGUS/test/ folder in this repository:
-
Compiled Firmware (
DWIN_SETfolder):- Copy the entire
DWIN_SETfolder directly to the root of a formatted SD Card (FAT32, <16GB). - Insert it into the DWIN display and power cycle to flash the "ZEUS System" test interface.
- Includes all required fonts, icons, and configuration files.
- Copy the entire
-
Source Project:
- Contains the
.hmi(or.imp) project file. - Open with DGUS II Software to inspect how the variables and buttons are addressed.
- Contains the
Here is a comprehensive test suite. It demonstrates sending Text, Numbers (Int/Float), and handling Touch Feedback via Callbacks.
#include <Arduino.h>
#include <DWIN_UNI_HMI.h>
// Initialize the Library Object
Dwin hmi;
// --- Event Callback Function ---
// This function is triggered automatically when the screen sends data.
// It handles both 16-bit (Buttons) and 32-bit (Keyboards/Sliders) data.
void onHmiEvent(uint16_t address, uint32_t data, uint8_t len) {
Serial.print("Event Captured -> Addr: 0x");
Serial.print(address, HEX);
Serial.print(" | Data: ");
Serial.print(data);
Serial.print(" | Type: ");
if (len == 2) Serial.println("16-bit (Word)");
else if (len == 4) Serial.println("32-bit (DWord/Float)");
else Serial.println("Unknown");
// Example: Beep if button at 0x5000 is pressed
if (address == 0x5000) {
hmi.beep(5); // 50ms Feedback
}
}
void setup() {
Serial.begin(115200);
// --- Initialize UART for DWIN ---
// ESP32: Using Serial2 (RX=GPIO16, TX=GPIO17)
// For Mega/STM32, use Serial1 or Serial3 as needed.
Serial2.begin(115200, SERIAL_8N1, 16, 17);
hmi.begin(Serial2);
// Register the event callback
hmi.attachCallback(onHmiEvent);
Serial.println("DWIN HMI Initialized. Sending Test Data...");
// --- TEST 1: System Controls ---
hmi.setPage(0); // Switch to Home Page
hmi.setBrightness(100); // Set Backlight to 100%
hmi.beep(10); // Startup Beep (100ms)
delay(500);
// --- TEST 2: Dynamic Text ---
// Sends a String to the Text Display at VP 0x1000
hmi.setText(0x1000, "ZEUS SYSTEM ONLINE");
// --- TEST 3: Numeric Data Types ---
// 16-bit Integer (VP 0x2000)
hmi.writeVP(0x2000, (uint16_t)1024);
// 32-bit Long Integer (VP 0x3000)
hmi.writeVP32(0x3000, 123456789);
// Float / Decimal (VP 0x4000)
// Note: DWIN uses IEEE 754 standard for floats
hmi.writeVP(0x4000, 24.50f);
}
void loop() {
// CRITICAL: The listen() function must be called in the loop.
// It handles incoming serial data asynchronously.
hmi.listen();
}Initializes the DWIN object with the specified Serial port.
- @param
serial: Reference to HardwareSerial (e.g.,Serial2) or SoftwareSerial object.
MUST be called inside loop(). Processes incoming data from the display asynchronously (Non-blocking).
Registers a user-defined function to handle events (Button presses, Keypad entries).
- Callback Signature:
void func(uint16_t address, uint32_t data, uint8_t len)
Writes a standard 16-bit Integer (2 Bytes) to a Variable Pointer address.
- @param
address: VP Address (e.g.,0x1000). - @param
value: The integer to write.
Writes a 32-bit Long Integer (4 Bytes) to a Variable Pointer address.
- @param
address: VP Address. - @param
value: The long integer value.
Writes a Floating Point number (4 Bytes, IEEE 754) to a Variable Pointer address.
- @param
address: VP Address. - @param
value: The float value (e.g.,24.50).
Writes a String to a Text Display control.
- @param
address: VP Address of the Text Display. - @param
text: The string character array (Max 200 chars).
Requests data from the display. The response is handled asynchronously via the attached callback.
- @param
address: VP Address to read from. - @param
wordLen: Number of words to read (1 word = 2 bytes).
Switches the screen to a specific Page ID.
Sets the backlight brightness.
- @param
level: Brightness level (0-100).
Activates the internal buzzer.
- @param
duration: Beep duration in 10ms units (e.g.,10= 100ms).
void setRTC(uint8_t year, uint8_t month, uint8_t day, uint8_t weekDay, uint8_t hour, uint8_t minute, uint8_t second)
Sets the Real Time Clock (Address 0x9C).
Requests current time (Address 0x10). Response comes via callback.
Plays a .wae audio file from the SD card.
- @param
musicID: ID of the audio file. - @param
volume: Volume level (0x00 - 0x40).
Performs a software reboot of the HMI (Address 0x04).
Requests OS/GUI versions (Address 0x0F).
Dynamically changes the UART2 baud rate (Address 0x0C).
- Note: Calculation is
3225600 / BaudRate.
Enables or disables system flags (Address 0x80).
- @param
touchSound: Enable buzzer on touch. - @param
dataUpload: Enable auto-upload data on touch.
Shows or hides a "Popup" page over the current screen (Address 0xE8).
- @param
enable:trueto show,falseto hide. - @param
overlayPageID: The Page ID to show as overlay.
Changes the color of a Text Display control dynamically.
- @param
spAddress: The Description Pointer (SP) address (NOT VP!). - @param
color: 16-bit RGB565 Color.
Sets a Page ID offset for multi-language applications.
- Example: If offset is
10and you callsetPage(0), it goes to Page10.
Switches the background image library (ICL) instantly (Address 0xDE).
Click to see what's new in v1.2.0 and earlier versions
- Universal Architecture: Supports any
Stream(Hardware/Software Serial). - 32-bit & Float Support: Added
writeVP32and Float overloads. - Dynamic Text: New
setTextfunction. - System Controls: RTC, Brightness, Beep, and Reset commands.
- HMI Reference: Pre-compiled
DWIN_SETinextras/.
- Optimized FSM parser for 115200 baud reliability.
- Improved buffer management for long strings.
- Initial ESP32 Dev Kit V1 support.
- Basic callback event mechanism.
- Initial release. Basic 16-bit VP Read/Write.
This library is open-source and licensed under the MIT License.
Author: Askin Keles
Maintainer: Askin Keles (askinkeles@gmail.com)
