IR remote question

It is a neopixels strip WS2812 I think, it was all working, beit a little flakily due to the problem that exists using the IRremote library and the Neopixels libraries in the same sketch, something to do with the use of interupts. My plan is to use one Arduino Nano as a receiver (this sketch) then output the colour values to 3 analog ports which will be read by another Nano to drive the Neopixel strip. Not a particularly elegant solution by it should work.

0xC001

Two MCUs is not such a bad idea.

There are no analog out port really though, I suppose you mean PWM ? how will you read that on the other arduino ?

Hmmm………… yes I was just researching this, I had originally thought that analog pins did actually output analog voltages, More research needed methinks, there has to be a way ;-)

Why wouldn't you use serial communication? Not exotic enough?

The neopixels (if you have a lot and lots of animation) will block interrupts for quite some time.

That's why it's an issue to use with the IR library (which requires interrupts to be triggered very often by a timer)

Using Hardware Serial might also prove a challenge, if the interrupts are blocked for too long, the UART might loose a few bytes along the way...


an option might be to go to an ESP32 where using FastLED with the RMT driver for NeoPixels avoids blocking interrupts, so it can coexist with an IR receiver more reliably. The IR library can then receive signals without being blocked. Using thousands of LEDs or very long update frames can still introduce occasional glitches...

Sounds like a perfect solution, I’ll look into it, though my 73 year old brainbox is a bit slow on the uptake, you’ve probably noticed.:wink:

Another vote for that.

Hi @mancavebob !

There might be a workaround that may work in your environment:

You replace all pixels.show() calls by a function like this (using your variable names of course)

void pixelsShow() {
  if (IrReceiver.isIdle()) {
    pixels.show();
  }
}

Here is an example on Wokwi:

https://wokwi.com/projects/421312361290532865

It might be worth a try.

The source of my "wisdom" is

http://www.notsodistantfuture.com/2016/12/04/resolving-timing-conflicts-with-neopixels-and-ir-signal-processing.html

Good luck!
ec2021

1 Like

The authoritative source is directly in the libary’s documentation where they mention that

2 Likes

Thanks @J-M-L !

I came across the link I posted a year ago when this problem occurred in a thread that time …

The GitHub documentation you posted has an additional interesting link to Marc Merlin's Neopixel project that gives further hints for the use of Teensy and ESP controllers.

@mancavebob if the function mentioned above doesn't work it might be helpful for you! Have fun and let's keep our brainboxes in a good shape!

Thanks for this, I try it a while ago without any success but must have entered something wrongly. Now working perfectly with the old library v 2.2.3

I’ll now have a go at updating it for the new version 4.6.0 as I’m sure my IDE will sooner or later update the library anyway. Thanks everyone for your help :grinning_face:

In my quest to use the idea of a second proccessor to process the neopixels bit using serial transfer from the IRreceiver, I’ve been looking at examples of serial data transfer. I’ve looked at several so far and in every case they fail to compile. In all cases I get the error

Compilation error: 'Serial1' was not declared in this scope

Below is just one example from serialtransfer.h v3.1.5 Why is this?

#include "SerialTransfer.h"

SerialTransfer myTransfer;

struct STRUCT {
  uint16_t adcVal;
  float voltage;
} data;

void setup()
{
  Serial.begin(115200);
  Serial1.begin(115200);
  myTransfer.begin(Serial1);
}

void loop()
{
  data.adcVal  = analogRead(0);
  data.voltage = (data.adcVal * 5.0) / 1023.0;
  
  myTransfer.txObj(data, sizeof(data));
  myTransfer.sendData(sizeof(data));
  delay(100);
}

What kind of arduino do you have ? not all boards have Serial1...

Ah, I hadn’t realised that, I’m using Nano, can I not do serial comms using these?

The classic Nano is like the UNO, only one UART. In theory you could use Serial rather than Serial1 as long as it's dedicated to this inter-board communication. (you'll have to unplug from pins 0 and 1 when uploading code).

But as I said earlier, Serial depends on interruptions too and the sender does not check if the receiver is ready for the next byte. It dumps it all at the speed defined in code (baud rate).

For WS2812 or WS2812B NeoPixels, updating one pixel takes about 30 microseconds because each pixel requires 24 bits sent at 800 kHz plus a one time reset latch time of roughly 50 microseconds.

Say you have 1000 pixels to update - 1000 x 30 + 50 = 30,050 µs ➜ ~30ms. So every time you call show on the strip(s) you block interruptions for 30ms.

In your code you want to send the data at 115200 bauds

That means you send roughly 11520 bytes per second or ~11 per ms.

➜ if you lock the interrupts for 30 ms, you stand to loose ~337 bytes in your communication... So I don't think it will work out fine...

Personally I buy APA102 led strips, they are a bit more expensive but they don't have the timing challenge of the neopixels so interrupts are not locked when updating them and you can also run them much faster (if you have SPI at 4Mhz the 1000 leds update in 8ms) .

Thanks once again, I will need some time to digest all of this, but here goes :grinning_face: