Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lots of Jitter when using over 64 WS2812B LEDs with ESP8266 #85

Open
dudesky71 opened this issue Aug 9, 2018 · 37 comments

Comments

Projects
None yet
7 participants
@dudesky71
Copy link

commented Aug 9, 2018

Jason, I have a 128 WS2812B 16x8 matrix connected in a non-serpentine format. When I run your webserver code I get jitter. Im using a level shifter. I noticed that when I set "NUM_LEDS" to anything over 69 when the ESP starts up, it fills everything with a solid color and i get jitter when the twinkle animations run. If i set "NUM_LEDS" to 64 for example, only 64 initialize at startup as it should and its perfectly smooth on twinkle animations. I've played with frame rate and everything I can think of including shutting off wifi and disabling interupts but nothing fixes this. Its running on a battery. There is no DC noise or current issues. If I run "NoisePalette" sketch from the fastled.io website, I can run all 128 LEDs super fast with no jitter on any animation. This proves the hardware works fine. Can you take a look and see if this is a memory allocation bug or something? I really love your implementation but I'm not sure how to fix it myself :)

Thanks!
-K

@dudesky71 dudesky71 changed the title Lots of Jitter over 64 WS2812B LEDs using ESP8266 Lots of Jitter using over 64 WS2812B LEDs with ESP8266 Aug 9, 2018

@dudesky71 dudesky71 changed the title Lots of Jitter using over 64 WS2812B LEDs with ESP8266 Lots of Jitter when using over 64 WS2812B LEDs with ESP8266 Aug 9, 2018

@jasoncoon

This comment has been minimized.

Copy link
Owner

commented Aug 9, 2018

Tried different values for these, before the FastLED include?

#define FASTLED_INTERRUPT_RETRY_COUNT 0
#define FASTLED_ALLOW_INTERRUPTS 0

FastLED/FastLED#367 (comment)

@dudesky71

This comment has been minimized.

Copy link
Author

commented Aug 9, 2018

Jason,
Thank you for the fast reply. I've tried the above definitions with different values. In fact, without them I get jitter no matter how many LEDs are defined (even with 64). I have the latest source and libraries. I've also tried compiling on two seperate machines running Arduino 1.6.10 and 1.8.5. Windows and MAC versions as well. There is something else going on.
-K

@tobi01001

This comment has been minimized.

Copy link

commented Aug 9, 2018

@dudesky71

This comment has been minimized.

Copy link
Author

commented Aug 9, 2018

Hey thanks tobi! If i use this will the frame rate be limited at all? unfortunately my hardware doesn't use this pin for the LED data. It will require a board spin :( I don't think this fork is actually required because my hardware works fine with the examples from the fastled.io website with no changes running a full 16x8 matrix on GPIO 12.

@dudesky71

This comment has been minimized.

Copy link
Author

commented Aug 9, 2018

Hey Jason, take a look at this thread. Do you know if your code and or FastLED supports the new LED timing spec?

FastLED/FastLED#465

-K

@tobi01001

This comment has been minimized.

Copy link

commented Aug 9, 2018

@dudesky71

This comment has been minimized.

Copy link
Author

commented Aug 9, 2018

Tobi, I totally agree with you but that doesn't explain why the unmodified examples from the fastled.io website just work on my same hardware out of the gate on the same GPIO that has no DMA.

@tobi01001

This comment has been minimized.

Copy link

commented Aug 9, 2018

@dudesky71

This comment has been minimized.

Copy link
Author

commented Aug 10, 2018

By chance is there a branch of this code that doesn't use wifi at all and just cycles through the animations manually? That would be a good test as well since the other FastLED animations work fine.

@jasoncoon

This comment has been minimized.

Copy link
Owner

commented Aug 10, 2018

That's pretty much DemoReel100: https://github.com/FastLED/FastLED/blob/master/examples/DemoReel100/DemoReel100.ino

If that doesn't exhibit the same issue, you could copy over and add any patterns to it.

