Esp32 Firmware v1.12 Bug (Neopixel Glitches)

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
shubham
Posts: 5
Joined: Wed Jan 22, 2020 6:16 am

Esp32 Firmware v1.12 Bug (Neopixel Glitches)

Post by shubham » Wed Jan 22, 2020 7:05 am

I have been working on micropython for esp32, and found a very trade off situation w.r.t Neopixel and Multi-Threading.

Problem 1 - When I am using latest Esp32 Firmware v1.12 there is problem in Neopixel Led (Ws2812 Addressable Leds). It shows glitches randomly while working, It blinks randomly without any specific interval.
According to me it is mostly because there is some timing issue occurred in library while updating the Firmware from v1.11 to v1.12.

Problem 2 - When I am using the Firmware v1.11, the neopixel library is working fine without any glitches or any problem. But the problem is in this firmware Multi-threading is not handled properly. While running multiple threads in my project, they tend to slow down the process or it is very seemingly delay in each thread execution.

So, if anyone has any suggestion or Solution for this. I am all ears.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Esp32 Firmware v1.12 Bug (Neopixel Glitches)

Post by pythoncoder » Thu Jan 23, 2020 4:02 pm

You may get better results using uasyncio instead of threading.
Peter Hinch
Index to my micropython libraries.

carsten
Posts: 15
Joined: Wed Aug 16, 2017 3:08 pm

Re: Esp32 Firmware v1.12 Bug (Neopixel Glitches)

Post by carsten » Tue Jan 28, 2020 2:42 pm

See https://github.com/micropython/micropython/issues/5157.

TL;DR; Use the latest micropython version and use the RMT implementation by nevercast: https://gist.github.com/nevercast/9c485 ... 4a22062795

shubham
Posts: 5
Joined: Wed Jan 22, 2020 6:16 am

Re: Esp32 Firmware v1.12 Bug (Neopixel Glitches)

Post by shubham » Sat Feb 01, 2020 6:25 am

@carsten after your suggestion I have tried RMT implementation and used the nevercast code of pixels.py for ws2812 led implementation.

Individually the library is working fine as it supposed to be But that implementation allocates a large chunk of memory and produces the error Memory Allocation Failed when I try to run it in my project which already consumes memory.

I read the the library for it, It makes tuples of very large size, which makes hard to allocate memory at runtime.

shubham
Posts: 5
Joined: Wed Jan 22, 2020 6:16 am

Re: Esp32 Firmware v1.12 Bug (Neopixel Glitches)

Post by shubham » Sat Feb 01, 2020 7:02 am

@carsten I have used your approach but has memory allocation issue as it needs 15k memory in ram, quite not possible in my case.
Still thanks for reply.

OutoftheBOTS_
Posts: 847
Joined: Mon Nov 20, 2017 10:18 am

Re: Esp32 Firmware v1.12 Bug (Neopixel Glitches)

Post by OutoftheBOTS_ » Sat Feb 01, 2020 8:09 am

Is it possible to mod the RMT implementation to use byte array instead of python tuples

shubham
Posts: 5
Joined: Wed Jan 22, 2020 6:16 am

Re: Esp32 Firmware v1.12 Bug (Neopixel Glitches)

Post by shubham » Sat Feb 01, 2020 11:51 am

@pythoncoder Thanks for replying.

We can only import uasyncio lib in Firmware v1.12, where threading is working fine but neopixel having glitching problem.
Multi Threading issue is in Firmware v1.11 and we can not import uasyncio in that version of Firmware.

shubham
Posts: 5
Joined: Wed Jan 22, 2020 6:16 am

Re: Esp32 Firmware v1.12 Bug (Neopixel Glitches)

Post by shubham » Fri Feb 07, 2020 7:03 am

Anyone has anymore solutions or suggestions?

User avatar
mattyt
Posts: 410
Joined: Mon Jan 23, 2017 6:39 am

Re: Esp32 Firmware v1.12 Bug (Neopixel Glitches)

Post by mattyt » Fri Feb 07, 2020 7:31 am

Hi @shubham,
shubham wrote:
Fri Feb 07, 2020 7:03 am
Anyone has anymore solutions or suggestions?
I think you have learnt most of this but just to recap...

RMT is the right way to drive NeoPixels on the ESP32. Whether you use threads or asyncio the underlying OS (FreeRTOS) will periodically interrupt the system long enough to cause glitches in the datastream significant enough to upset NeoPixels.

RMT employs hardware specific to the ESP32 where a bitstream can be specified such that the hardware can send it out with highly accurate timing (down to 12.5ns).

I'm aware that currently RMT takes a large amount of RAM and have a plan to resolve this (effectively double-buffering the datastream, calling back into MicroPython when more data is required - as the alternate buffer is being sent) but I don't have time to work on this in the near future. If you'd like to take a go at implementing this yourself I'd be happy to help explain what I have in mind. Otherwise I'm afraid you'll have to wait a little while.

I wish I could give you a better solution right now! :(

carsten
Posts: 15
Joined: Wed Aug 16, 2017 3:08 pm

Re: Esp32 Firmware v1.12 Bug (Neopixel Glitches)

Post by carsten » Sun Feb 09, 2020 1:14 pm

The only way to get rid of the memory requirements would be to completely write the neopixel driver in C with a live-calculation of the pulses as has been done in FastLED: https://github.com/FastLED/FastLED/blob ... mt_esp32.h

The downside to that is that you can't use the current RMT implementation with that, because it requires you to use your own interrupt handlers. That would mean the driver would completely block the RMT and you couldn't use the other channels for anything else.

Implementing that shouldn't be that hard when you use FastLED for reference...

Post Reply