I’m having trouble just getting FastLED to work properly with a Wemos D1 mini. I’m just trying to run the example cylon code, and the only modifications made were to set the LED pin to D6 on the D1, and to include the esp8266 library. It is running but I’m getting some strange random flashing, as seen in this video. Any ideas?
Hardware-wise I’m using the evil genious board with level shifter for the wemos D1 mini. I have two D1s so i replicated the hardware on a breadboard and had the same issue. I must be missing something simple here?
It’s likely problems with interrupts - there’s a couple things to try listed here - namely, setting the retry count and/or disabling interrupts while writing out led data.
Sorry for the trouble, and the delayed response. In addition to the great advice you’ve gotten already, there are more recommendations in this thread: https://github.com/FastLED/FastLED/issues/367
When I’ve encountered this issue, I made sure I’m using the latest versions of FastLED and ESP8266 Arduino libraries, and then tried different combinations of values for FASTLED_ALLOW_INTERRUPTS and FASTLED_INTERRUPT_RETRY_COUNT. You can also try setting the CPU Frequency to 160 MHz.
And if you’re still running out of luck, or time, I recommend you switch to the DMA I2S driver instead:
ESP8266 has an I2S DMA driver that can be abused to also put out a perfect wave, without tying up the CPU and worrying about interrupts.
There is a DMA driver for both, but sadly not in FastLED, so you lose the fancy functions.
However, if you’re just trying to light up LEDs and do simple things, you can do it without the fancy fastLED API.
Look at my code to see what I mean about the different drivers: https://github.com/marcmerlin/Neopixel-IR
Do have a look at https://github.com/JoDaNl/esp8266_ws2812_i2s/ as well as how I made a basic common API in my code so that you can use that and it’ll convert to the underlying driver.
If you use that basic API, you can switch back and forth between FastLED and esp8266_ws2812_i2s , and stick with the one that works best for you
@Jason_Coon , I’ve always been a bit confused about those defines like FASTLED_ALLOW_INTERRUPTS and FASTLED_INTERRUPT_RETRY_COUNT
Are they supposed to be set correctly for that platform out of the box or are they exactly there for the user to enable/disable for each platform as required?
Since the ESP8266/ESP32 chips are a bit complicated given that it’s hard to really disable interrupts on them (especially ESP32 that is dual core and has its own OS running underneath), it’s be great to have precise settings for those 2 platforms, that are known to work.
But even more great would indeed to absorb a hardware specific driver for them (I2S and RMT).
@Marc_MERLIN ‘FASTLED_ALLOW_INTERRUPTS 0’ just causes FastLED to prevent interrupts while writing out LED data. It totally depends on what your code (or a library) are doing during those interrupts, and how long it takes. More info: https://github.com/FastLED/FastLED/wiki/Interrupt-problems
@Jason_Coon right. I understand what it’s supposed to do on a simple CPU like the teensy where indeed you can run stuff during interrupts as long as you’re fast enough, on the ESP chips, I think interrupts are never really disabled, or to put it another way there seems to always be some background stuff running that can mess with neopixel timing, especially on ESP32.
So, I was wondering if FASTLED_ALLOW_INTERRUPTS actually made a real difference there (assuming no ISR in the user code), and whether even anyone has gotten fastled to work without glitching on ESP8266 (I have not).
@Marc_MERLIN I have 12 different pieces currently running on Wemos D1 Mini Pro ESP8266 boards, no glitching. Most are WS2811 & WS2812 (~256 per piece), and one with ~400 APA102.
Ah, great to know. Then not sure why it was glitchy for me, but at least it’s good to know that FastLED manages to get the CPU to respond in a time consistent manner, which is not trivial to do on an ESP8266.
#define FASTLED_ALLOW_INTERRUPTS 0
fixed my problem. The fastLED demo reel works fine on WeMos D1 with 144 pixels.
Question though, I’m guessing that the default FastLED setting is there for a reason. What are the drawbacks of using this method to get FastLED to work with ESP8266? Will I run into issues when I’m trying to do music syncing from microphone or line input, or switching modes based on buttons? Or does this create issues with the LEDs when used in combination with ESP8266 Wifi control code? I read the documents linked to above, but this still wasn’t quite clear to me.
@Mike_Clifford I’m not an expert, but my understanding is that turning off interrupts on ESP8266 will break wifi and anything else that runs in the background in addition to arduino code. On other platforms, you’re allowed to have short interrupt code, but my guess is that on ESP8266 it just won’t work.
If you need wifi and/or other interrupt code, you should look at the I2S driver I mentioned in comment #10
@Mike_Clifford@Marc_MERLIN I set Interrupts to 0 on my WeMos D1 Mini and am using @Jason_Coon 's Web Server without any issues. My IR receiver works as well.