A Keychain for IEEE at CWRU
Using a CH32 microcontroller to bring merriment to the holiday season


Why?
I'm part of IEEE's student branch at Case Western Reserve University. Every year the ECSE department puts on a Christmas party and IEEE hands out goodie bags. This year instead of a cheap toy we added a custom keychain which I had the pleasure of designing. The design is intentionally simple. The brain is a CH32V003F4P6, a 48 MHz RISC-V microcontroller in a TSSOP-20 package with 16 KB of flash. It runs on anything from 2.7 V to 5.5 V, so it can be powered straight from USB with no voltage regulator at all. Ten of its GPIO pins each drive one LED through its own current-limiting resistor, so every LED can be controlled independently. One more pin reads the push button, which switches between light animations. Firmware is loaded through WCH's single-wire SWDIO debug interface, which only needs one data pin plus power and ground.


Schematic
The whole circuit fits on one page. J2 is a power-only USB-C receptacle. The two 5.1 kΩ pull-down resistors on the CC1 and CC2 pins (R12 and R13) identify the keychain as a USB device, which is what tells a USB-C charger it is allowed to turn on 5 V; without them, a C-to-C charger supplies nothing. VBUS then passes through a 4.7 Ω resistor (R1) into a 4.7 µF capacitor (C1), forming a small RC filter that also softens the inrush current when the keychain is plugged in. Each of the ten LEDs (D1 to D10) hangs off its own GPIO pin with a series resistor to ground. The button (SW1) pulls the BTTN pin up to 5 V when pressed, and a 1 kΩ resistor (R14) holds it low the rest of the time. J1 is the programming connector, carrying 5 V, ground, SWDIO and NRST.
The CWRU IEEE logo is drawn in silkscreen as an oversized SOIC-8 package, and the ten LEDs and their resistors sit in two rows above and below it. It is a two-layer board: every component and nearly all of the routing is on the top layer, and the bottom is a solid ground pour. The plated keyring hole is ta standard plated m3 mounting hole. The USB-C receptacle sits on a narrow tab at one end so it is easy to plug in, and the programming pads (J1) are tucked into the corner next to the microcontroller. The back silkscreen lists the names of this year's IEEE exec board.


PCB
Assembly and Programming
The boards were fabricated and fully assembled by JLCPCB for less than a dollar each. The only work left was snapping them apart and loading firmware. To program each one, I power the keychain from USB-C and use a regular ESP32 dev. I wrote a script on the ESP32 to upload my C code and Because the CH32V003 uses single-wire SWD, there are only a few contacts to line up. I connect one pad to ground and the other to a ESP32s GPIO pin thru a 1k resistor (the ESP32 is a 3.3v board and the keychain is a 5v board).




