Control Arduino with Universal Remote

This library works great for me using the sample program to print out the remote codes.
But, when I try to integrate it into my object-avoiding robot, things go bad. One of two motors stops completely, the other becomes intermittent. The stepper motor used for vision control "drifts" when not being driven, like it is being disconnected for short periods of time. I am using the servotimer1 library, but that just uses timer 1 and it looks like NECIRrcv is using timer 2.

Any idea what could be going wrong?
Any idea how much RAM this library uses?

Thanks!

Any idea how much RAM this library uses?

Here is a thread with 2 different functions to determine how much ram a program is using if that helps.
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1213583720;start=all

Well I don't think it is a memory problem. I tried two different memory tests down in the innermost loop. One showed 638 bytes free, the other, 697.

For reference, here's my code, I'd sure appreciate the help. I wonder if the NECIRrcv library is colliding with servoTimer1 in some way. When I uncomment the ir.begin() line, things go bonkers.

#include <ServoTimer1.h>
#include <NECIRrcv.h>

int eyePin = 0;
int servoPin = 10;
int bumperPin = 7;
int motor_leftdig=4;
int motor_leftpwm=5;
int motor_rightdig=12;
int motor_rightpwm=11;
int irPin = 8;

/* Object constants */
#define DANGER_DISTANCE 500
#define MAX_SAFE_DISTANCE 400

/* Servo motor contstants */
#define SERVO_STEP_SIZE 5
#define NUM_SERVO_STEPS 36
#define STRAIGHT_AHEAD 18

/* Motor speeds. PWM output pins turn 0-255 into 0-5v */
#define NO_SPEED 0
#define HALF_SPEED 127
#define FULL_SPEED 255

#define ON 0
#define OFF 1

int view[NUM_SERVO_STEPS];
ServoTimer1 servo;
NECIRrcv ir(irPin);

void setup() {
pinMode(motor_leftdig, OUTPUT);
pinMode(motor_rightdig, OUTPUT);
servo.attach(servoPin);
moveServo(STRAIGHT_AHEAD);
// Serial.begin(9600); /* For debugging purposes only */
// ir.begin();

}

void loop() {
static int remoteControl = OFF;

if (remoteControl == ON) {
stopMoving();
}
else { // Remote control = OFF

/* If we hit something with the bump switch, back up and turn around */
if (digitalRead(bumperPin) == HIGH) {
stopMoving();
reverse();
delay(1000);
stopMoving();
turnAround(bestDirection());
}

/* Debounce the Sharp IR sensor. I suspect a capacitor would work just as well... /
int distance = analogRead(eyePin);
while (abs(distance - analogRead(eyePin)) > 20) {
distance = analogRead(eyePin); /
Debounce */
}

/* Too close to something? Stop and turn around */
if (distance > DANGER_DISTANCE) {
stopMoving();
turnAround(bestDirection());
}

/* Getting close to something, slow down */
else if (distance > MAX_SAFE_DISTANCE) {
halfSpeed();
}

/* All clear ahead, full on */
else {
moveStraight();
}
}
}

void moveServo(int distance) {
servo.write(distanceSERVO_STEP_SIZE);
delay(50); /
For the servo to settle */
}

/*

  • Routine to figure out where to rotate to get the most unobstructed angle.
    /
    int bestDirection() {
    /
  • Rotate the servo, building a map of the obstacles we see in front of us.
  • Record the position that is most unobstructed, scaled up to use as a delay factor when turning.
    */
    refresh_view(0, NUM_SERVO_STEPS);
    int safest = furthestView();
    return ((safest - STRAIGHT_AHEAD) * 50);
    }

/* Routine to return the least number in the view[] array. */
int furthestView() {
int furthest=view[0];
int servo_position=0;

for (int i=0; i<NUM_SERVO_STEPS; i++) {
if (view < furthest) {
_ furthest = view*;_
servo_position = i;
_
} _
_
}_
return(servo_position);
_
}_
_/ Routine to scan around, recording what we see where /
void refresh_view(int start, int end) {
_
for (int i=start; i<end; i++) {

_
moveServo(i);_
_ / Debounce the Sharp IR sensor /
while (abs(analogRead(eyePin) - view
) > 10) {
view = analogRead(eyePin);
}
}_

moveServo(STRAIGHT_AHEAD);
_}
/ Negative turnAmount means turn left, positive turnAmount means turn right /
void turnAround(int turnAmount) {
if (turnAmount < 0) {_

setSpeed(-FULL_SPEED, FULL_SPEED);
_ }
else {_

setSpeed(FULL_SPEED, -FULL_SPEED);
_ }
delay(500); / Arbitrary delay factor, it just works well /
}
void moveStraight() {_

setSpeed(FULL_SPEED, FULL_SPEED);
_}
void stopMoving() {_

setSpeed(NO_SPEED, NO_SPEED);
_ delay(500);
}
void halfSpeed() {_

setSpeed(HALF_SPEED, HALF_SPEED);
_}
void reverse() {_

setSpeed(-FULL_SPEED, -FULL_SPEED);
_ delay(500);
}
void setSpeed(int left, int right) {
if (left >= 0) { / Forward /_

digitalWrite(motor_leftdig, LOW);
analogWrite(motor_leftpwm, left);
_ }
else { / Reverse /_

digitalWrite(motor_leftdig, HIGH);
analogWrite(motor_leftpwm, FULL_SPEED+left);
_ }
if (right >= 0) { / Forward /_

digitalWrite(motor_rightdig, LOW);
analogWrite(motor_rightpwm, right);
_ }
else { / Reverse /_

digitalWrite(motor_rightdig, HIGH);
analogWrite(motor_rightpwm, FULL_SPEED+right);
_ }
}*_

