0

Limitations of ESP32 Neopixel support
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Limitations of ESP32 Neopixel support

by kb5mu on Tue May 16, 2017 1:08 am

I'm seeing a pretty fundamental problem with the ESP32 support in the Adafruit_NeoPixel support. In short, it appears that an interrupt that occurs every millisecond (presumably the millisecond timekeeping) corrupts the very finicky timing being generated for the NeoPixels by inserting about 5 microseconds of extra delay. That's way out of spec for the NeoPixels, so the result is flaky pixels that may flicker or display the wrong color.

This doesn't show up as a problem if the NeoPixel strand is shorter than 34 RGB pixels, IF the strand method call show() is called right after a call to delay(), which it always is in the simple demo programs provided as examples with the library. That's because the delay() function synchronizes to the millisecond interrupt, and it takes just under a millisecond to update 33 RGB pixels (or 24 RGBW pixels).

The simple demo programs use delay() liberally to create animations, but in a real application you probably have other work to do in between pixel updates. In that case, you will probably keep time some other way, such as by calling millis() repeatedly and keeping track of when the next pixel update is scheduled. If you do that, you won't necessarily stay synchronized with the millisecond interrupt, so the extra 5 microseconds can slip into even the shortest pixel strand. You can choose to resynchronize by calling delay(1) before mystrip.show(). That will work around the problem, as long as your strand is short enough to be updated in less than a millisecond.

The other workaround is to disable interrupts during the call to mystrip.show(). On the ESP32, noInterrupts() doesn't do anything, but you can still disable interrupts by calling portDISABLE_INTERRUPTS(). This uses the mechanisms provided by FreeRTOS, which is managing the ESP32 under the covers in the ESP32 Arduino environment. Use portENABLE_INTERRUPTS() after the call to mystrip.show(). Of course, now you're disabling interrupts for more than a millisecond, maybe much more than a millisecond if you have a long strand of NeoPixels. That's bound to cause problems for other time-critical operations, such as loss of millisecond ticks (though I have not confirmed that experimentally).

I filed an issue on the Github project for Adafruit_NeoPixel, here: https://github.com/adafruit/Adafruit_Ne ... issues/139

I believe that this problem is fundamental in that trying to bit-bang NeoPixel timing on a multitasking system (which the ESP32 is under the covers) is never going to be reliable without putting unacceptable constraints on other realtime tasks. The best way to solve this is to use a dedicated processor to create the NeoPixel timing. Chris Osborn has an ESP32 NeoPixel driver that uses the infrared remote peripheral hardware on the ESP32 chip to generate timing. His version is not currently targeted to the Arduino environment AFAIK, but the method seems very promising. http://www.insentricity.com/a.cl/268/co ... -the-esp32

Thanks to Abraxas3d for tracking this down with me.

kb5mu
 
Posts: 1
Joined: Tue Aug 10, 2010 11:46 am

Re: Limitations of ESP32 Neopixel support

by vseven on Sun Jan 07, 2018 5:06 pm

I would love to see a updated NeoPixel library because of these issues. There is FastLED but which is 100% stable when WiFi on my ESP32 is disabled but as soon as I enable WiFi I get constant crashing. About to give up on NeoPixels and just buy more "analog" strips which work great on the ESP at the cost of using more outputs and some MOSFETs.

vseven
 
Posts: 3
Joined: Wed Oct 04, 2017 10:59 pm

Re: Limitations of ESP32 Neopixel support

by Arudinne on Mon Jan 08, 2018 7:15 pm

An alternative is DotStar LEDs at the expense of needing both a data and clock line. They don't have many of the issues with timing that the NeoPixels have.

Arudinne
 
Posts: 296
Joined: Sun Mar 19, 2017 9:36 pm

Re: Limitations of ESP32 Neopixel support

by clarkj on Thu Apr 12, 2018 4:15 pm

I happened to find this thread, as I'm thinking about basing a project on the Feather HUZZAH ESP32. Using DotStars is NOT a viable option for my project because of the lack of "formats" - although I could probably use something like the "jewel", or a small ring, my preference is for an 8mm LED like PID 1734.

Fortunately, it looks like it will work since my need is for fewer than 32 NeoPixels, and it can easily tollerate waiting until the next millisecond tick.

clarkj
 
Posts: 88
Joined: Thu Aug 08, 2013 12:34 pm

Re: Limitations of ESP32 Neopixel support

by vseven on Thu Apr 12, 2018 4:29 pm

Be warned that I've had my ESP32 crash with as little as 15 pixels and I've gotten it to work as high as 50 pixels. It seems random based on what the WifI happens to be doing. No wifi = 100% stable. Wifi on = completely random.

vseven
 
Posts: 3
Joined: Wed Oct 04, 2017 10:59 pm

Re: Limitations of ESP32 Neopixel support

by Clouseau on Sat Jul 14, 2018 3:49 pm

We tried to setup a clock with this Neopixels and encountered randomly flashing pixels showing up. To such a degree it was not usable. Our strip had only 30 pixels in row.

After we changed our code to:
Code: Select all | TOGGLE FULL SIZE
delay(1);
strip.show();

it was mostly ok. We now still have some of the pixels showing false colors now and then. And once in a minute a wrong pixel is showing up. But it is way less then before.

Is there any better library than this <Adafruit_NeoPixel.h>?

Clouseau
 
Posts: 3
Joined: Sat Jul 14, 2018 3:32 pm

Re: Limitations of ESP32 Neopixel support

by Clouseau on Sat Jul 14, 2018 6:11 pm

I hooked up a logic analyzer to see what's going on.


It is very easy to see that at random times there are gaps (>5µs) in the stream of data which shouldn't bee there. As soon as there is a pause, the data get 'latched' in the current Pixel instead of being pushed futher. This is what causes the random errors on the display.


So, how can i avoid this problems?

Clouseau
 
Posts: 3
Joined: Sat Jul 14, 2018 3:32 pm

Re: Limitations of ESP32 Neopixel support

by Clouseau on Sat Jul 14, 2018 8:48 pm

I switched to this library:

https://github.com/Makuna/NeoPixelBus

Since then i do not have any problems with uncontrolled blinking of NeoPixels. Seems i have found my solution.

Clouseau
 
Posts: 3
Joined: Sat Jul 14, 2018 3:32 pm

Please be positive and constructive with your questions and comments.