Hacker News new | past | comments | ask | show | jobs | submit login
Over-engineering an RGB LED strip: let’s make a custom programming language (pixelspark.nl)
105 points by misterdata on July 17, 2022 | hide | past | favorite | 21 comments



There already is a custom programming language for LED lights. It's called E1.31, and there are open source programs that exist to program in it (one of the most popular is called Xlights). It's what most people use to make their programable Christmas lights shows, and it also is the same protocol used in stage lighting.


If I understand correctly that’s 'Streaming ACN' e.g. more or less DMX512 over IP. In that case the image is generated on a beefy lighting desk/computer, not on the microcontroller inside the fixture (which is what this and e.g. the Lua project linked in another comment does)

WLED (firmware for ESP8266) appears to support E1.31 [1] as well as Art-Net and the WLED custom protocol referenced in the article.

[1] https://github.com/Aircoookie/WLED/wiki/E1.31-DMX


This is nice. I once tried to get programmatic animations running on MicroPython, but it seemed to fail to load even the simplest color conversion class (I didn't have an ESP32 back then).

I also tried streaming patterns (could've been really cool to hook it up to something like ColorCord), but my Wifi connection was definitely also too unreliable for that (hmmm, what about PoE LED strips?).

There's some project based on Javascript (I think) with in-browser previews for the patterns, but it's proprietary and only sold as pre-flashed modules. I forgot the name, but I think it has been posted here.

This bytecode-custom-language solution definitely looks over-engineered (wish I could use a language I already know to make an animation), but damn, it should be efficient. I think I'll play around with it bit.


> There's some project based on Javascript (I think) with in-browser previews for the patterns, but it's proprietary and only sold as pre-flashed modules. I forgot the name, but I think it has been posted here.

That would be the PixelBlaze from https://electromage.com/

... and it's super-duper-amazing for actually finishing LED projects. While the code on the ESP32 is proprietary, everything else is very open and the community is awesome.

If your name is Sisyphus or you just want to hack on LED electronics and maybe make some lights blink, anything else is fine.


That’s pretty cool.

I did something similar once, where I wrote a Qt application that let you add effects to a timeline, which would get saved as json and could then be run on a Raspberry Pi to control a grid of NeoPixel LEDs. Each effect on the timeline has a start and length, which pixels it affected, RGBW colors, easing function in and out and effect type (fade, blink etc — there were a few basic effect types that could be combined to create more elaborate effects). The Qt application was able to simulate the LEDs in a GUI using the same code that ran on the RPi (just the GUI was replaced with LED driver code there). It was used to play animations on a t-shirt that was covered in a grid of LEDs made for a local musician. It was a fun project. The code is on GitHub but it’s terrible quality due to having been written over the space of 3 days and then never touched again: https://github.com/danielytics/ledstudio


On a sidenote: Can anyone recommend decent quality LED strips on Aliexpress or Ebay (I'm not in the US)? Points of interest would be:

* reproducable (when buyin two 10m strips of the same product, LED colors should match)

* lean (I read some reviews (Amazon), where the buyer experienced one or two LEDs in the strip having a different color temperature)

* etc.

I mainly want to equip the bottom edge of the kitchen cupboards with these, so I have better lighting, when cooking on the cutting board below them. I don't need animation, just good light, ideally in different color temperatures and hues (dimmable). Thanks.


I have the Govee ones and they work fairly well. Can work with Alexa and Google Home and they have their own app too (in addition to a built in physical control).


Thanks, I'll check!


Related: a multi-program programmable LED strip (in Lua, allows the led strip to be split up into multiple segments) https://zeus.gent/blog/21-22/ledstrip_sandbox/ with the code on https://github.com/ZeusWPI/ledstrip_sandbox


This looks cool! Lua obviously is a much more mature language. I'd expect it to use a fairly complex interpreter (LuaJIT is not available for esp8266 I assume..) so this is likely a bit less efficient (even though the Lua interpreter is probably well-optimized, it is simply more complex) but obviously much more functional than my toy language.


I'm surprised you didn't use floating point math, it seems cumbersome to make animations that way. My attempt at programmable LED strips used Lua (like that: https://gist.githubusercontent.com/Milek7/760a683f3480a4ff95...), though they were driven directly from Linux SBC. https://milek7.pl/.stuff/26gru.webm


Floating point is just not very fast on ESP8266 (I believe it could even be softfloat, so emulated in software?).

Nevertheless it shouldn't be that difficult to change the interpreter to use floats instead of ints as base type (mixing the two would be more involved I think).


How did you implement "sleep"? For timing the effects?

I see a 'get_precise_time' command. I guess you could poll that, if you aren't worried about power use. (LEDs using far more power than your CPU.)


The interpreter will throttle the program to a certain frame rate - it will suspend the program on each ‘yield’ instruction and resume the program when a new frame is needed. It can also ignore the yields to get as high a frame rate as possible. Programs should not poll but use get_precise_time to draw what is necessary for that time stamp.

(And yes, the LEDs use way more power than the CPU here)


Ah, much cleaner, cool.


This is very cool. And very generalizable, there are many situations where you want something like a scripting language for a MCU, and the VM implementation here is very straightforward.


I'm surprised this one[0] hasn't been mentioned, it is my favorite so far.

[0] https://kno.wled.ge/

A fast and feature-rich implementation of an ESP8266/ESP32 webserver to control NeoPixel (WS2812B, WS2811, SK6812) LEDs or also SPI based chipsets like the WS2801 and APA102!


I've got WLED running on 10+ projects around the house, and have been using it for years. It's great. Super easy to install, lots of features, controllable via web app or API (and compatible with dozens of related services), and there's native phone apps available if you're into that.


This might interest you as well:

https://www.bhencke.com/pixelblaze


Kudos to the author.

The readme links to a protocol.md that lives in a private repository, any posibility it gets copied to the github repo?


You had me at Lua. It's cool to think that runs on an RGB strip. I'd do it there but kudos on going all the way down!




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: