problem understanding ping sensor
justin weber
Posts: 36
It seems that the ping sensor likes to return 5 alot. Here is my code:
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
VAR
long range
OBJ
tv : "tv_text"
ping : "Ping"
PUB main
tv.start(12)
repeat
range := ping.Inches(0)
tv.dec(range)
waitcnt(clkfreq / 10 + cnt)
tv.out($0d)
hardware-wise I have the vcc to 5V on the propeller starter board and gnd to the vss. SIG is connected to p0 with a 1k resistor. This program should be returning a reading in inches, but it displays 5 ALOT and other values randomly, but always returns to displaying 5's. I don't know if the demo from the exchange works, because I don't have a LED debug display, so i'm sending it to tv term instead.
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
VAR
long range
OBJ
tv : "tv_text"
ping : "Ping"
PUB main
tv.start(12)
repeat
range := ping.Inches(0)
tv.dec(range)
waitcnt(clkfreq / 10 + cnt)
tv.out($0d)
hardware-wise I have the vcc to 5V on the propeller starter board and gnd to the vss. SIG is connected to p0 with a 1k resistor. This program should be returning a reading in inches, but it displays 5 ALOT and other values randomly, but always returns to displaying 5's. I don't know if the demo from the exchange works, because I don't have a LED debug display, so i'm sending it to tv term instead.
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
I had problems for the longest time because I was supplying the the protoboard with 5V (thinking that this was sufficient as the prob runs on 5V), but the actual power requirement for the board is 6-9V. Not realizing this took me down the confusing path of debugging code that wasn't buggy.