does this work with a infrared LED reciever? what resistor should i use??

hi, i am very new to arduino and programming. i have attempted to replicate the code above but for some unknown reason i get this really weird error message:
"
In file included from C:\Documents and Settings\Adam\Desktop\arduino-0012\hardware\cores\arduino/WProgram.h:4,

c:/documents and settings/adam/desktop/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:80: error: expected unqualified-id before 'int'

c:/documents and settings/adam/desktop/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:80: error: expected `)' before 'int'

c:/documents and settings/adam/desktop/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:80: error: expected `)' before 'int'

c:/documents and settings/adam/desktop/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:111: error: expected unqualified-id before 'int'

c:/documents and settings/adam/desktop/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:111: error: expected `)' before 'int'

c:/documents and settings/adam/desktop/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:111: error: expected `)' before 'int'

c:/documents and settings/adam/desktop/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:144: error: expected identifier before '(' token

c:/documents and settings/adam/desktop/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:144: error: expected `)' before '(' token

c:/documents and settings/adam/desktop/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:144: error: expected ',' or '...' before '(' token

c:/documents and settings/adam/desktop/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:144: error: expected initializer before ')' token

c:/documents and settings/adam/desktop/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:176: error: '__compar_fn_t' has not been declared

In file included from C:\Documents and Settings\Adam\Desktop\arduino-0012\hardware\cores\arduino/WProgram.h:6,

"
and i dont know what is going on because it doesnt even mention anything to do with the NECIRrcv library.
any possible ideas on how to overcome this?
thanks

Maybe a syntax error of some kind? Did you cut and paste the code exactly as is, or type it in yourself? If the latter, post your code and maybe I can spot the problem. By the way, I got this working perfectly, basically by making sure the servo was stopped anytime I was reading the receiver. I think there was some interference going on.

hi, sorry i didnt mean to confuse but i copied and pasted the original code posted by jmknapp and for some reason recieved those errors. i copied and pasted exactly and cannot get it to work.
any ideas?

The code was written for version 0011 of the IDE. You are running version 0012.

There are a few fixes floating around on the forum. Check the last post here:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1221741304/52#52

But also do some searching around.

ladyada has a version of servotimer1 that works with 0012 here: http://www.ladyada.net/media/mshield/ServoTimer1-fixed.zip

No that code worked fine for me, make sure you've got the NECIR library installed.

I have the NECIRrcv.h library added to the Arduino sw but still get compiling errors when compiling the small program that is listed above:

In file included from C:\Program Files\arduino-0012\hardware\cores\arduino/WProgram.h:4,

c:/program files/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:80: error: expected unqualified-id before 'int'

c:/program files/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:80: error: expected `)' before 'int'

......

c:/program files/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:176: error: '__compar_fn_t' has not been declared

In file included from C:\Program Files\arduino-0012\hardware\cores\arduino/WProgram.h:6,

Do I need some other library? WProgram?

Please help... I am totally new and "desperately" need a working NEC IR receiving sketch.

Thanx...

did you check out the what trialex posted above?

I think I can take two things from this post:

  1. Include #undef int somewhere

    • Moved insertion of #include <WProgram.h> to after any comments and #include statements in the main sketch file. This means that an #include <stdlib.h> now works.

If one of these or both are supposed to "do the job" where do I have to change code then? In "NECIRrcv.h" or in the "main sketch calling "NECIRrcv.h"?

Peter.

Hi, I am a noob at Arduino en English... :stuck_out_tongue:

And I have a problem, I use a IR Photodiode for this library, does that work? And do you must connect the Photodiode to a analog pin or a digital?

The IR signal from a remote control has a carrier frequency, usually around 38kHz or 40kHz. This helps filter out noise because the system can ignore any signal that's not at the carrier frequency.

The IR modules discussed in this thread strip out the carrier and just output the signal. If you use a straight photodiode connected to an Arduino pin, the pin will see the carrier frequency, and you will have to deal with that signal.

You would connect it to a digital input, but connecting it isn't completely straightforward.

Hey Lighty,
To be able to receive and decode commands from remote controls you would need an IR receiver, like this one:

This is an IC that does much more than a photodiode.
Signals from this IR receiver is digital, so you connect it to a digital input.
Read this:
http://www.arduino.cc/playground/Code/InfraredReceivers
or follow this thread for another solution:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1176098434

Ah this is really cool!

Where did this code go?

does anyone still have this library? can you send it to me?

Here are some mirrors where you can download the necirrcv file.

http://www.easy-upload.nl/index.php/file/164a43b8100a5b3
http://lemio.nl/files/necirrcv.zip

Modernators, please add these to the begin post.