Shop OBEX P1 Docs P2 Docs Learn Events
PING using ping_demo.bas2 limits range to 5" — Parallax Forums

PING using ping_demo.bas2 limits range to 5"

JimGJimG Posts: 84
edited 2009-12-08 17:01 in Accessories
I have begun fiddling with the PING.· I have it stuck on a BOE that is mounted on a BoeBot.· The only code running is the ping_demo2.bas2.· The greatest distance I can read is 5" or 15cm.· I doesn't matter where I point the unit,·5" is the maximum range it will read.· The product description says, "Provides precise, non-contact distance measurements within a 2 cm to 3 m range."· ·What am I doing wrong.

Code is below:

' =========================================================================
'
'·· 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}
'
' =========================================================================

'
[noparse][[/noparse] 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.

'
[noparse][[/noparse] Revision History ]

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

'
[noparse][[/noparse] 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

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

'
[noparse][[/noparse] EEPROM Data ]

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

'
[noparse][[/noparse] 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

'
[noparse][[/noparse] 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

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jim, K6JMG

www.spinochio.com

//

·

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-11-30 22:40
    The demo program does work and the PING works, at least for other BoeBots. Is there some object in the "field of view" at a range of about 5"? Sometimes a table edge or part of the BoeBot can provide enough echo so that the PING will react to that.
  • FranklinFranklin Posts: 4,747
    edited 2009-11-30 23:44
    Also, if you click on "post reply" and then use the "Attachment Manager" to attach the actual program you are loading into your stamp that would help. You'd be suprised how many times there is a typo in the code.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • JimGJimG Posts: 84
    edited 2009-11-30 23:55
    Mike,

    I have the sensor out in the very last holes on the BOE board and it is mounted on the BoeBot as usual. The US sensors stick out beyond anything else on the board.

    I doesn't matter where I point the board, I get the same results. I have tried lifting it off the table entirely. I have pointed it in the air toward the ceiling. I am holding it by the back of the BoeBot so I am not interfering with the sensor. Doesn't seem to matter what I do I have the same issue. If I move in closer to the US sensor it acknowledges that there is something closer just nothing further way.

    Jim

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jim, K6JMG

    www.spinochio.com

    //

    ·
  • JimGJimG Posts: 84
    edited 2009-11-30 23:57
    Stephen,

    I included the code in the actual message.

    Jim

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jim, K6JMG

    www.spinochio.com

    //

    ·
  • Mike GreenMike Green Posts: 23,101
    edited 2009-12-01 00:01
    I suggest you call Parallax Tech Support. It's still possible there's something wrong with your setup, but it's hard to tell via a forum. There's nothing wrong with the demo program. As Franklin mentioned, it may be an error in your copy of the demo program if you entered it yourself. It's possible that a short on the PING could limit the drive current to the transmit transducer, but that's rare and probably wouldn't manifest with your symptoms.
  • JimGJimG Posts: 84
    edited 2009-12-01 00:32
    Mike,

    Thanks. I'll give them a call tomorrow and see what they have to say.

    Jim, K6JMG

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jim, K6JMG

    www.spinochio.com

    //

    ·
  • JimGJimG Posts: 84
    edited 2009-12-01 21:32
    This just shows, again, what a fine company Parallax is.

    I called the Tech Support Dept. spoke with Jack. Told him I had this PING sensor that I have had for a year or more but have just gotten it out of the bag to try. Explained the issue. He told me they had a few of these that got past QC some time back that manifested this exact problem. He is sending me a new one. No scrounging around for my old invoice, no argument about how long I have had it, just no Smile, in general. I sure wish they sold cars and washing machines!

    Now I remember why I buy Parallaxx stuff!

    Jim

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jim, K6JMG

    www.spinochio.com

    //

    ·
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-12-03 23:36
    Jim I am curious...had you mounted this PING))) Module to anything using the mounting holes and any screws? Just curious.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Parallax Engineering
    50 72 6F 6A 65 63 74 20 53 69 74 65
    ·
  • JimGJimG Posts: 84
    edited 2009-12-04 00:29
    Chris,

    The only time I used it was about a week, or so, ago and I stuck it on the BOE board that is sitting on top on one of my BoeBots. Didn't mount it to anything other than by the pins into a breadboard.

    Jim

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jim, K6JMG

    www.spinochio.com

    //

    ·
  • JimGJimG Posts: 84
    edited 2009-12-04 01:16
    The replacement came today and works perfect.

    Chris,

    Do you wan this bad one back so you can look it over?

    Jim

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jim, K6JMG

    www.spinochio.com

    //

    ·
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-12-08 17:01
    Jim,

    No, I only asked because I have seen cases where someone mounted the PING))) module via a screw through the mounting hole and the screw managed to short a trace causing the same malfunction. It seems that is not the case here and you are set. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Parallax Engineering
    50 72 6F 6A 65 63 74 20 53 69 74 65
    ·
Sign In or Register to comment.