Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!

CNLohr's microlcd Uses Bit-Bang Wizardry to Add USB, LCD, and Touch to the RISC-V CH32V003

Tiny three-digit LCD plugs into a USB-C port with no connector and a microcontroller without native USB support.

James Lewis
2 days ago β€’ Displays

The 10-cent RISC-V CH32V003 lacks native USB, LCD, or touch controller hardware. Yet, CNLohr implements all three with creative bit-banging techniques. The three-digit microlcd is a programmable USB-C dongle without physical buttons or USB-C connectors.

Previously, CNLohr created the 1,920-byte rv003usb bootloader. This tiny bit of code lets you re-program the USB-less microcontroller over USB. While that capability is valuable on its own, you can reuse about 250 lines of the bootloader's C-code to add USB support to a WCH CH32V003 project. By reusing that software driver, CNLohr can easily re-program the microcontroller and send updates to display values on the LCD.

CNLohr points out that displays like inexpensive three-digit seven-segment LCDs use Indium Tin Oxide (ITO) to achieve a transparent display. ITO is the same material used in touchscreens. So, it seemed possible that a display could also act as a touch element. However, before this feature could be realized, CNLohr had to overcome the challenge of driving the LCDs with an MCU that lacked a built-in LCD driver.

Diving LCD segments can be tricky since they require AC waveforms. Regardless, CNLohr was able to write some assembly code to handle the timing needed to achieve suitable signals from the CH32V003's digital pins. Check out around 5:43 in the project video for more details about the driving method.

The next outlandish task was using the LCD as a capacitive touch sensor. The LCD module connects to the MCU ADC input. A clever bit of timing code stops updating the LCD while detecting a human finger's presence. The voltage detected by the ADC correlates to the finger's distance. Using the ADC instead of a digital pin provides more flexibility for determining if the user is performing a gesture or a press action.

In the X thread announcing the video, @thornley_david suggested that a programmable RGB backlight was the only feature missing in the 3-digit microled. However, CNLohr quickly pointed out that you don't need a custom bit bang routine for that!

Microlcd's most expensive component is the printed circuit board (PCB). The LCD and MCU make up $0.31 of the bill of material cost, but the PCB costs about 10x that! However, that additional cost became necessary because CNLohr wanted to implement a USB-C connection without a connector. This requirement means the PCB needs a thickness of 0.6 millimeters and an ENIG (Gold) surface finish. The gold finish prevents the manufacturer from applying solder to the "edge" connector.

Bit Banging LCD + Touch + USB on the ch32v003

Check out the full project video for detailed explanations of how the touch sensor and LCD work. CNLohr also provides a brief explanation of the rv003usb bootloader code. You can download the code and KiCad design files from the ch32v003_3digit_lcd_usb GitHub repository.

James Lewis
Electronics enthusiast, Bald Engineer, and freelance content creator. AddOhms on YouTube. KN6FGY.
Latest articles
Sponsored articles
Related articles
Latest articles
Read more
Related articles