esp8266 neopixel_write glitches

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
norbo
Posts: 4
Joined: Mon May 04, 2015 7:12 am

esp8266 neopixel_write glitches

Post by norbo » Thu Aug 11, 2016 9:31 am

I use the following code in a timer callback to update/animate a large number (50+) of ws2812 neopixel leds in a timer callback every 10ms.
in the main loop i have the simple http server example running.

Code: Select all

fh=open("leddata.dat","rb")
buf=bytearray(80*3)
def timercallback(x):
    gloabal fh,buf
    nr=fh.readinto(buf)
    if nr==0:
        fh.seek(0)
        nr=fh.readinto(buf)
    neopixel_write(neopin,buf,True)
Bassically this works but sometimes the leds doent light up correctly. There are some glitches or they flicker or leds which should be off are on occassionally very randomly and short.
My first idea was that the neopixel_write function somehow gets interrupted and the pixeldata isn't written correctly. Could this be the case? is ther a workaround. Would it be possible to dissable intterrupts in the neopixel_write -> would this make wlan-networking non-functioning?

Another unrelated thing is when i send more than 1024 byte in the http response from the micropython esp8266 they are not displayed in the browser. Is this a known thing?

Best Regards.

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: esp8266 neopixel_write glitches

Post by deshipu » Thu Aug 11, 2016 9:35 am

The problem is that the neopixel protocol is done in software, and the ESP8266 has sometimes other things to do, such as various interrupts, handling of the wifi communication, etc. -- so there will sometimes be small differences in timing that result in the effects you describe.

There has been some attempts to use ESP8266's I2S interface, with its DMA hardware, to generate the signals for neopixels -- and they look promising. You could try experimenting with that, and maybe even writing a MicroPython module that uses it. https://github.com/cnlohr/esp8266ws2812i2s

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: esp8266 neopixel_write glitches

Post by pfalcon » Thu Aug 11, 2016 11:16 am

There's an (apparently) related patch: https://github.com/micropython/micropython/pull/2211 . Feel free to test it and comment on that pull request with your experiences.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

norbo
Posts: 4
Joined: Mon May 04, 2015 7:12 am

Re: esp8266 neopixel_write glitches

Post by norbo » Mon Aug 15, 2016 8:47 am

Hi

To test i added a ets_intr_lock and ets_intr_unlock over the neopixelwrite loop in the source. The update of the neopixel works fine then, but it seems that the wlan connections then gets unrelaible. (connection breaks, connection establishment fails, etc.. ) For me it look that it was due to this change, but i am not a 100% about this.

To the other note: the approx. 1024 byte limit in the http response doesnt seem to exist when i use the client_sock.makefile("rwb") api instead of the normal socket send method.

Best Regards
Norb

torwag
Posts: 220
Joined: Fri Dec 13, 2013 9:25 am

Re: esp8266 neopixel_write glitches

Post by torwag » Thu Sep 08, 2016 12:06 pm

The esp needs to be able to set interrupts for a wide range of functions, most notable wifi.
If you disable the interrupt routine, all those functions might or might not brake depending on pure luck of timing.
Thus, one should try to keep the interval without interrupt routine as short as possible.
Recently the patch mentioned by deshipu was merged into micropython. It tries to be as fast as possible to avoid timing problems with other functions and I could not observe any glitches anymore.

Hope thats helps.

Post Reply