I'll try to perform some tests today. It's been a while since I went through setting up a new esp8266-fastled-webserver project from scratch.

@jasoncoon

This comment has been minimized.

Copy link
Owner

commented Aug 11, 2018

Sorry, just to confirm, have you tried:

#define FASTLED_INTERRUPT_RETRY_COUNT 1
#define FASTLED_ALLOW_INTERRUPTS 1

#include <FastLED.h>

at the very top of your sketch?

@dudesky71

This comment has been minimized.

Copy link
Author

commented Aug 11, 2018

Jason,

Yes. Without the above code, I get lots of jitter no matter how many LEDs are initialized. Only values of 64 or less are smooth. After further testing this morning, anything above 64 LEDs I get jitter regardless of interupt disabling.

Thanks!
-K

@jasoncoon

This comment has been minimized.

Copy link
Owner

commented Aug 11, 2018

@dudesky71

This comment has been minimized.

Copy link
Author

commented Aug 11, 2018

Jason,

I tried this branch. Overall the animation speed is slower. As-is, I have jitter on every animation. I changed the led type to WS2812B, set it for pin 6 and from 400 LEDs down to 128 and 64. It does it constantly no matter what.

When i set the retry count from 1 to 0 it runs fine (but slow) at 128 leds and 64 leds.

Thank you for looking at this on a Saturday by the way! :)

Also, quick question... Is this meant for TV scan line (L to R, L to R, L to R) or serpentine data wiring (L to R, R to L, L to R)?
-K

@dudesky71

This comment has been minimized.

Copy link
Author

commented Aug 11, 2018

Jason,

Also, it seems to do it only on the twinkle animations and this branch doesn't really have any. However, It does have alot of jitter on the confetti animation.

-K

@dudesky71

This comment has been minimized.

Copy link
Author

commented Aug 19, 2018

Jason, any news on this? Thanks

@jasoncoon

This comment has been minimized.

Copy link
Owner

commented Oct 6, 2018

Try again with the latest from master?

I just ran through a test setup and was seeing jitter on anything over 50 LEDs. I nearly eliminated it by doing the following:

  • adjusted the FastLED interrupt options to what's currently in master
  • switched from powering over USB
  • updated to the latest:
    • arduino
    • fastled library
    • esp8266 board and libraries
@jasoncoon

This comment has been minimized.

Copy link
Owner

commented Oct 7, 2018

Also, in loop(), try replacing

FastLED.delay(1000 / FRAMES_PER_SECOND)

with

delay(1000 / FRAMES_PER_SECOND)

If that doesn't work, also try reducing FRAMES_PER_SECOND from 120 to 60.

@tstill88

This comment has been minimized.

Copy link

commented Nov 8, 2018

https://youtu.be/AxHRdYMEOiQ

I'm getting this issue with 2812B. I've tried all of the above but regardless on LED length I'm getting that flashing/ jitter

Just updated to latest IDE and now using 5v USB plug rather than from laptop.

@jasoncoon

This comment has been minimized.

Copy link
Owner

commented Nov 8, 2018

@tstill88 are you using a level shifter? Have GND connected to the power supply and ESP8266?

@tstill88

This comment has been minimized.

Copy link

commented Nov 8, 2018

No not using a low level shifter and power is just via the USB port on the NodeMCU. Im still "testing" with this at the moment, my final project i was going to add an external 5v power supply but even if i set the LED number to 10-20 im getting this issue so assumed it wasnt due to that.

@tstill88

This comment has been minimized.

Copy link

commented Nov 8, 2018

I ordered a new strip that arrived today which was just 1m 60 LEDS and im getting no jitter on that, so maybe its the strip length thats the issue. I thought defining the amount of LED's in the sketch would limit the amount of power required when i had my 3m strip of 200+ LEDs connected. Should i maybe connected another USB power at the other end of my long strip?

@dudesky71

This comment has been minimized.

Copy link
Author

