CH32V003J4M6 (SOP-8) drives a 5x6 LED matrix with only 6 GPIOs.
- EasyEDA: https://oshwlab.com/mingjie/ch32v003-tristate-multiplexing-led
- YouTube: LED Chaser Terminator - Low-Cost CH32V003 MCU Drives a 5x6 LED Matrix with 6 GPIOs - 555 Timer RIP!
- Bilibili: Ultra Low-Cost LED Chaser - 6 GPIOs Drive a 5x6 LED Matrix
I programmed 5 boards to show running words. But as there is no synchronization among the boards, the boards will soon run out of sync.
The program uses the Tristate Multiplexing (Charlieplexing) technique to drive LEDs. Each GPIO is used as both row and column lines, so n GPIOs support n x (n - 1)
LEDs.
There is only one LED light at a time, and each LED supports 16 brightness levels. The program uses SysTick
to update the LED matrix 50,000 times per second, so each LED updates at 50,000/30/16 = 104Hz, which is too fast for human eyes to notice.
To program the CH32V003 microcontroller, you will need a programmer that supports SWD.
- The official WCH-LinkE programmer.
- Check CNLohr's ch32v003fun project for other options, such as ESP32S2 and Arduino-based programmers.
If the blue LED on the WCH-LinkE is always on, it is in ARM mode. To program CH32V003, it needs to be switched to RISC-V mode. Hold the Modes key while plugging it in the USB port.
Install RISC-V Toolchain.
brew tap riscv-software-src/riscv
brew install riscv-tools
This project uses the minichlink
utility to upload, so the libusb
is required as a dependency.
brew install libusb
Clone the project, connect the board to the programmer, then run the make
command to compile and upload the firmware.
git clone https://github.com/limingjie/CH32V003-Tristate-Multiplexing-LED.git
cd CH32V003-Tristate-Multiplexing-LED
make
The PD1/SWDIO
, PD4
, and PD5
share the same pin on CH32V003J4M6, after the program uploaded, it is not possible to upload again. Use the minichlink -u
command to clear all code flash (unbrick) and then upload.
./tools/minichlink -u
make
The minichlink
utility in the tools
library is built for x86_64
. If your macOS runs on Apple Silicon, you can build the minichlink
utility and copy it to the tools folder.
brew install pkg-config
brew install libusb
git clone https://github.com/cnlohr/ch32v003fun.git
cd ch32v003fun/minichlink
make