FastLED for MicroPython

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
ayke
Posts: 3
Joined: Mon Sep 04, 2017 2:46 pm

FastLED for MicroPython

Post by ayke » Mon Sep 04, 2017 9:12 pm

I've ported over some animations from FastLED to MicroPython, to make animations actually *fast*. The default LED implementation was way too slow for me. I took inspiration from how NumPy accelerates calculations by doing them on a whole array at once.

Example (BBCode doesn't seem to work, sorry about that):

import pixels
import machine
import time
l = pixels.Pixels(machine.Pin(15), 150, pixels.GRB)
hue = 0
while True:
. . hue = (hue + 0.005) % 1
. . l.fill_rainbow(hue, -0.02)
. . l.write()
. . time.sleep(0.01)

More complicated animations are also possible. I ported both Fire2012WithPalette[1] and pride2015[2] over to this library, with decent speed (about 80fps and 115fps respectively for 150 LEDs). It's about 2-10 times slower than native FastLED on the ESP8266 and sometimes slower than FastLED on the Arduino Uno. On the other hand, we have to consider it's written in Python and lacking all template-based optimization that FastLED normally uses so it's actually quite fast. Writing out the LEDs (WS2812) is slower than generating the next frame, unless you have very complicated animations or are doing them pixel-by-pixel in Python.

The code is over here in the modpixel branch: https://github.com/aykevl/micropython/tree/modpixel. Some documentation can be found over here: https://github.com/aykevl/micropython/b ... /pixels.py

I would love to see something like this in the MicroPython core, but I doubt that's going to happen. If there was a way to include true native code in a Python library I'd try that.

[1]: https://github.com/FastLED/FastLED/blob ... alette.ino
[2]: https://gist.github.com/kriegsman/964de772d64c502760e5

gomibako
Posts: 1
Joined: Fri Sep 29, 2017 5:31 am

Re: FastLED for MicroPython

Post by gomibako » Fri Sep 29, 2017 5:34 am

Great Job! This is what i am looking for. Thanks a lot.

sunrise17
Posts: 2
Joined: Sat Jan 27, 2018 10:18 pm

Re: FastLED for MicroPython

Post by sunrise17 » Tue Feb 27, 2018 9:18 pm

I am getting following error in ESP32 board. Is it possible to adjust it?
File "pixels.py", line 4, in <module>
ImportError: no module named '_pixels'

dn8beats
Posts: 1
Joined: Sat Jun 09, 2018 7:29 am

Re: FastLED for MicroPython

Post by dn8beats » Sat Jun 09, 2018 7:32 am

Are your ports of Fire2012WithPalette and pride2015 available online?

ayke
Posts: 3
Joined: Mon Sep 04, 2017 2:46 pm

Re: FastLED for MicroPython

Post by ayke » Tue Jun 12, 2018 8:13 pm

I haven't originally written them myself (only converted them), but I've put them online here:
https://gist.github.com/aykevl/0b4031c9 ... 6e4b0f3b64

Post Reply