External IR Sensor in Zumo

Hi
I have a Zumo Robot with 75:1 HP Motors.
Im mounting an extra IR Sensor on port 2, using this tutorial:
learn.adafruit.com/ir-sensor/using-an-ir-sensor

If the Zumo and Arduino UNO is only using the code provided in the tutorial, it works just fine. However, when I try to add the code to, for example, MazeSolver, It gets stucked here:

[code]void loop(void) {
uint16_t highpulse, lowpulse; // temporary storage timing
highpulse = lowpulse = 0; // start out with no pulse length

// while (digitalRead(IRpin)) { // this is too slow!
while (IRpin_PIN & (1 << IRpin)) { +++++++++++++++++STUCK HERE++++++++++++++++++++++++
// pin is still HIGH[/code]

this is my loop

[code]void loop()
{

int numberpulses;

numberpulses = listenForIR();
Serial.println(“listened”);
// solveMaze() explores every segment
// of the maze until it finds the finish
// line.
if (IRcompare(numberpulses, IRPlaySignal, sizeof(IRPlaySignal) / 4)) {
Serial.println(“PLAY”);
solveMaze();
}
if (IRcompare(numberpulses, IRStopSignal, sizeof( IRStopSignal) / 4)) {
Serial.println(“STOP”);
motors.setSpeeds(0, 0);
}

delay(100);
// Sound off buzzer to denote Zumo has solved the maze
buzzer.play(">>a32");

}[/code]

What Im trying to achieve is using a TV Remote, controlling the stop/go from the Zumo Robot.
By the way the code is getting stuck, I believe it has something to do with PORTD. BTW Im using PIN 2 for the IR Sensor. Correct me if Im wrong, but for a setup with IR Array, no LEDON, Buzzer, the pins go like this:
IR bottom sensors (5, A2, A0, 11, A3, and 4)
pushbutton digital pin 12
motor driver digital pin 7, 8, 9, 10
buzzer digital pin 3

free 2,6,A1, A2, A4, A5

Hello.

It sounds like you have an Arduino Uno that is connected to a Zumo Robot for Arduino, and you are trying to connect an IR sensor to pin 2 and use it to receive signals from a remote control.

On the Arduino Uno, pin 2 is usually used to control the IR emitters of the Zumo’s reflectance sensors. By default, the ZumoReflectanceSensorArray library uses pin 2 as an output, so it will not be able to receive remote control signals. To override that behavior and tell the library to not use any pin as an emitter pin, you could change the line that defines the sensor object to:

ZumoReflectanceSensorArray reflectanceSensors(QTR_NO_EMITTER_PIN);

Alternatively, you might edit the Adafruit code to use a different pin for the IR sensor. There is nothing special about pin 2; any I/O pin on the ATmega328P can act as a digital input.

Those pin assignments are mostly right. However, on the Arduino Uno, A4 and A5 are not free because they are the I2C lines (SCL and SDA) that are connected to sensors on the Zumo Shield. For more information, I recommend looking at the “Arduino pin assignment table” section of the Pololu Zumo Shield for Arduino User’s Guide.

If you continue to have trouble, please simplify your code to the simplest thing that should work, but does not, and then post your entire code here.

By the way, the newer Zumo 32U4 robot has IR receivers included in its front sensor array. These are designed for proximity sensing, but you can also use them to receive commands from a 38 kHz, 940 nm infrared remote. Here is a video we made to demonstrate this:

We are planning to release example code for that project soon. When we do, it will be an example in the Zumo32U4 library.

–David

Hi David,
Thanks for your reply.

Regarding

From what I read those I2C Lines are not connected by default, I need to manually wire them, so A4 and A5 are still free right?

Can you explain me [quote]IR emitters of the Zumo’s reflectance sensors[/quote] what is the IR emitters? ANd whats the LEDON for? Does it relates to the IR Emitters?

BTW is worth mentioning that I tried my setup with all the free pins and still didn’t suceeded.

The I2C jumpers are documented in the “Jumper settings” section of the Pololu Zumo Shield for Arduino User’s Guide. They are connected by default.

Each reflectance sensor in the Zumo Reflectance Sensor Array has an infrared (IR) emitter that shines downward. It is generally good to turn them on while reading the reflectance sensors and turn them off at other times. Our ZumoReflectanceSensorArray library takes care of this. LEDON is a pin on the reflectance sensor array that is high by default, but can be driven low to turn off the emitters. You can find more information on the Zumo Reflectance Sensor Array product page.

The Adafruit IR sensor code and our Zumo maze-solving example both use blocking loops and delays, so it will be hard to navigate the maze and also listen for remote control signals at the same time unless you make major changes to the code. If you are still having trouble, I still recommend posting a simplified version of your code demonstrating the problem. You should say exactly what you expect the code to do and what it actually does.

–David

Hi David,
I tried your sugeestion on the reflectance sensors but with no success. I also tried on pin 6. Im sending you some code. What I want to do is just controlling the car with a TV Remote, Stop and GO. That is just what I need. In going to have a line with intersections, thats why i used Maze solver, because it fixed the problem of following the wrong line - my car only goes straight forward and then straight forward (on a single line).

I altered a little bit of the maze solver, specifically, the turn method always goes straight instead of left and i removed some while(1) so that i made sure he would always return to the loop(). Before i did this I tried to put the IR listener on the followSegment() so that i could control the speed, but the same thing happens, I can’t read the sensor. If you delete everything related to the sensors the car and the IR sensor will work. I can attach you an image of my car setup, I dont think you need it, my IR sensor is on top of the car.

The IRcodes.h is specific to my TV Remote. If you want to test this out to the tutorial from adafruit I sent previously. Its really easy.

Thank you
CarLogicV2_zumosupp.rar (5.79 KB)

I looked at your code a little bit and I do not see anything obviously wrong with it.

Right now you have a code sample that works (successfully decodes an IR message) and a code sample that doesn’t work, but there are so many differences between the two code samples that it is hard to tell what is causing the problem. If you want to troubleshoot this, I recommend that you make one program that works and another one that doesn’t, where both of the programs are as short as possible (less than 40 lines) and as similar as possible (only a few lines are different). This will help us figure out what is actually causing the problem. Once you have these two programs, you should post them here using [code ] tags (without the spaces) and explain exactly how you expect them to behave, and how the non-working one actually behaves.

I would start first by simplifying the code that doesn’t work, which is a mixture of maze-solving and IR decoding code. Instead of calling IRListen, you could just turn on the yellow LED, loop until pin 2 goes low, and then turn off the yellow LED. This would tell you if your code can successfully get any kind of signal from the remote. If the problem is still there after this simplification, you can then remove IRListen and all the code it uses. I would also remove all of the code related to maze solving, line sensors, the buzzer, and the motors, unless some part of it turns out to be necessary for reproducing the problem.

–David