I’ve wired up the GP2D12 to pin 31 of my ATOM, and run this code:
sensor_read var word
main:
Adin 31,sensor_read
debug [DEC sensor_read,13]
pause (300)
goto main
its supposed to report distances between 10 and 80 cm as a value between 0 and 1024. But all I get is values between 600-800, and the values tend to wander all over the place, even when the sensor is pointing at the an immobile object.
Can anyone offer some advice with using these things? Is my sensor fubar?
Well, I realized I was reading a non-existent pin, so the new code is:
sdata var word
main:
Adin 0,sdata;
pause (2000)
debug DEC sdata,13]
goto main
but its still reading funny. When I turned it on, this was its output, it started out reading 496. With every read the value climbed till it stayed steady at 811. Moving the object its pointing at closer and farther didn’t change the value.
I restarted it and it repears the climb from a number near 500 to a number in the 800’s. Very strange!
This sensor’s docs do not say anything about triggering it (its not the lynxmotion IRPD, this is the Sharp IR Distance Sensor).
I started to wonder if the sensor was even turned on, so I measured the + and GND pins on AX0 of my BotBoard, and they do not appear to be carrying any current!!!
So, how do I turn on the power so my sensor can work in the first place? Anyone? The instructions on that page make is sound “Plug and Play” easy, but it sure isn’t working out that way!
Got it working. Forgot to put a jumper across the 5V supply for the A/D pins.
Just so this thread wasn’t a complete waste of time, I’ll go through what stumped me so others can read this later when they do a search…
** #1** Where the heck is my A/D pin???
ABB Pin Label<-> ATOM PRO Pin name
AX0 <-> P19
AX1 <-> P18
AX2 <-> P16
AX3 <-> P17
If your sensor seems to completely ignore things (just seems to spit out random #'s, or gradually climbs to 1023 or drops to 0, its probably off. Make sure you jump the 5V supply for the A/D bank.
I sure hope this helps some future roboteer avoid the 7 hour hair pulling session that my day-off became. Time for a beer!
The output of the sensor is analog, but it’s not linear. You would get the best results just measuring the value returned with the obstacle at the distance you want.