Pololu QTR-8RC sensor on RPi

We are using a Pololu QTR-8RC line following module. This sensor array has 8 IR LED/phototransistor pairs and provides a capacitor discharge that we need to time in order to work out any relative reflectance – lower values would be lighter surfaces to higher values.

a diagram of the sensor array showing measurments: 7 times 0.375 inch sections

qtr-8rc showing connectors and dimensions

The sensor array is powered by 3V3 (5v default, converts to 3V3 by bypassing a resistor) direct from the Pi’s rail. A mosfet is connected to LEDON pin on the sensor and is pulled up (if not connected it will be on) – LEDON can be PWM controlled which would help us manage the current required from the Pi to the IR LEDs but we’ve currently just attached it to a digital pin. Each IR pair is then connected to I/O pins 22 – 29 on our 40 pin GPIO. We’re using python wrapped wiringpi with wpi pin numbering.

sensor is wired and taped to piece of card

QTR-8RC connected to Pi, taped to cardboard hole to raise sensors from surface for testing

Guidance given in the qtr-8rx pdf suggests the following:

  1. Turn on IR LEDs (optional).
  2. Set the I/O line to an output and drive it high.
  3. Allow at least 10 μs for the sensor output to rise.
  4. Make the I/O line an input (high impedance).
  5. Measure the time for the voltage to decay by waiting for the I/O line to go low.
  6. Turn off IR LEDs (optional).

Here’s our code:

Pololu could be right and the qtr-8rc sensor might not be compatible with the Pi, we certainly would like to use the PWM capability of LEDON to lower the current required by the sensor array but we can’t get consistent raw readings when we do. This caused issues for us for over a week, the frustration almost driving us to withdrawing from the competition at times! (Little things can build up…) The PWM issue may be due to variable settings of the Pi’s PWM (pin 1/dcm 18)- clock speed/frequency, PWM type and the pulse-widths used or/and possible that wiringpi delay functions are messing with the system timings for the hardware PWM too, though that sort of understanding is far beyond us.

At the moment we are happy with just using digital on/off at 3V3 on LEDON which is working. We’ve got some calibration functions and headline functions to write and if we’ve time we may write a test client to cycle through the different PWM settings to see if we can get that working too. Critical thing for us next is to get the sensor detecting lines and our robot controlling the motors as needed.

Leave a Reply

Your email address will not be published. Required fields are marked *