Working Atom Pro/Ping )) code

Hi everyone. I recently purchased a scout kit and I’ve been having a ton of fun with it, but I’m getting really really iritated over one thing. The ping I ordered doesn’t seem to play nice with the Atom Pro. I need the Atom Pro for its eeprom size + ram, but I also need my Ping )) to make distance measurements. I know in the past the two haven’t been known to work well together and I was wondering if anyone can tell me what I’m doing wrong. Here is my code:

[code]pingValue var word
pingPort con p5

getping:
low pingport
pulsout pingport, 5
rctime pingport, 0, pingvalue
pingvalue = pingvalue / 2
debug [dec pingValue]
return[/code]

What ends up happening is it will read really big numbers when nothing is in its path, but if anything is within three feet of it, it goes down to 0. Its not at all gradual. It’s like 3 feet is the cutoff mark. I know my ping is functioning properly because i got it to work just fine with a BS2. I don’t know whats wrong. If anybody could please help me, I’d be so appreciative. Thanks!

P.S. I know I should’ve posted in the thread with the sample code for the ping, but it seemed as though it had been abandoned, plus nobody had established any solid answers.

Ok, after playing around for quite some time, I answered my own question. Here’s my code:

[code]pingValue var word
pingPort con p5

getping:
low pingport
high pingport
pulsin pingport, 0, pingvalue
low pingport
pingvalue = pingvalue / 2
debug [dec pingValue]
return[/code]

It works perfect and is very reliable. For my means, I don’t need to convert it to centimeters but if anyone wants to work out the conversion, more power to them :smiley:
Thanks,
Patrick

I tried this code on a Basic Atom Pro / BB II / Ping:

pingValue var word
pingPort con p12

main
gosub getping
debug [13]
pause 500
goto main

getping:
low pingport
high pingport
pulsin pingport, 0, pingvalue
low pingport
pingvalue = pingvalue / 2
debug [dec pingValue]
return

I also tried it with "pulsin pingport, 1, pingvalue and it still didn’t work.

Any ideas? The sensor strobes like it’s taking a measurement but I always get a “0” value back. No matter how close or far from the sensor, it’s always 0.

Thanks in advance,

Brian

I tested the program here.

lynxmotion.net/viewtopic.php?t=4359

I ran this exact code on my BB II / BA Pro 28:

Notice I did change the serial output to debug statements, but nothing else changed. I even used your pin (P4) for my test.

All I get is the “Timeout, sensor is not working” message, but the sensor does strobe the green light exactly like it is supposed to do.

Try with serout s_out. Debug mode may screw up timing…

Kurt

Just to make sure nothing changed lately I grabbed a Ping and tested it. I used 8.0.1.7 because it’s what was installed last. When running you click on the terminal1 tab, change the baud rate to 9600, click connect, and viola the number in the terminal window is the distance in inches. I get a minimum of 1" and a maximum of 129". If this doesn’t work for you the ping may be defective. Other things that could effect it is the battery used on the system could be low. The atom could be suspect too, but you have tried it on different I/O pins so I dunno… Which IDE are you using? It’s working here.

I tested it too, since I have 8.0.1.8 installed.
I was unable (as most people seem to be) to get the code to work with debug, however the code worked just fine using serouts instead.

You guys nailed it. It was the debugger.

I bet that also explains why my “Serout/Serin” commands were falling on deaf ears even though the oscilloscope showed what appears to be perfectly formed serial line data.

Thanks guys! Greatly appreciated. I’ll get up to speed on this stuff yet!

What would be different in this code for
MINI ABB
Basic Atom 28 (not pro)
sensor at pin 8.

The sensor shrobs, and the terminal reads
"timeout sensor is not working)
this is my code:

[code]wdist var word

main:
low p8
pulsout p8, 5
input p8
pulsin p8, 0, toolong, 40000, wdist
wdist = wdist / 148 ;convert for inches
serout s_out, i9600, "Distance: ", sdec wdist, 13] ;display result in terminal
'debug "Distance: ", dec wdist, 13, 10]
goto main

toolong: ; if the program gets here the sensor is not functioning, or wired wrong
serout s_out, i9600, “Timeout, sensor is not working”, 13]
'debug “Timeout, sensor is not working”, 13]
goto main [/code]