Hi!
I've got a NeoPixel shield running rainbow(20) on a loop (from the Neopixel shield sample code). I'm trying to use an IR receiver so I can turn the shield on and off. The IR receiver alone is working fine, however, when the rainbow function is running, the IR receiver is never getting through. Is there a way to set up the IR receiver on an interrupt or something?
Thanks!
Can't use IR receiver with Neopixel Rainbow Function
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- dannya
- Posts: 111
- Joined: Thu Nov 14, 2013 7:35 pm
- Franklin97355
- Posts: 23910
- Joined: Mon Apr 21, 2008 2:33 pm
Re: Can't use IR receiver with Neopixel Rainbow Function
I'm sure there is some way to do that. What IR receiver are you using and post your code using
Code: Select all
tags or the code button </> also tell us how you have things connected.
- SeiRruf
- Posts: 82
- Joined: Thu Sep 04, 2014 3:07 am
Re: Can't use IR receiver with Neopixel Rainbow Function
dannya,
I have had this same problem and have not been able to come up with a solid solution myself, yet.
I was able to find out one thing though. The problem relies within the timing used to control the NeoPixels. The IR receiver so happens to be quite picky with receiving commands, and being how the NeoPixels completely disable the internal inturrupts, there becomes no room for the IR receiver to function properly as they are then required (which explains why it stops working when your LEDs are cycling the rainbow, the arduino is constantly updating them every 20ms, but in other modes, I am guessing your animations aren't as constant).
The trick.
I ended up writing code to check for an IR signal before the neopixles are updated. This may delay some animations, but it worked quite nicely.
Something like:
That function would replace occurrences of strip.show() in your existing code.
I hope this sends you in the right direction. :)
EDIT:
clafrieda was able to achieve this, and posted his complicated source code here (not sure why he chose to library-ify everything, but it's sweet):
http://forums.adafruit.com/viewtopic.ph ... 2&p=288672
I have had this same problem and have not been able to come up with a solid solution myself, yet.
I was able to find out one thing though. The problem relies within the timing used to control the NeoPixels. The IR receiver so happens to be quite picky with receiving commands, and being how the NeoPixels completely disable the internal inturrupts, there becomes no room for the IR receiver to function properly as they are then required (which explains why it stops working when your LEDs are cycling the rainbow, the arduino is constantly updating them every 20ms, but in other modes, I am guessing your animations aren't as constant).
The trick.
I ended up writing code to check for an IR signal before the neopixles are updated. This may delay some animations, but it worked quite nicely.
Something like:
Code: Select all
void stripShowCheckIR ()
{
if ( irLibrary.check() == 0 ) { //irLibrary, as an example (won't work, replace with your setup)
//delay (20); //you mayyy need some delay here. Kind of depends, commented out for now.
//do IR processing here
}
//then push the strip on
strip.show ();
}
I hope this sends you in the right direction. :)
EDIT:
clafrieda was able to achieve this, and posted his complicated source code here (not sure why he chose to library-ify everything, but it's sweet):
http://forums.adafruit.com/viewtopic.ph ... 2&p=288672
Last edited by SeiRruf on Fri Sep 12, 2014 5:08 pm, edited 1 time in total.
- adafruit_support_bill
- Posts: 88087
- Joined: Sat Feb 07, 2009 10:11 am
Re: Can't use IR receiver with Neopixel Rainbow Function
Interrupts are disabled in the neopixel show() code in order to meet the tight WS2811 timing constraints. Checking for IR between calls to show() is about the only option - other than adding a second processor for the IR.
- michaelmeissner
- Posts: 1821
- Joined: Wed Aug 29, 2012 12:40 am
Re: Can't use IR receiver with Neopixel Rainbow Function
In terms of adding a second processor for IR, there are some chips that do the decoding of IR, and emit a signal that you can read to off-load the IR handling.
- Sparcfun sells the SIS-2 that can handle 2 different IR signals: https://www.sparkfun.com/products/8753;
- The Simerec manufacturer of the SIS-2 chip also makes a SIS-7C chip that can handle 7 different IR signals, that they sell directly: http://www.simerec.com/order.html
- Sure electronics makes an IR decoder chip that you can use to read 7 signals (NEC protocol) from via 3 pins or various signals using a UART: http://www.ebay.com/itm/350608682887?_t ... EBIDX%3AIT
- Obviously, you could use an ATtiny85 with the appropriate IR receiver (either a raw ATtiny85, or Gemma/Trinket).
- michaelmeissner
- Posts: 1821
- Joined: Wed Aug 29, 2012 12:40 am
Re: Can't use IR receiver with Neopixel Rainbow Function
As a footnote, decoding IR signals has similar timing constraints to neopixels, except it is on input instead of output (i.e. you have to wait and see if you got a short pulse or a long pulse). Controlling servos and reading encoder pulses is other areas where neopixels turning off interrupt handling for relatively long periods of time can be a problem.
- dannya
- Posts: 111
- Joined: Thu Nov 14, 2013 7:35 pm
Re: Can't use IR receiver with Neopixel Rainbow Function
Could I do it this way?
Hook up the Neopixels to the Arduino, and add an ATTiny to the project, whose sole function is to interface with the IR receiver? Then, I can have the ATTiny trigger a transistor or a relay which will allow the power to flow to the Neopixels?
Also, I just got the Neopixel board, which seems to have greater power requirements than the shield, and I read that it needs to have a separate power supply. Can I take the 5V 2A power supply, hook it up to the breadboard, and wire that to both the Neopixel board AND the Trinket? Or is that too much power draw (if I have all the LED's lit, but not all of them on white ever at the same time)?
Thanks!
Hook up the Neopixels to the Arduino, and add an ATTiny to the project, whose sole function is to interface with the IR receiver? Then, I can have the ATTiny trigger a transistor or a relay which will allow the power to flow to the Neopixels?
Also, I just got the Neopixel board, which seems to have greater power requirements than the shield, and I read that it needs to have a separate power supply. Can I take the 5V 2A power supply, hook it up to the breadboard, and wire that to both the Neopixel board AND the Trinket? Or is that too much power draw (if I have all the LED's lit, but not all of them on white ever at the same time)?
Thanks!
- adafruit_support_bill
- Posts: 88087
- Joined: Sat Feb 07, 2009 10:11 am
Re: Can't use IR receiver with Neopixel Rainbow Function
It is not a good idea to be sending control signals to an un-powered neopixel. Better to keep it powered and have the ATTiny trigger the Arduino to start displaying things on the pixels.Then, I can have the ATTiny trigger a transistor or a relay which will allow the power to flow to the Neopixels?
The best way is to wire the power supply direct to the Neopixels (your main power consumer) and then run wires from that back to the Trinket and/or Arduino.Can I take the 5V 2A power supply, hook it up to the breadboard, and wire that to both the Neopixel board AND the Trinket?
- dannya
- Posts: 111
- Joined: Thu Nov 14, 2013 7:35 pm
Re: Can't use IR receiver with Neopixel Rainbow Function
Thanks!
So I should have the transistor/relay sit in between the power-out pin from the neopixel board to the Vin pin on the Trinket? Meaning, when the relay is "off" the Arduino will have no power, correct? If I kill power to the Arduino (via the relay), won't the Neopixel board remain lit with whatever the last command sent was? Or if it loses it's data input pin does it go completely dark?
Is it preferable to use a relay or a transistor?
Does the Neopixel board have power out and ground out pins (I don't have it with me, traveling at the moment)?
Thanks!
So I should have the transistor/relay sit in between the power-out pin from the neopixel board to the Vin pin on the Trinket? Meaning, when the relay is "off" the Arduino will have no power, correct? If I kill power to the Arduino (via the relay), won't the Neopixel board remain lit with whatever the last command sent was? Or if it loses it's data input pin does it go completely dark?
Is it preferable to use a relay or a transistor?
Does the Neopixel board have power out and ground out pins (I don't have it with me, traveling at the moment)?
Thanks!
- dannya
- Posts: 111
- Joined: Thu Nov 14, 2013 7:35 pm
Re: Can't use IR receiver with Neopixel Rainbow Function
....and I would need the ATTiny to always have power to receive the IR commands, so how do I give THAT power? Directly from the 5v 2a wall wart wires?
- adafruit_support_bill
- Posts: 88087
- Joined: Sat Feb 07, 2009 10:11 am
Re: Can't use IR receiver with Neopixel Rainbow Function
Just keep everything powered full time. and use the IR commands to tell the Arduino how to control the pixels.
Please be positive and constructive with your questions and comments.