Rangefinding project (a little help required)

johncameron

New Member
hello all,

I will start by saying this is my first post in your (from reading so far) quite simply brilliant forum, and i hope to stick about and learn alot from everybody here.

however i shall get to the reason i am here.

as part of an ongoing project, i am attempting to use a sharp IR sensor, PICAXE 18m2 and a serial OLED display to actively display range at a refresh rate of around 2hz

I did a reasonable amount of pbasic programming in high school, but that was a few years back and my code her slipped baddly :/

here is my equipment list:

sensor: http://www.ebay.co.uk/itm/High-Sensitivity-Sharp-IR-Sensor-GP2D12-Arduino-Compatible?item=280850827766&cmd=ViewItem&_trksid=p5197.m7&_trkparms=algo=LVI&itu=UCI&otn=3&po=LVI&ps=63&clkid=8151708283767129697#ht_5075wt_1163

main board: http://www.picaxe.com/Hardware/Teaching-Systems/PICAXE-Experimenter-Board/

display: http://www.picaxe.com/Hardware/Add-on-Modules/Budget-Serial-OLED-Module/



my current setup is such that, everything is connected up, and i am recieving the default message from the display "serial oled www.picaxe.com"

however, i cannot seem to get anything else to output, and am even unsure if i can correctly reading the adc.

its been a long time guys, and i need this board to be working by next friday at the very latest, you have no idea how much i would appreciate your help

John.
 

nick12ab

Senior Member
Welcome to the forum.

What is your circuit? Have you programmed an intermediate PICAXE (or the AXE133 PICAXE itself) correctly to interface with this sensor using the readadc command?
 

johncameron

New Member
Hi Nick12ab, and thank you,

i honestly cannot be sure of my code at all, the default voltage range of the adc is is 0-5v? which should be fine for the time being (you can use fvrsetup to change it correct?) so i am just running on readadc 2, B0 (read the data move to b0? )

i honestly cannot even remember if that is correct or not

here is a picture of how things are setup WP_000381.jpg
 
Last edited:

nick12ab

Senior Member
Hi Nick12ab, and thank you,

i honestly cannot be sure of my code at all, the default voltage range of the adc is is 0-5v? which should be fine for the time being (you can use fvrsetup to change it correct?) so i am just running on readadc 2, B0 (read the data move to b0? )

i honestly cannot even remember if that is correct or not

here is a picture of how things are setup http://imageshack.us/photo/my-images/24/wp000381.jpg/
DO you mind using the forum attachments feature, ImageShack is filtered.
 

hippy

Technical Support
Staff member
my current setup is such that, everything is connected up, and i am recieving the default message from the display "serial oled www.picaxe.com"

however, i cannot seem to get anything else to output, and am even unsure if i can correctly reading the adc.
First step is to split the project into two halves; write some code which just gets the OLED display working, and then write some code which uses SERTXD or DEBUG commands rather than the display to get the range sensor working.

When you are confident you have both working, update the range sensor code to output to the OLED.
 

johncameron

New Member
ok, that sounds like a solid plan, after a little playing this code:
main: Pause 500
serout B.7,n2400,(254,1)
pause 30
serout B.7,N2400,(254,128)
serout B.7,N2400,("hello")
end

gets me "hello" on the display, so on that front we are good to go.

now for the adc code i am pretty stumped so all help is appreciated, currently i have the +5 and 0v connected to power, and the "data" line connected to c2 is this correct?
 

johncameron

New Member
Hi E,

i have to be honest haha, i am reading though forum posts on this sensor, and getting more confused by the second, reading though its data sheet -- http://www.sharpsma.com/webfm_send/1203
"pulse cycle duration" ? what on earth does that correspond too in real life terms?

honestly, can i just use the readadc command? or is this going to be much much more complicated?
 

Technical

Technical Support
Staff member
Yes, Ec's link is a bit misleading as that was code for the GP2D02

If you really have the '12' then readadc should work - looks like you are using pin C.2 so

Code:
Pause 500
    serout B.7,n2400,(254,1)
    pause 30
 
 main:
    readadc C.2,b0
    bintoascii b0,b1,b2,b3
    serout B.7,N2400,(254,128)
    serout B.7,N2400,("value=",b1,b2,b3)
    pause 100
    goto main
 
Last edited:

johncameron

New Member
definitly the 12,

connected to c.2 when i try to throw in your code there its giving me
serout B.7,N2400,("value"=b1,b2,b3)
^

Error: Syntax error in this line!

thank you all for the super quick replys too! genuinly amazing!
 

hippy

Technical Support
Staff member
serout B.7,N2400,("value"=b1,b2,b3)
^
Error: Syntax error in this line!
That's not exactly how Technical specified it, you've got the " in the wrong place and lost a comma ...

serout B.7,N2400,("value=",b1,b2,b3)
 

johncameron

New Member
ok, so i removed the "value" and now it is actively reporting too the screen, however, i am only getting either 0, or a value between 63 and 65, nothing inbetween,

does anybody know how sensitive these sensors are too their supply voltage (since i am running all this from 3AA's)

edit -- sorry hippy my bad, the value is now back in, as was originally posted, and its reading that on the screen, however, still reading either 0 (when i unplug) or 65 when connected
 

eclectic

Moderator
It may not be directly relevant but

1. Are the batteries "full"?
2. Have you included the 10 uF capacitor, as recommended in the datasheet?

e
 

johncameron

New Member
batteries are brand new Duracell's,

i do not have a capacitor, but i didn't think it would be completely necessary...or is it? :S

i dont have a multimeter at hand right now, to test the sensor, either, in case it is faulty
 

hippy

Technical Support
Staff member
reading either 0 (when i unplug) or 65 when connected
Perhaps put a volt meter on the sensor output and see what that shows. It should range from about 0.5V (80cm) to 2.5V (10cm).

Connect a pot across +V/0V and read its wiper into the ADC, see if that shows 0 to 255

Perhaps check your wiring, post a circuit, and even a photograph of your set up.
 

johncameron

New Member
we are working!!

voltage range is 1.6-3.55v (bit strange)

so how would i limit that into the code?, so the adc only reads between those values,? (1.6v =0cm) (3.55= about 20cm)
 
Last edited:

hippy

Technical Support
Staff member
we are working!!
Excellent. And go on, tell us what was wrong because it's useful to know. And nothing to be embarrassed about as everyone here has ( or will ) do something D'Oh! at least once, and frequently often. It maybe even part of the 'rights of passage' :)


voltage range is 1.6-3.55v (bit strange)
It does seem to be +1V above what would be expected across the board.

so how would i limit that into the code?, so the adc only reads between those values,? (1.6v =0cm) (3.55= about 20cm)
It's all about 'similar triangles', mapping one onto another. Ultimately 'y=mx+c' where x is the voltage in and y is distance but I can't off-hand remember how to calculate m or c.
 

johncameron

New Member
It was the wiring seemed slightly counter intuitive, the black (0V i though) is now connected to c.2, with the red into +vcc and the brown into the 0v rail

i tried every other combination after that and the current one is the only working one.


the voltage does seem off....and its strange, the voltage goes from 3.55--to--1.6--back to 3.55, over a range of 8cm, to 20cm, to 80cm, really very strange...

not entirly sure how to tackle getting that sorted out....however, i am happy it is "working" haha,



"similar triangles" ? so calibrating it so say a +0.1 volt jump = 1cm so it is reporting an accurate range? anybody got any help on that, because i genuinly dont have a clue :p
 
Top