Show me the code!
Sure, it's here: https://github.com/marcmerlin/Neopixel-IR (but go to the end of this page for more details). See also the newer https://github.com/marcmerlin/NeoMatrix-FastLED-IR (from http://marc.merlins.org/perso/arduino/post_2018-07-30_Building-a-64x64-Neopixel-Neomatrix-_4096-pixels_-running-NeoMatrix-FastLED-IR.html )Why my pants needed IR controlled neopixels :)
I mean, don't everyone's pants need neopixels? :) I started with a silver shirt, I added a few LEDs, and then more I got from a swap meet, and later added some LED shoes I hacked to last 12H instead of 4 The end goal was adding neopixel strips on my shirt sleeves and pant legs: Here is a 6mn clip showing the shoes and shirt if you'd like the details:Why IR and Neopixels at the same time, is hard
So, the main point of this page is however to look into the issues of controlling Neopixels and receiving IR signals at the same time. It's easy to listen for IR, and then change neopixels, leave them alone, and listen for IR again. It's hard (or near impossible on some chips) to actively update neopixel strips for animations and listen for IR commands at the same time. Why? This video explains the issue:Now, there are actually many other addressable multicolor LED types. The nice ones are 4 wire and work via SPI, which allows the CPU to control the timing and the clock, removing this exact bit banging timing issue. The cheaper 3 wire ones have a set clock and require that the CPU sends a very precisely timed signal, usually done while disabling interrupts. See https://github.com/FastLED/FastLED/wiki/Overview But since neopixel strips (aka WS2811/WS2812/WS2812B) is what I already had, I now had to deal with this precise timing issue. As you can guess, disabling interrupts causes issues with the IRRemote library because it has its on interrupt handler timer that also requires being run at a special timing, or it doesn't capture proper IR signals.
The end result is that you cannot disable interrupts and receive IR signals, and if you don't disable interrupts, the neopixel signal is unstable and the colors flicker (demonstrated int the video above). So, unless you use some special hardware to drive neopixels strips on an AVR chip, concurrent IR + neopixels is just not going to work.
an arduino nano v3 running neopixel strips
my 328p arduiny chip (equivalent to arduino nano) and anti plug backwards toothpicks :)
because my 328p chip was unprogrammed, I had to figure out direct ISP programming pinout for it and I flashed a bootloader on it
Concurrent IR + Neopixels solution #1: be fast (Teensy 3.1)
a few chips for comparison (uno, leostick, nano v3, arduiny, and Teensy 3.1 in green)
sei(); delayMicroseconds(WAIT_TIME); cli(); Thanks to this re-enabling of interrupts, things work. So at this point, someone sensible would have declared victory. However, I felt bad wasting a Teensy 3.1 on something as simple as driving a single neopixel strip (it can drive 8 in parallel) and reading from an IR receiver, when it has around 32 I/O ports. This is why I checked if I could get this to work on ESP8266 chips which are even cheaper and have much fewer I/O pins (but add Wifi)
Concurrent IR + Neopixels solution #2: don't use the CPU for neopixels (ESP8266 (I2S) and ESP32 (RMT))
I had more 32bit chips, so I thought I would give them a try. I tried the ESP8266 and ESP32: First, the ESP8266 mostly worked with FastLED + IRRemote, but not quite. The FastLed code, just like on Teensy, is nice enough to re-enable interrupts for a short while: https://github.com/FastLED/FastLED/blob/master/platforms/esp/8266/clockless_esp8266.h#L45os_intr_unlock();However in my tests, the IRremoteESP8266 library was maybe a little bit too slow and caused occasional visible neopixel glitching (this has been fixed in FastLED since I originally wrote this). This is where I found this interesting library: https://github.com/JoDaNl/esp8266_ws2812_i2s/ which manages to drive the neopixels without doing bit banging with interrupts disabled ((ab)-using the I2S hardware support). It's not a very fancy library in what it offers, but it works perfectly with interrupts enabled. There is another DMA library using the UART instead of I2S interface, that also works without affecting interrupts: https://github.com/Makuna/NeoPixelBus
delayMicroseconds(WAIT_TIME);
os_intr_lock();
Same thing for ESP32. Actually ESP32 is even more difficult to get a perfect timing out of using bit-banging given that it's a dual core CPU running on top of an RTOS, and no matter how precise your code is, you just cannot guarantee that it'll run perfectly at the timing you need all the time. I did add ESP32 support to the Adafruit Neopixel library, but it only works most of the time, which isn't really good enough.
This where its built in RMT support comes in. It can generate 8 precise signal waves, which are perfect for neopixels, so this is the way to go to animate neopixels without disabling interrupts (making IR receiving trivial). IRremote was missing ESP32 receive support, but I added it recently, so it's all working. FastLED now supports RMT on ESP32, so you can run interrupts while talking to Neopixels. Here's a video summary of ESP8266 and ESP32: