Shop OBEX P1 Docs P2 Docs Learn Events
srf04 and basic stamp — Parallax Forums

srf04 and basic stamp

RobbanRobban Posts: 124
edited 2006-06-30 07:51 in BASIC Stamp
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

Comments

  • johnsroboticsjohnsrobotics Posts: 26
    edited 2006-06-29 13:17
    Robban,

    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.
  • RobbanRobban Posts: 124
    edited 2006-06-29 17:40
    oki...here it is

    ' {$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 :-)
  • RobbanRobban Posts: 124
    edited 2006-06-29 18:54
    tried to do as you said but then i´ll get ex....1200,1300....
    how do i get it to show 1,2...1,3 instead?
  • johnsroboticsjohnsrobotics Posts: 26
    edited 2006-06-30 01:11
    Ah. I see you're looking for a floating-point result.
    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.
  • johnsroboticsjohnsrobotics Posts: 26
    edited 2006-06-30 01:54
    OK. I found where I read the simple work around.
    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!
  • johnsroboticsjohnsrobotics Posts: 26
    edited 2006-06-30 02:59
    Also, if you want to get rid of those zeros in th output (I saw you had this problem in a different post), use this:

    main:
      GOSUB [b]sr_sonar_2[/b]
      DEBUG DEC wDist, CR
      PAUSE 200
      GOTO main
    
    



    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.
  • RobbanRobban Posts: 124
    edited 2006-06-30 07:51
    thanks for the lines..( with the zero:s)..worked perfect!

    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
Sign In or Register to comment.