QTR Sensor Library and the Arduino Mega

Hi, I seem to be having trouble getting the QTR-8RC sensor to work on the Mega. The sensors seem to always time out. I assume something in the code isnt quite translating over correctly. Any thoughts as to what’s going wrong would be most appreciated.



I’ve heard of people having problems with the QTR code on Arduinos. I don’t have an Arduino to test it on, but it works on a bare AVR running at 20 MHz. The 16 MHz clock on the Arduino shouldn’t break it, but it seems like something in the Arduino’s environment is interfering with its operation.

Reading the QTR-RC sensors is as simple as performing digital pulse timing, so it wouldn’t be hard for you to write your own sensor-reading functions. You could also try using the Pololu AVR library code as a starting point and modify it until you get something that works. If you do manage to figure out why it doesn’t work on the Arduino, please let us know!

- Ben


Just a guess after trying to get the think to run for 2hrs (thanks man, you could have written put what you posted into this forum into the manual): Your library seems to be ignorant of the fact that each Arduino has a different microcrontroler and wiring. Example: In your .h file it says

Note that Arduino digital pins 0 - 7 correpsond to port D
	// pins PD0 - PD7, respectively.  Arduino digital pins 8 - 13
	// correspond to port B pins PB0 - PB5.  Arduino analog inputs
	// 0 - 5 are referred to as digital pins 14 - 19 (these are the
	// enumerations you should use for this library) and correspond
	// to port C pins PC0 - PC5.

Might be true for some arduinos, but in the mega eg. I/O pins 0-7 are connected to PE0, PE1, PE4, PE5, PG5, PE3, PH3 and PH4. This already screws you library if somebody tries to connect a sensor to I/O 0-7. Same true for the rest of the pins.

I think it is very cool that you try to write/write a library for Arduino, but please keep it updated. Otherwise it gets only annoying.

Thanks, Garnele

Ps. No, it also doesn’t work if you try to connect it to the right PC/PD/PB. On the Arduino mega eg, PC0 is equal to digital pin 37. Connect it to 37 and write PololuQTRSensorsRC qtr((unsigned char[]) {14}, 1), it doesn’t work. There seems to be some timer problem too, maybe you guys could look into that?