srf04 and basic stamp
Robban
Posts: 124
Hi there!
Have a BS2 and a ultrasonic SRF04,i have downloaded the demoprogram and it works pretty good..
But now i am wondering how i instead of showing the range in cm change it to meters...
and how i make it to show...like· 1,2 meters.....0,8 meters
please help
Regards
Robert
Have a BS2 and a ultrasonic SRF04,i have downloaded the demoprogram and it works pretty good..
But now i am wondering how i instead of showing the range in cm change it to meters...
and how i make it to show...like· 1,2 meters.....0,8 meters
please help
Regards
Robert
Comments
If I remember correctly, the input value from the sensor is divided by 29 to get centimeters. This simplest way to get meters would be to multiply your centimeter result by 100 decimal to get a result in meters.
Another way to do it would be to divide the input value by .29.
Maybe if you submit your sample code we could help more.
' {$STAMP BS2}
wDist· VAR· Word
INIT· CON· 0
ECHO· CON· 1
' CONVERSION FACTORS:
'
' The PULSIN command returns the round-trip echo time in 2us units
' which is equivalent to the one-way trip time in 1us units.
'
' distance = (echo time) / (conversion factor)
'
' use 74 for inches······ (73.746us per 1 in)
' use 29 for centimeters· (29.033us per 1 cm)
'
convfac· CON· 29· ' use inches
'
main
· GOSUB sr_sonar
· DEBUG DEC wDist, CR
· PAUSE 200
· GOTO main
sr_sonar:
· PULSOUT INIT,5··· ' 10us init pulse
· PULSIN ECHO,1,wDist· ' measure echo time
· wDist=wDist/convfac· ' convert to inches
· PAUSE 10
· RETURN
sr_sonar_2:
· PULSOUT INIT,5··· ' 10us init pulse
· OUTPUT INIT··· ' dummy command (delay)
· RCTIME ECHO,1,wDist· ' measure echo time
· wDist=wDist/convfac· ' convert to inches
· PAUSE 10
· RETURN
the base program of SRF04 from this site..
BTW...nice guitar :-)
how do i get it to show 1,2...1,3 instead?
The BS2 only works with integer math. This means that decimal results are truncated.
I don't remember where I read it, but there is a simple work around for this...
I'm a little busy right now, I'll get back to you in a few hours with more info.
BTW, the guitar is just an avatar that these forums had available to choose.
See this segment of a Nuts and Volts column:
www.parallax.com/dl/docs/cols/nv/vol1/col/nv36.pdf
Read starting at page 401, and try to integrate this into your code.
If I just changed your code for you, it'd be no fun!
Report back on how you make out!
as your main loop. You can also get rid of the pause 200 in your main loop, and the pause 10 in your subroutines to get faster readings.
But still i dont get the stamp to set a tex "132 cm to 1,3 meters"....."675 cm to 0.7 meters"....
i hope you know what i mean,i don´t know how to explain it...
Post Edited (Robban) : 7/1/2006 3:58:47 PM GMT