TrickLED - NeoPixel WS2812B Animation Library

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.
User avatar
artacus
Posts: 1
Joined: Tue Jan 26, 2021 6:52 pm

TrickLED - NeoPixel WS2812B Animation Library

Post by artacus » Thu Jan 28, 2021 8:57 pm

Hey folks. I've been lurking here for a while and wanted to make my introduction with a small gift for you fine people.
I've been working on an animation library for MicroPython. There's no reason the Arduino folks should have all of the fun!

I wrote if for the ESP32 but it runs fine on an ESP8266 if you use the *.mpy files instead. I put a demo video up on Youtube here https://www.youtube.com/watch?v=vLvrJPNvkvU

But the colors didn't come across at all on the video, so load up a copy onto your board and see it live.
https://gitlab.com/scottrbailey/trickLED

Shout out to Peter Hinch. Even though you didn't know it, you were immensely helpful. Thanks for your contributions to the community.

Artacus

Primesty
Posts: 48
Joined: Sun Jun 28, 2020 11:06 pm

Re: TrickLED - NeoPixel WS2812B Animation Library

Post by Primesty » Sat May 01, 2021 3:19 pm

Hi Artacus!

This library is fantastic! Thanks a lot for this!

I have one question though. I'm trying to run your example on an ESP32 with MicroPython 1.15 and am getting import errors.

I have

Code: Select all

trickLED.py
, as well as

Code: Select all

animations.py
and

Code: Select all

generators.py
installed and this is your example code I'm trying to run to get started:

Code: Select all

from machine import Pin
import machine
import uasyncio as asyncio
import trickLED
from trickLED import animations
from trickLED import generators

# use TrickLED class instead of NeoPixel
tl = trickLED.TrickLED(machine.Pin(19), 4)
tl.fill((50, 50, 50), start_pos=0, end_pos=2) # fill first 25 pixels with white
tl.fill_gradient(0xDC143C, 0xF08080, 3) # fill remaining with red gradient
tl.write()
Two things are basically happening: 1) When I run the code without the animations/generators import, I get an error about function arguments:

Code: Select all

Traceback (most recent call last):
  File "main.py", line 11, in <module>
TypeError: unexpected keyword argument 'start_pos'
MicroPython v1.15 on 2021-04-18; ESP32 module with ESP32
Type "help()" for more information.
And 2) when I'm trying to import generators/animations, I get this error (for both and also individually):

Code: Select all

Traceback (most recent call last):
  File "main.py", line 5, in <module>
ImportError: can't import name animations
MicroPython v1.15 on 2021-04-18; ESP32 module with ESP32
Type "help()" for more information.
What am I doing wrong here? I assume there might be some circular dependency issue? Also, would you be willing to share the code for the animations/examples in your Youtube video?

SpotlightKid
Posts: 459
Joined: Wed Apr 08, 2015 5:19 am

Re: TrickLED - NeoPixel WS2812B Animation Library

Post by SpotlightKid » Thu May 06, 2021 2:55 pm

You probably need to copy the whole trickLED directory with its content to your ESP32 board's flash. Not just the *.py files in it.

sgar
Posts: 11
Joined: Sat May 01, 2021 1:14 pm

Re: TrickLED - NeoPixel WS2812B Animation Library

Post by sgar » Fri May 07, 2021 9:16 am

Awesome library! Congratulations!
I will try to use it in my project :D Thanks!!

Primesty
Posts: 48
Joined: Sun Jun 28, 2020 11:06 pm

Re: TrickLED - NeoPixel WS2812B Animation Library

Post by Primesty » Fri May 07, 2021 6:15 pm

@Spotlightkid, good thought! I tried that but it threw the same error.

Does anyone have any setup instructions and examples that run reliably on MicroPython 1.15 and an ESP32??

SpotlightKid
Posts: 459
Joined: Wed Apr 08, 2015 5:19 am

Re: TrickLED - NeoPixel WS2812B Animation Library

Post by SpotlightKid » Fri May 07, 2021 7:05 pm

Primesty wrote:
Fri May 07, 2021 6:15 pm
@Spotlightkid, good thought! I tried that but it threw the same error.

Does anyone have any setup instructions and examples that run reliably on MicroPython 1.15 and an ESP32??
I had a look at the trickLED code and I can't see how you would get the errors you get if you have the package installed correctly on your board.

I would take these steps to install the library:

Code: Select all

rshell rm -r /pyboard/trickLED
rshell mkdir /pyboard/trickLED
for py in trickLED/*.py; do
    mpy-cross "$py"
done
rshell cp trickLED/*.mpy /pyboard/trickLED
Add options for the serial device and baudrate to the rshell commands as necessary.

sgar
Posts: 11
Joined: Sat May 01, 2021 1:14 pm

Re: TrickLED - NeoPixel WS2812B Animation Library

Post by sgar » Tue May 11, 2021 10:06 am

@artacus any chance to configure brightness in Fire animation and/or flip the direction of the animations? (Fire start from last led)

Thanks!

Primesty
Posts: 48
Joined: Sun Jun 28, 2020 11:06 pm

Re: TrickLED - NeoPixel WS2812B Animation Library

Post by Primesty » Wed May 12, 2021 3:16 pm

@sgar

Do you mind posting your sample code or a link to a repo with the code you’re running? Are you using an ESP32? How did you install the trickLED lib?

I tried installing the entire folder, but am still getting an error.

sgar
Posts: 11
Joined: Sat May 01, 2021 1:14 pm

Re: TrickLED - NeoPixel WS2812B Animation Library

Post by sgar » Fri May 14, 2021 9:08 am

Primesty wrote:
Wed May 12, 2021 3:16 pm
@sgar

Do you mind posting your sample code or a link to a repo with the code you’re running? Are you using an ESP32? How did you install the trickLED lib?

I tried installing the entire folder, but am still getting an error.
No worries :) :
I'm running the main.py demo from the library with the folow lines modified:

Line 170: Changed the pin where I have connected the leds.
Line 176: Commented, to avoid any wifi connection

Running with Thonny, ESP32, only copied the .py files and it works well, here you can see the setup.
Image
https://i.ibb.co/yNvZGzS/14-05-2021-10-54-53-REC.png

Primesty
Posts: 48
Joined: Sun Jun 28, 2020 11:06 pm

Re: TrickLED - NeoPixel WS2812B Animation Library

Post by Primesty » Sun May 16, 2021 9:40 pm

Hi Sgar,

Thanks, I’ll give that a shot.

Post Reply