Demo Code
Waveshare provides demo projects for both the Arduino framework and ESP-IDF. Each demo targets a specific peripheral or feature of the board, making them useful as both verification tools and starting points for custom firmware. The demos progress from simple bus scans through individual peripheral tests to a full LVGL graphical interface, so working through them in order is a natural way to bring up a new board and confirm that all hardware is functioning.
Download
Section titled “Download”The complete demo package including all examples, libraries, and configuration files is available from the Waveshare wiki.
Download from Waveshare — look for the Demo Code download link on the wiki page.
Arduino Examples
Section titled “Arduino Examples”| Demo | Peripheral | Description |
|---|---|---|
| 01_I2C_Test | I2C | Scans the I2C bus from 0x01 to 0x7F, reports all responding device addresses. First test to run on a new board. |
| 02_RS485_Test | RS-485 (UART) | Echo test: receives data via RS-485 (Serial1, GPIO15 RX / GPIO16 TX at 115200 baud) and sends it back. |
| 03_SD_Test | SD Card (SPI) | Initializes CH422G IO expander, mounts SD card, performs file operations (create, write, read, rename, delete), reports card type and capacity. |
| 04_Sensor_AD | ADC | Reads analog sensor input and prints values to serial monitor. |
| 05_UART_Test | UART | Basic UART echo test. |
| 06_TWAItransmit | CAN (TWAI) | Transmits CAN frames (ID 0x0F6, 8 bytes, 50 kbit/s). Uses NO_ACK mode for standalone testing. Initializes CH422G for USB_SEL pin control. |
| 07_TWAIreceive | CAN (TWAI) | Receives CAN frames and prints ID, DLC, and data bytes. |
| 08_DrawColorBar | RGB LCD | Initializes the 800x480 RGB LCD and draws color bars. Verifies display hardware without LVGL dependency. |
| 09_lvgl_Porting | LCD + Touch + LVGL | Complete LVGL integration using ESP32_Display_Panel library. Initializes board, display, and touch, then runs the LVGL widget demo. |
ESP-IDF Examples
Section titled “ESP-IDF Examples”| Demo | Peripheral | Description |
|---|---|---|
| 01_I2C_Test | I2C | I2C bus scanner with console REPL interface. |
| 02_RS485_Test | RS-485 (UART) | UART echo over RS-485. Pin assignments and baud rate configurable via Kconfig menuconfig. |
| 03_SD_Test | SD Card (SPI) | SD card mount and file I/O using VFS FAT filesystem. Manages CH422G CS pin via raw I2C commands. |
| 04_Sensor_AD | ADC | Analog reading using ESP-IDF ADC oneshot driver. |
| 05_UART_Test | UART | UART echo task. |
| 06_TWAItransmit | CAN (TWAI) | CAN transmitter with alert monitoring (TX success, TX failure, bus errors, error passive state). |
| 07_TWAIreceive | CAN (TWAI) | CAN receiver with error checking. |
| 08_lvgl_Porting | LCD + Touch + LVGL | Full LVGL integration with multiple rendering modes (normal, full refresh, direct mode). Supports display rotation (0/90/180/270). Reference implementation for production display applications. |
Key Code Patterns
Section titled “Key Code Patterns”A few architectural patterns appear consistently across the demo code. Understanding them upfront saves time when adapting demos for your own firmware.
-
Initialize the IO expander first. The CH422G controls chip selects, resets, and signal routing for several peripherals. It must be configured before the SD card, display, touch controller, or CAN transceiver will respond. Every demo that touches hardware beyond basic UART begins with IO expander setup.
-
Address the CH422G correctly. The IO expander uses I2C address 0x24 for its mode/configuration register and 0x38 for the output register. These are not two separate devices — they are two register spaces within the same CH422G chip, addressed differently due to the chip’s I2C protocol design.
-
Set USB_SEL according to your interface needs. The EXIO5 pin on the CH422G controls the FSUSB42 USB multiplexer. When EXIO5 is LOW, GPIO19 and GPIO20 are routed to the USB connector (Type-C1, side port) for USB device or host operation. When EXIO5 is HIGH, those same pins are routed to the TJA1051T CAN transceiver. You cannot use USB native and CAN simultaneously — they share the same physical pins through the multiplexer.