Controlling an RGB LED light strip over the network via a Raspberry Pi
- Should work with 12V common-anode RGB LED strips
- Web form for setting colors (color picker imported from taufik-nurrohman/color-picker, falls back to HTML5 color picker if no JavaScript)
- HTTP JSON API for setting colors, predefined patterns, or custom timed patterns
- UDP OSC API for setting colors or predefined patterns (tested from Sonic Pi)
Note: I only know enough about electronics hardware to be dangerous. This could fry a Raspberry Pi given it is using an external (but regulated) non-USB power source or fry it for other reasons. It hasn't broken mine yet running all of the time but it is still quite possible. I'm not responsible if the hardware causes the magic blue smoke to leave your Raspberry Pi or summons demons that break your LED strip.
- 3x N-channel MOSFETs
- 3x 15 Ω resistors (other small resistors would work; probably not required)
- 1x ATX Power Connector Breakout Kit
- 1x Raspberry Pi (tested with RPi 4B but other models should work)
Image generated with Fritzing
A Rust toolchain (stable or unstable) is required, and using rustup is recommended to ensure a current toolchain on Raspberry Pi OS. Running cargo run --release
will run the daemon, which includes a light pattern animation and output thread, HTTP server, WebSocket server, and OSC server. In a deployment, the static
and templates
directories as well as the binary are the only artifacts needed.
Method | Description |
---|---|
GET |
Retrieve current color (including currently displayed color of pattern) |
PUT |
Set a solid color |
{
"red": 0,
"green": 169,
"blue": 255
}
Method | Description |
---|---|
GET |
Retrieve current pattern |
PUT |
Set a new pattern |
{
"type": "off"
}
{
"type": "solid",
"content": {
"red": 255,
"green": 0,
"blue": 195
}
}
Durations are in milliseconds
{
"type": "custom",
"content": [
{
"color": {
"red": 255,
"green": 0,
"blue": 137
},
"duration": 500
},
{
"color": {
"red": 0,
"green": 140,
"blue": 255
},
"duration": 500
},
{
"color": {
"red": 255,
"green": 255,
"blue": 255
},
"duration": 500
}
]
}
Multiple formats accepted
red: int32
green: int32
blue: int32
red: float32
green: float32
blue: float32
red: float64
green: float64
blue: float64
color: rgba
[no arguments]
Multiple formats accepted
red: int32
green: int32
blue: int32
red: float32
green: float32
blue: float32
red: float64
green: float64
blue: float64
color: rgba
The WebSocket interface streams color updates to the client (which includes color updates as part of timed patterns) and supports receiving messages to set solid colors.
The URI to connect to the WebSocket can be retrieved by making a GET
request to the /wsinfo
endpoint. If the response from /wsinfo
is empty, a default of ws://<hostname>:8001/
should be assumed.
{
"red": 0,
"green": 169,
"blue": 255
}