I am trying to use the stock Pololu QTR Sensor library (https://github.com/pololu/qtr-sensors-arduino) with my Teensy 3.5. When it reads the IR sensor, all it returns is 0 or 1, not the range of values it is supposed to return. I wrote some simple sample code and it works fine using my Arduino Uno, but the same code only returns 0 or 1 on the Teensy. The only difference is the pin number used for the input (12 on Uno, 2 on Teensy).
Any ideas what might be causing this? Has anyone had success using the Pololu sensors on Teensy?
Sample code:
#include <QTRSensors.h>
// Edge sensors
const int NUM_EDGE_SENSORS(1);
const int EDGE_TIMEOUT(500); // waits for 500 microseconds for sensor outputs to go low
QTRSensorsRC edgeSensors((unsigned char[]) {12}, NUM_EDGE_SENSORS, EDGE_TIMEOUT, QTR_NO_EMITTER_PIN);
unsigned int edgeSensorValues[NUM_EDGE_SENSORS];
void setup() {
Serial.begin(9600);
}
void loop() {
if (millis() % 100 == 0) {
readEdgeSensors();
}
}
void readEdgeSensors(void) {
// read raw sensor values
edgeSensors.read(edgeSensorValues);
// print the sensor values as numbers from 0 to 500, where 0 means maximum reflectance and
// 500 means minimum reflectance
for (unsigned char i = 0; i < NUM_EDGE_SENSORS; i++)
{
Serial.print(edgeSensorValues);
Serial.print('\t'); // tab to format the raw data into columns in the Serial monitor
}
Serial.println();
}
Any ideas what might be causing this? Has anyone had success using the Pololu sensors on Teensy?
Sample code:
#include <QTRSensors.h>
// Edge sensors
const int NUM_EDGE_SENSORS(1);
const int EDGE_TIMEOUT(500); // waits for 500 microseconds for sensor outputs to go low
QTRSensorsRC edgeSensors((unsigned char[]) {12}, NUM_EDGE_SENSORS, EDGE_TIMEOUT, QTR_NO_EMITTER_PIN);
unsigned int edgeSensorValues[NUM_EDGE_SENSORS];
void setup() {
Serial.begin(9600);
}
void loop() {
if (millis() % 100 == 0) {
readEdgeSensors();
}
}
void readEdgeSensors(void) {
// read raw sensor values
edgeSensors.read(edgeSensorValues);
// print the sensor values as numbers from 0 to 500, where 0 means maximum reflectance and
// 500 means minimum reflectance
for (unsigned char i = 0; i < NUM_EDGE_SENSORS; i++)
{
Serial.print(edgeSensorValues);
Serial.print('\t'); // tab to format the raw data into columns in the Serial monitor
}
Serial.println();
}