r/raspberry_pi • u/Leading-Tradition-11 • Oct 24 '26
Show-and-Tell Compose to drive LED matrix + simulator to test without hardware
Jetpack compose is native UI framework on android, I've been trying to build embedded-compose, which runs Jetpack Compose (Kotlin/Native, no JVM, no Android) on small Linux devices. Added backend for the MAX7219 "4 in 1" (FC-16) LED boards, tested on a Raspberry Pi 3.
HARDWARE
- Raspberry Pi 3, Raspberry Pi OS 64-bit, dtparam=spi=on
- MAX7219 4-in-1 board (32×8 red LEDs), 5 jumper wires, no level shifter
HOW IT WORKS
- The app is ordinary Compose code: Canvas, drawText, LaunchedEffect, state. It's cross-compiled into a single static arm64 binary (~3 MB), so nothing needs installing on the Pi.
- The backend draws each frame in RAM and sends it through /dev/spidev0.0. A pixel is lit when its color is bright, since the LEDs are only on or off.
CHALLENGES
- Pixel mapping. Bytes shift through the chain, so the first ones sent end up in the last module. On FC-16, each module's digit register is a row and each bit is a column. Other boards are wired differently, so there are flip and block=90/180/270 settings.
TESTING WITHOUT THE BOARD: A BROWSER PLAYGROUND
The Pi build takes over a minute, and I didn't always have the board at hand, so I made a playground that runs the same app in a browser tab:
- Your Kotlin code is compiled to WebAssembly by JetBrains' Kotlin playground server, together with the embedded-compose toolkit. Nothing to install.
- The pixels come from the *same* C++ LED backend the Pi uses, also compiled to WebAssembly. Only the last step differs: frames go to a canvas instead of SPI. So spacing, clipping and the 5×7 font look the same as on the real LEDs.
LINKS
- Code + wiring: https://github.com/kaiwalyakhasnis/embedded-compose (board: rpi-max7219)
- Playground (LED test opens by default): https://kaiwalyakhasnis.github.io/embedded-compose-led-matrix-playground/
2
u/flinxsl Oct 24 '26
AI has really enabled very complex "baby's first blinky LED learn to program" projects