Shop OBEX P1 Docs P2 Docs Learn Events
Ultrasonic sensir using Ping_Demo.BS2 — Parallax Forums

Ultrasonic sensir using Ping_Demo.BS2

mdjetmdjet Posts: 8
edited 2010-12-20 18:29 in Accessories
All my numbers are 0 in the Debug Terminal? What did I do wrong, please HELP.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-12-20 16:35
    There's no way to tell you what's wrong without more information from you.

    The PING does work and the demo program does work, at least for others. The question is "what's different about what you have from what others have?". Maybe you entered the program incorrectly. Maybe you wired incorrectly whatever setup you're using. Maybe your batteries or AC adapter can't supply enough power (possible, but not likely).

    At the very least, provide a copy of your program (use the Attachment Manager) and a diagram or detailed description of what you have and how it's connected.
  • mdjetmdjet Posts: 8
    edited 2010-12-20 17:08
    I just use the demo code with my ultrasonic sensor http://www.parallax.com/Store/Sensors/ObjectDetection/tabid/176/CategoryID/51/List/0/Level/a/ProductID/92/Default.aspx?SortField=ProductName%2cProductName :

    ' ================================================== =======================
    '
    '·· File....... Ping_Demo.BS2
    '·· Purpose.... Demo Code for Parallax Ping Sonar Sensor
    '·· Author..... Jon Williams -- Parallax, Inc.
    '·· E-mail..... jwilliams@parallax.com
    '·· Started....
    '·· Updated.... 08 JUN 2005
    '
    '·· {$STAMP BS2}
    '·· {$PBASIC 2.5}
    '
    ' ================================================== =======================

    '
    [ Program Description ]
    '
    ' This program demonstrates the use of the Parallax Ping Sonar sensor and
    ' converting the raw measurement to English (inches) and Metric (cm) units.
    '
    ' Sonar Math:
    '
    ' At sea level sound travels through air at 1130 feet per second.· This
    ' equates to 1 inch in 73.746 uS, or 1 cm in 29.034 uS).
    '
    ' Since the Ping sensor measures the time required for the sound wave to
    ' travel from the sensor and back.· The result -- after conversion to
    ' microseconds for the BASIC Stamp module in use -- is divided by two to
    ' remove the return portion of the echo pulse.· The final raw result is
    ' the duration from the front of the sensor to the target in microseconds.

    '
    [ Revision History ]

    '
    [ I/O Definitions ]
    Ping··········· PIN···· 15

    '
    [ Constants ]
    #SELECT $STAMP
    · #CASE BS2, BS2E
    ··· Trigger···· CON···· 5······················ ' trigger pulse = 10 uS
    ··· Scale······ CON···· $200··················· ' raw x 2.00 = uS
    · #CASE BS2SX, BS2P, BS2PX
    ··· Trigger···· CON···· 13
    ··· Scale······ CON···· $0CD··················· ' raw x 0.80 = uS
    · #CASE BS2PE
    ··· Trigger···· CON···· 5
    ··· Scale······ CON···· $1E1··················· ' raw x 1.88 = uS
    #ENDSELECT
    RawToIn········ CON···· 889···················· ' 1 / 73.746 (with **)
    RawToCm········ CON···· 2257··················· ' 1 / 29.034 (with **)
    IsHigh········· CON···· 1······················ ' for PULSOUT
    IsLow·········· CON···· 0

    '
    [ Variables ]
    rawDist········ VAR···· Word··················· ' raw measurement
    inches········· VAR···· Word
    cm············· VAR···· Word

    '
    [ EEPROM Data ]

    '
    [ Initialization ]
    Reset:
    · DEBUG CLS,··································· ' setup report screen
    ······· "Parallax Ping Sonar· ", CR,
    ······· "=====================", CR,
    ······· CR,
    ······· "Time (uS).....······ ", CR,
    ······· "Inches........······ ", CR,
    ······· "Centimeters...······ "

    '
    [ Program Code ]
    Main:
    · DO
    ··· GOSUB Get_Sonar···························· ' get sensor value
    ··· inches = rawDist ** RawToIn················ ' convert to inches
    ··· cm = rawDist ** RawToCm···················· ' convert to centimeters
    ··· DEBUG CRSRXY, 15, 3,······················· ' update report screen
    ········· DEC rawDist, CLREOL,
    ········· CRSRXY, 15, 4,
    ········· DEC inches, CLREOL,
    ········· CRSRXY, 15, 5,
    ········· DEC cm, CLREOL
    ··· PAUSE 100
    · LOOP
    · END

    '
    [ Subroutines ]
    ' This subroutine triggers the Ping sonar sensor and measures
    ' the echo pulse.· The raw value from the sensor is converted to
    ' microseconds based on the Stamp module in use.· This value is
    ' divided by two to remove the return trip -- the result value is
    ' the distance from the sensor to the target in microseconds.
    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
  • Mike GreenMike Green Posts: 23,101
    edited 2010-12-20 18:26
    You've not supplied any information about what Stamp and board you're using and how you have things hooked up. What power source you're using is important.
  • Mike GreenMike Green Posts: 23,101
    edited 2010-12-20 18:29
    You've not supplied any information about what Stamp and board you're using and how you have things hooked up. What power source you're using is important.

    These forums work through give and take. You pose a question, someone else asks for information. You supply the information requested, then you either get more requests for information or you get advice or both and the exchange of information continues.
Sign In or Register to comment.