commented Nov 8, 2018

tstill88... It's been my experience that you just can't run more than 64 LEDs with this sketch. Jason has been very helpful and has released some forks for me to try but none of them work. My diligent research has uncovered the issue. The WiFi stack uses significant resources and needs some interrupt time on the MCU. When the LEDs exceed 64, the MCU has too much to process along with WiFi. Yield statements do not help this situation. If you look around on GitHub you will find some code that utilizes the DMA memory that is used for the UART pin. This is the ONLY pin that can output "SMOOTH" data to the LEDs. It acts like a "Cache Buffer" if you will that allows the WiFi to "Hog" the resources when needed but not enough to empty the buffer which outputs a constant stream to the LEDs regardless of what background processes are running :)

@jasoncoon

This comment has been minimized.

Copy link
Owner

commented Nov 8, 2018

@tstill88 a level shifter may help. ESP8266 output 3.3v logic levels, but the LEDs require 5v logic. You might also try measuring the voltage (between 5V and GND) at the far end of your strip. If it's below 5v, it'd help to connect 5V and GND at that end as well.

@dudesky71 sorry you're still having issues. I have built a lot of pieces using much more than 64 LEDs, all with ESP8266 and variants of this sketch. I've built 2D and 3D fibonacci pieces with 100 and 200 LEDs. I've tested parallel output with 1,200 LEDs split between 4 and 6 outputs, for a total of 300 and 200 LEDs per pin. I've always been able to eliminate the flicker.

I wonder if something in the ESP8266 libraries has changed lately? Have you reduced the framerate, tried using delay instead of FastLED.delay, etc, to try to reduce the amount of time spent in interrupt? Are you using long data wires to cover long distances between the ESP8266 and LEDs? Have you tried using CAT5 or CAT6 cable to reduce noise and ringing?

@dudesky71

This comment has been minimized.

Copy link
Author

commented Nov 8, 2018

@jasoncoon I have also successfully ran more than 64 LEDs on ESP8266. On the particular project I keep having issues is a custom PCB with 128 LEDs on it. Other sketches run completely fine with no jitter. I'm using a level shifter from TI that works great. The connection from the ESP to the first LED is only 3 inches using a 10 mil trace. Each LED has a .1uF decoupling capacitor right at the LED. It also runs on a battery power source so there is absolutely no power supply noise. There is no wiring involved. This is all on a PCB. I have not tried using delay instead of FastLED.delay. Expressif recommends to not use ANY "Blocking" delays at all as this will crash the WiFi stack. Non-Blocking delays are the only way to go... I haven't fully looked at your code. Does it include "Blocking" delays?

@jasoncoon

This comment has been minimized.

Copy link
Owner

commented Nov 8, 2018

@dudesky71 delay on ESP8266 internally calls esp_yield: esp8266/Arduino#1410 (comment)

So on ESP8266, in long running functions, loops, etc, it's actually better to use short calls to delay than to use FastLED.delay which will use up the time to refresh the LEDs.

@tstill88

This comment has been minimized.

Copy link

commented Nov 8, 2018

Thanks Jason. Is there any guide I could check for using the level shifter with the nodemcu? Quite new to this!

@jasoncoon

This comment has been minimized.

Copy link
Owner

commented Nov 9, 2018

No problem, hope you get it working! Here's how you wire up a level shifter:

https://community.openhab.org/t/nodemcu-mqtt-led-strip-controller-build-config-how-to-videos/39902/23

I wouldn't bother trying to use anything except 74HCT125 or 74HCT245. Most level shifters are not fast enough to handle WS2812 or APA102 data rates.

I don't have anything for NodeMCU ESP8266, but I do have a variety of level shifter shields for other ESP8266 and ESP32 boards: https://www.tindie.com/stores/jasoncoon/

@tstill88

This comment has been minimized.

Copy link

commented Nov 9, 2018

Ahh thanks a lot mate! Got all of the above on order in multiple quantities in case of screw up :)

