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.

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.

Posts: 2
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.

Posts: 293
Joined: Sun Mar 19, 2017 9:36 pm

Please be positive and constructive with your questions and comments.