PING using ping_demo.bas2 limits range to 5"
JimG
Posts: 84
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
//
·
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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
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
//
·
I included the code in the actual message.
Jim
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jim, K6JMG
www.spinochio.com
//
·
Thanks. I'll give them a call tomorrow and see what they have to say.
Jim, K6JMG
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jim, K6JMG
www.spinochio.com
//
·
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 Savage
Parallax Engineering
50 72 6F 6A 65 63 74 20 53 69 74 65
·
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
//
·
Chris,
Do you wan this bad one back so you can look it over?
Jim
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jim, K6JMG
www.spinochio.com
//
·
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
·