Firmware for esp32-c3 microcontroller written in Rust, which shows animations on sk6812 led strip. Compiled animations writen in animation-lang can be uploaded using build in web server.
Main idea of this project is to allow users write their own animations in animation-lang using web-fronend and send them to the microcontroller for demonstrating on sk6812 addressable led strip. For compiling and running animation-lang is used.
- Compiler is running in client browser though webassembly, it converts source code into bytecode (p-code).
- Virtual-machine (p-code machine) is running on microcontroller, which executes received bytecode program.
For details about animation language and examples of programs, please check my animation-lang repository.
- Clone project repository
git clone https://github.com/MabaKalox/esp-rust-lighting.git
- Navigate into it
cd esp-rust-lighting
For operation, Wi-Fi connection is required, and wifi-manager is not implemented yet. So you need to supply SSID and password of your Wi-Fi beforehand. Also you can specify number of leds on your led strip.
- create
cfg.toml
file in project directory with following content:
[esp-rust-lighting]
wifi_ssid = "your wifi SSID"
wifi_pass = "your wifi password"
led_quantity = 150
- Install dependencies listed in
Compiling Dependencies
- Add rust nightly toolchain
rustup install nightly
- Add rust-src for nightly toolchain
rustup component add rust-src --toolchain nightly
- Build, you should be in project directory
cargo build --release
- Install espflash
cargo install espflash
- Flash, replace
/dev/ttyACM0
by path totty
device of connected esp32-c3 over usb.espflash --speed 921600 --partition-table partitions.csv /dev/ttyACM0 /target/riscv32imc-esp-espidf/release/esp-rust-lighting
- Attach data pin of sk6812 led strip to GPIO6 of esp32-c3
- Power up esp32-c3
- Wait till both leds on microcontroller turn off
Navigate to http://rust_led_strip.local, be sure that your device support mdns
.
Alternatively you can find ip of microcontroller in your router settings and use ip instead: http://[IP]
-
Try to send some program:
- Open
Programming
tab (top left corner). - Try to write some program in left textarea, e.g:
// Blank everything for(n=get_length) { set_pixel(n-1, 0, 0, 0); }; loop { // set random pixel to random color lucky = random(get_length); for(n=get_length) { if(n == lucky) { r = random(255); g = random(255); b = random(255); set_pixel(n-1, r, g, b); } }; // Display on led strip blit; // Black one random pixel luckyb = random(get_length); for(n=get_length) { if(n == luckyb) { set_pixel(n-1, 0, 0, 0); } }; blit; }
- Check frame color
- Green - compiled successfully, disassembly can be found in right window
- Red - compiling error, detailes can be found in right window
- Press
Send
green button on web page in top right corner - You should see how random pixels turn on and off on led strip
- Open
-
Try presets (saved programs in your web browser)
- Write some program in
Programming
tab - Click
Save
button in middle part of screen - Input desired
name
for preset - Preset should appear under
Save
button:
- You can apply it, by clicking on
name
- You can delete it, by clicking
X
button nearname
- Write some program in
-
Try to change configuration:
- Open
Configuring tab
tab (top right corner) - Here you can change
FPS
- changes delay between presenting new framesLed Quantity
- self-explanatory, worth to note, it is not reboot persistentWhite brightness
- sk6812 has dedicated white led in pixels, and you control their brightness by this setting
- Apply by
Submit
button - Check applied config in window below
- Open
The REST API to the esp-rust-lightning
Request
POST /send_prog_base64
Body
base64 encoded string with compiled program
Example
curl -X POST -d "[base64 encoded compiled program]" http://rust_led_strip.local/send_prog_base64
Request
POST /set_conf
Query params
fps
- frames per second [0, 255]
white_brightness
- brightness of white subpixel in sk6812 [0, 255]
led_quantity
- how many leds in led strip to control [0, 2^32-1]
Example
curl -X POST -G -d 'white_brightness=20' -d 'led_quantity=150' -d 'fps=60' http://http://rust_led_strip.local/set_conf
This project is licensed under the MIT License - see the LICENSE.md file for details