Well, I’ve fairly extensively tested the QTR library and it works fine for me. Note that the modification date of the QTR library I’m using is 8/26/08 and it comes as part of the Pololu AVR library package that you can download here.
I wrote the following two programs using the Arduino IDE and programmed them onto a mega168 that has pin 0 (PD0) connected to the sensor’s LEDON (emitter) pin and analog inputs 0 - 3 (PC0 - PC3) connected to sensor outputs 1 - 4 as labeled on the array’s PCB:
Test of raw sensor output:
#include <OrangutanLCD.h>
#include <PololuQTRSensors.h>
#define NUMSENSORS 4
#define SAMPLES 3
#define EMITTERPIN 0
unsigned int sensors[8];
long cnt = 0;
unsigned int line = 0;
OrangutanLCD lcd;
PololuQTRSensorsAnalog qtra((unsigned char[]) {0, 1, 2, 3}, NUMSENSORS, SAMPLES, EMITTERPIN);
void setup()
{
}
void loop()
{
int i;
qtra.read(sensors, QTR_EMITTERS_ON);
lcd.gotoXY(0, 0);
for (i = 0; i < 4; i++)
{
lcd.print(sensors[i] / 103);
lcd.print(' ');
}
lcd.gotoXY(0, 1);
qtra.read(sensors, QTR_EMITTERS_OFF);
for (i = 0; i < 4; i++)
{
lcd.print(sensors[i] / 103);
lcd.print(' ');
}
delay(100); // stop the program for some time
}
Test of calibrated sensor output:
#include <OrangutanLCD.h>
#include <PololuQTRSensors.h>
#define NUMSENSORS 4
#define SAMPLES 3
#define EMITTERPIN 0
unsigned int sensors[8];
long cnt = 0;
unsigned int line = 0;
OrangutanLCD lcd;
PololuQTRSensorsAnalog qtra((unsigned char[]) {0, 1, 2, 3}, NUMSENSORS, SAMPLES, EMITTERPIN);
void setup()
{
int i;
lcd.clear();
lcd.print("...");
delay(3000);
lcd.clear();
lcd.print("calib.");
for (i = 0; i < 250; i++)
{
qtra.calibrate();
delay(20);
}
}
void loop()
{
int i;
int position = qtra.readLine(sensors, QTR_EMITTERS_ON);
lcd.clear();
lcd.print("pos=");
lcd.print(position);
lcd.gotoXY(0, 1);
for (i = 0; i < 4; i++)
{
lcd.print(sensors[i] / 101);
lcd.print(' ');
}
delay(200); // stop the program for some time
}
You should be able to make this code work on your end by replacing the lcd methods with serial output calls. I think you either still have an old version of the library or something very strange is going on, because every aspect of these programs works as expected for me.
- Ben