Shop OBEX P1 Docs P2 Docs Learn Events
Help! Using PING Sensors with ARobot — Parallax Forums

Help! Using PING Sensors with ARobot

SandgroperSandgroper Posts: 62
edited 2007-11-06 12:10 in Robotics
Can anyone help me with this one?

I've just hooked up a PING sensor to my ARobot (BS2e chip). The problem is, I'm ony getting a "0" reading from PULSIN.

The PING is connected via the ARobot's expansion port to Gnd, +5v and P6 (pin 11) respectively.··The PING's LED lights up when the ARobot is switched on.· The batteries have been freshly charged and are putting out approximately. 10.6 v.· There is + 4.96v to the 5v pin, and·approximately 30 ma running through the sensor.

I've tested Pulsout on P6 with a LED and transistor circuit and it seems to be OK.· The ARobot's 4.7k SIP resistor "RN1" is intact and in·place.· The BS2e is correctly seated.· The sensor is mounted 150 mm above the desktop and is unobstructed for approximately 400 mm.

I'm using the demo code that came with the sensor but have modified it for P6 (pin 11) instead of P15, and included a debug to check Pulsin.· The details are listed below.

What am I doing wrong?


' =========================================================================
'
' File....... Ping_Demo.BS2
' Purpose.... Demo Code for Parallax PING))) Sonar Sensor
' Author..... Parallax, Inc.
' E-mail..... support@parallax.com
' Started....
' Updated.... 08 JUN 2005
'
' {$STAMP BS2E}
' {$PBASIC 2.5}
' {$PORT COM1}
'
' =========================================================================
'
[noparse][[/noparse] Program Description ]
'
' This program demonstrates the use of the Parallax PING))) sensor and then
' 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] I/O Definitions ]
Ping PIN 6
'
[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] Initialization ]
Reset:
·DEBUG CLS,
·"Parallax PING))) Sonar", CR, ' setup report screen
·"======================", CR,
·CR,
·"Time (uS)..... ", CR,
·"Inches........ ", CR,
·"Centimeters... "
'
[noparse][[/noparse] Program Code ]
Main:
· DEBUG DEC ? trigger,CR
· DEBUG DEC ? scale,CR
·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
··DEC5 rawDist, CLREOL,
··· CRSRXY, 15, 4,
··DEC5 inches, CLREOL,
··· CRSRXY, 15, 5,
··DEC5 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
· 'DEBUG DEC ? rawdist,CR
···rawDist = rawDist */ Scale ' convert to uS
·rawDist = rawDist / 2 ' remove return trip
· RETURN

Comments

  • ZootZoot Posts: 2,227
    edited 2007-11-04 21:28
    The LED on the Ping should not light up just because you apply power to your Stamp and electronics -- the LED on the Ping should only light up when the Ping is actually taking a measurement. I know you checked the pin with an LED, but if the above is true, then it sounds like the pin is going HIGH (and staying that way?) on power-up (the demo Ping code you're using takes the pin low before the pulsin, so not sure what's up with that).
    Somebody said...
    The ARobot's 4.7k SIP resistor "RN1" is intact and in place.

    I don't know the ARobot very well -- is this a series resistor, or a pullup, or?? The Ping itself has a series resistor already on on-board, so you don't need external protection for your Stamp pin.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST
  • SandgroperSandgroper Posts: 62
    edited 2007-11-05 11:51
    Zoot, you're a genius.· You hit the nail right on the head!··· idea.gif

    The ARobot has two·SIP resistors, RN1 and RN2.· RN1 is for·pins P0 to P8.· RN2 is pins·P9 to P15.··I snipped·off the lead on RN1 that corresponds to P6.· Bingo, instant result.····

    Thanks, Zoot!· You've made my day.
  • GrievousfishGrievousfish Posts: 54
    edited 2007-11-05 16:32
    Sandgroper - get used to snipping those resistor pins. I have an ARobot as well and have found that I have had to snip a quite a few of those pins.
  • ZootZoot Posts: 2,227
    edited 2007-11-05 17:35
    Glad it worked out smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST
  • SandgroperSandgroper Posts: 62
    edited 2007-11-06 12:10
    Grievousfish, I saw your ARobot while I was researching the problem.· When I spotted its PINGs I thought "Aha! It can be done... ". So thanks for your previous post!
Sign In or Register to comment.