A few quick questions though!

  1. On my NodeMCU i have 3.3v and VIN which is a 5v out, with the level shifter should i then use the 3.3v out and have the level shifter provide the 5v. Is the 5v coming the level shifter "smoother" than the 5v from VIN?
  2. Power supply - Any recommendations for a PSU on these projects? Ive got a few old PC PSU kicking around that i could butcher but something smaller would be ideal as my final project will be something like 5m 300LED or more.
@jasoncoon

This comment has been minimized.

Copy link
Owner

commented Nov 9, 2018

  1. Level shifter should be connected to 5v, ideally with a 0.1uF decoupling capacitor connected directly to the 5V and GND on the level shifter. The level shifter is going to convert the 3.3v logic on the data pins to 5v.
  2. Each LED can theoretically draw a max of 60mA each, at full brightness, solid white. So 300 LEDs could draw 18A. Of course, you likely won't be driving them at max, and you can always limit the max power with FastLED. These 5V 10A power supplies are known good: https://www.adafruit.com/product/658 . I've also used these before: https://amzn.to/2RO0713
@tstill88

This comment has been minimized.

Copy link

commented Nov 9, 2018

Thanks again mate, i got it now :)

That second link is ideal actually as it comes with the female connector, just what I was looking for :) Once I have those bits hooked up I will let you know if the issue is sorted, sure it will be!

@maik-dmxc

This comment has been minimized.

Copy link

commented Feb 2, 2019

Jitter doesn't go away on some patterns.
hook't up my oszi.
frame rate is 60
CPU freq is set to 160

#define FASTLED_ALLOW_INTERRUPTS 0
(tested all variations)

this is "pride"
ds1z_quickprint18
here is no jitter

this is "rainbow"
ds1z_quickprint17
a lot of jitter

regards maik

@maik-dmxc

This comment has been minimized.

Copy link

commented Feb 2, 2019

Workaround

switching from
FastLED.delay(1000 / FRAMES_PER_SECOND);
to
delay(1000 / FRAMES_PER_SECOND);

stop the jitter on all patterns, but reduce the framerate as seen in the picture

ds1z_quickprint19

regards maik

@maik-dmxc

This comment has been minimized.

Copy link

commented Feb 2, 2019

could this be the problem? found that -> FastLed.delay

FastLED.delay() basically always does { delay(1); FastLED.show() }.  There are two cases where it doesn't:
(1) if the delay value == 0, then FastLED.show() is NOT called by FastLED.delay()
(2) if the delay value == 1 AND the millis() timer ticks between the first read and the second read inside delay(), then show() will NOT be called.

But if the delay value is 2 or more, FastLED.delay() calls FastLED.show().

regards

@dudesky71

This comment has been minimized.

Copy link
Author

commented Feb 2, 2019

@AlirezaAbdiyan

This comment has been minimized.

Copy link

commented Apr 11, 2019

I add #define FASTLED_INTERRUPT_RETRY_COUNT 0 before #include<FastLED.h> and change line 19
https://github.com/FastLED/FastLED/blob/master/platforms/esp/8266/clockless_esp8266.h
from:
template <int DATA_PIN, int T1, int T2, int T3, EOrder RGB_ORDER = RGB, int XTRA0 = 0, bool FLIP = false, int WAIT_TIME = 50>
to:
template <int DATA_PIN, int T1, int T2, int T3, EOrder RGB_ORDER = RGB, int XTRA0 = 0, bool FLIP = false, int WAIT_TIME = 5>
Then the problem solved...

@tripdragon

This comment has been minimized.

Copy link

commented Apr 17, 2019

Can attest for AlirezaAbdiyan. This Seems to have worked for our setup.
Specs 720 lights (3 per one ws2811b chip)
esp8266 controller
custom sin maths and cylon code demos
LOTS of power in links, NO ethernet < that one seems to cause issues with and SUPEr without a 100 ohm thingy
Still digging for performance tweaks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.