5 ms·
Rust, a Raspberry Pi and Addressable LEDs
- slicedbrandy 7y agoSo I finally got around to writing about a project using the Raspberry Pi to power a panel of WS2812b LED's. Let me know what you guys think.
- timClicks 7y agoReally cool! Thanks also for taking the time to take photos and add figures.
- drtse4 7y agoJust FYI, since I've implemented something similar in Swift, using the PWM you would have had to implement more or less the same algorithm, i.e. changing the duty cycle of an high frequency signal to generate these "slot-based" patterns that identify the 0s and 1s of the WS281x (there are minimal timing differences between the variants) protocol. Note: God bless the Oscilloscope, essential for these projects.
- JoshMcguigan 7y agoThanks for sharing. One question about the code, why does the LedPanel struct use a String as a buffer rather than using a Vec<u8>? edit - I think I see the reason now. Using a string made it easy to print the u8 as a string of bits, which you could then iterate over using chars. This was used to help perform the conversion from bits directly representing colors to the on the wire representation.
- slicedbrandy 7y agoThat would certainly work as well, and ultimately it does get converted into a Vec<u8>. I did consider just having the buffer as it from the start, but by using a String it was just a little more intuitive when it came to pushing more bits onto the buffer, as well as doing the padding operation at the end. More just to reduce complexity during development than anything I guess.
- JoshMcguigan 7y agoI may have overlooked some things, but I made a quick PR[0] just to see what this would look like using a Vec<u8>. Feel free to close if you prefer the original. [0]: https://github.com/tomarrell/rasp-ws2812b/pull/2 https://github.com/tomarrell/rasp-ws2812b/pull/2
- xgbi 7y agoUnrelated, but how did you draw your curves/charts? They look fantastic.
- slicedbrandy 7y agoThanks! I drew them using Notability on an iPad, then exported the document as a jpeg and cropped them out.
- FraKtus 7y agoFor that to work correctly, the piece of code generating the signal should never be interrupted. To my knowledge, this is not possible with a Raspberry Pi. You should see glitches on the output when your loop generating the 1s and 0s is interrupted. That may be ok it if you just when to send one static light pattern but the glitches should be more evident if you want to create beautiful, flowing light patterns. That's why it's better to drive those WS2812b with an Arduino that you code bare metal.
- bitwize 7y agoOP should consider installing a Xenomai kernel on his Pi, to handle the signal output in hard real time while still providing a nice Linux-based interface to his program.
- Ao7bei3s 7y agoAPA102 is strictly better than WS2812B (standard SPI, much less sensitive to timing, way less PWM flicker, similar price/availability). When you still want bare metal, pick a modern uC like ESP8266 (cheap, 32 bit, integrated WiFi for trivial connectivity) instead of "classic" overpriced, outdated 8/16 bit AVR (Attiny/Atmega) based Arduino hardware. Arduino the software platform still works great of course, but so does NodeMCU which is the go to stack on ESP8266.
- zaarn 7y agoArduino's still have a use, Atmega/Attiny in general, the chips are much cheaper, especially if you don't need connectivity.
- simcop2387 7y agoI'd recommend looking at some of the ARM dev boards instead of the ESP8266 for general purpose stuff and if you need the wifi, the ESP32. This is mostly because the ESP8266 is missing a lot of hardware functionality that you'll find in the ESP32 or any arm boards. In particular UARTs (serial ports), I2C, and SPI periphrials that can make working with other things like the APA102 a lot nicer to code for. With the arm chips you usually even can setup the SPI transfers as DMA so that you don't have to actually do any work on the cpu itself to drive the lights. That said the ESP8266 still has a place because of how cheap you can usually find them. Lowest price arm board that i know of from a manufacturer is the Teensy LC at ~$12USD, but there are cheaper ones out there on ebay and aliexpress. I just can't say anything about how well they work or are supported by anyone.
- ircdrone 7y agoAnother day another rust post. Wondering how soon will it fade in obscurity as go did.
- joe_xyz 7y agoVery cool! We built a similar WS2812b array at university for an embedded systems design project: https://github.com/joe-wright/wiisel https://github.com/joe-wright/wiisel We looked at using a Raspberry Pi but instead settled on an mbed FRDM-KL25Z so we had more control over the signal timing. The trade-off was that the KL25Z only had 16KB memory instead of the Pi's 512MB, so getting everything to fit took a bit of creativity and a few late nights...
- teambob 7y agoYou need to use the timer to bit bang - which may require writing a device driver Source: wrote a software UART for an embedded project