Shop OBEX P1 Docs P2 Docs Learn Events
help ping and distance measurement — Parallax Forums

help ping and distance measurement

fred1456fred1456 Posts: 13
edited 2007-07-08 17:12 in BASIC Stamp
i have bough a new basic stamp 2 and·a ping)) sensor. The ping work but not correctly, it detect object at 15cm (about 6 inches), but not far of this distance.
Technical spécifications tell the ping detect objects 2cm to 3m.

the routine bellow show me numbers between 90(near) and 422, (15cm to infinite)
(sorry my english is poor)

could you tell me why it don't work far than 15cm ?

the routine

' {$STAMP BS2}
' {$PBASIC 2.5}

x VAR Word
Get_Sonar:
LOW 15
PULSOUT 15, 5
PULSIN 15,1, x
DEBUG DEC ? x
PAUSE 200
GOTO get_sonar

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2007-07-06 11:53
    Fred -

    Perhaps you should start with the sample programs, which can be found at the link below, then go on from there, after you understand them:

    http://www.parallax.com/detail.asp?product_id=28015

    Regards,

    Bruce Bates
  • D FaustD Faust Posts: 608
    edited 2007-07-06 21:43
    Bruce,
    If you look at the example code, the code posted has the same routine for getting sonar.
    Fred,
    Are you sure tha the wait is long enough to eliminate echoes? ( That is the the main part of your code that is different. )

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    D Faust
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-07-06 22:30
    Actually, the routine posted has some conversion being done.· The code above is not displaying the data correctly either.
    Get_Sonar:
      Ping = IsLow                                  ' make trigger 0-1-0
      PULSOUT Ping, Trigger                         ' activate sensor
      PULSIN  Ping, IsHigh, rawDist                 ' measure echo pulse
      rawDist = rawDist */ Scale                    ' convert to uS
      rawDist = rawDist / 2                         ' remove return trip
      RETURN
    

        inches = rawDist ** RawToIn                 ' convert to inches
        cm = rawDist ** RawToCm                     ' convert to centimeters
        DEBUG DEC inches, CLREOL, CR, DEC cm, CLREOL
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • D FaustD Faust Posts: 608
    edited 2007-07-07 00:44
    Chris, what i meant by it was the same as the example code is that it uses the same code to get the raw distance from the PING (that is correct right?). Yes, I know that there is conversion being done, but I think that Fred was just trying to get a distance reading farther than the 442 (15 cm) that he recieved. (Fred, correct me if I am wrong) So, the conversions aren't necessary. What is wrong with displaying the raw value?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    D Faust
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-07-08 00:50
    Actually, I thought for some reason that the formatter would cause an issue with using the ? to display the variable. The formatter (DEC) isn't needed to do that. My apologies. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • fred1456fred1456 Posts: 13
    edited 2007-07-08 09:38
    in fact, the detector detect anything far than 15cm and that the probl
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-07-08 17:12
    Please contact Tech Support by e-mail at support@parallax.com or tomorrow by phone. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
Sign In or Register to comment.