I've been knocking my head against the wall for a few days trying to get my Arduino Uno to receive IR signals from a 2nd gen Apple remote, and then control a standard Futaba servo with the received codes. It is a BoeBot application, so I am using the Board of Education shield with an IR receiver from Parallax running to pin 4 and the servo to pin 12. The problem I am having is that whenever I load Ken Shirriff's IRremote.h library and the Servo.h library, I encounter a servo twitch.
Here's a simple instance of the code that is giving me the issue:
Code: Select all
#include <IRremote.h>
#include <Servo.h>
int RECV_PIN = 4;
IRrecv irrecv(RECV_PIN);
Servo myservo;
void setup()
{
irrecv.enableIRIn(); // Start the receiver
myservo.attach(12);
}
void loop()
{
}
Here are some things I've tried:
1. Using a different servo
2. Using different pins, for both the servo and IR receiver
3. Change the IRreceive.h library to interrupt with timer0, instead of timer2. (My thinking here is that there may have been a priority of operation, and I wanted to give the servo priority over the IR pin. This didn't change anything though, and I'm pretty sure timer0 has higher priority anyhow..)
4. Wrap the IRremote.h timer ISR in a "detach.servo();" and "attach.servo();" command somehow, but I can't seem to get the coding correct, and I'm not sure if this approach would work.
I should mention that the IR receive demo sketch and a basic servo sweep sketch work just fine when they're independent of one another.
I've seen some postings online where people have gotten the same code to work on the same type of application, so I feel like I'm really missing something big here. I've copied their approach exactly, but am still stuck with a twitchy servo. Any help would be great..I really do appreciate the support.
Ken Shirriff's IRremote library:
https://github.com/shirriff/Arduino-IRremote