Ping Sensor Help
NWCCTV
Posts: 3,629
Not sure what I am doing here so bear with me. I am trying to test my Ping sensor to make sure it works. When I run the followimg program, the Debog screen shows cm 000 and in 000, but when I place an object in front of the sensor nothing changes. I double checked the pinning and it is correct.
' {$STAMP BS2sx}
' {$PBASIC 2.5}
·'
[noparse][[/noparse] Constants ]
·· '
#SELECT $STAMP
· #CASE BS2, BS2E
··· T2400······ CON···· 396
··· T9600······ CON···· 84
··· T19K2······ CON···· 32
··· Trigger···· CON···· 5·············· ' trigger pulse = 10 uS
··· Scale······ CON···· $200··········· ' raw x 2.00 = uS
· #CASE BS2SX, BS2P
··· T2400······ CON···· 1021
··· T9600······ CON···· 240
··· T19K2······ CON···· 110
··· Trigger···· CON···· 13
··· Scale······ CON···· $0CD··········· ' raw x 0.80 = uS
· #CASE BS2PE
··· T2400······ CON···· 396
··· T9600······ CON···· 84
··· T19K2······ CON···· 32
··· Trigger···· CON···· 5
··· Scale······ CON···· $1E1··········· ' raw x 1.88 = uS
#ENDSELECT
·· ' Conversion constants FOR room temperature measurements.
CmConstant CON 2260
InConstant CON 890
cmDistance VAR Word
inDistance VAR Word
time VAR Word
DO
PULSOUT 15, 5
PULSIN 15, 1, time
cmDistance = cmConstant ** time
inDistance = inConstant ** time
DEBUG HOME, DEC3 cmDistance, " cm"
DEBUG CR, DEC3 inDistance, " in"
PAUSE 100
LOOP
' {$STAMP BS2sx}
' {$PBASIC 2.5}
·'
[noparse][[/noparse] Constants ]
·· '
#SELECT $STAMP
· #CASE BS2, BS2E
··· T2400······ CON···· 396
··· T9600······ CON···· 84
··· T19K2······ CON···· 32
··· Trigger···· CON···· 5·············· ' trigger pulse = 10 uS
··· Scale······ CON···· $200··········· ' raw x 2.00 = uS
· #CASE BS2SX, BS2P
··· T2400······ CON···· 1021
··· T9600······ CON···· 240
··· T19K2······ CON···· 110
··· Trigger···· CON···· 13
··· Scale······ CON···· $0CD··········· ' raw x 0.80 = uS
· #CASE BS2PE
··· T2400······ CON···· 396
··· T9600······ CON···· 84
··· T19K2······ CON···· 32
··· Trigger···· CON···· 5
··· Scale······ CON···· $1E1··········· ' raw x 1.88 = uS
#ENDSELECT
·· ' Conversion constants FOR room temperature measurements.
CmConstant CON 2260
InConstant CON 890
cmDistance VAR Word
inDistance VAR Word
time VAR Word
DO
PULSOUT 15, 5
PULSIN 15, 1, time
cmDistance = cmConstant ** time
inDistance = inConstant ** time
DEBUG HOME, DEC3 cmDistance, " cm"
DEBUG CR, DEC3 inDistance, " in"
PAUSE 100
LOOP
Comments