Shop OBEX P1 Docs P2 Docs Learn Events
SRF04 as a backwarner — Parallax Forums

SRF04 as a backwarner

RobbanRobban Posts: 124
edited 2006-07-02 18:37 in BASIC Stamp
Hi!

I wonder if anyone have tried to use the SRF04 as a backwarner.?

or if someone has tried to connect a ultrasonic sensor from a carsaler and then connected it to the stamp?



' {$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 cm


'
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 cm
· 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 cm
· PAUSE 10
· RETURN

i have tried the program "shown above" and it works pretty godd but sometimes the value(distance) is shown as "0"
ex

23
24
23
0
0
24
23

my question is WHY do i get the "zero:s"?




Post Edited (Robban) : 6/29/2006 6:31:12 PM GMT

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-06-29 18:08
    There is no program in your post.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • RobbanRobban Posts: 124
    edited 2006-07-01 21:03
    now there is
  • TiboTibo Posts: 81
    edited 2006-07-02 18:37
    Hi, i beleive this is because you dont give the sensor the minimum time to do the measure, this delay is implemented in the sr_sonar_2 procedure. ++
Sign In or Register to comment.