I am new to this form and the basic atom. I have used the the basic stamp and the ping sonar with good results but whatever I do I can’t get the ping to work with the basic atom pro. Some example code or a subroutine to read the sonar would be helpful.
My next code project is to write a routine to read the PING sensor. I have one on the turret of my rover W.A.L.T.E.R. Hopefully I can post some code late next week or the following week.
Yes, W.A.L.T.E.R. is my octagonal shaped two wheel rover. There is an Octabot topic and a W.A.L.T.E.R. topic in the Rovers forum. The Octabot topic has the earliest stages of W.A.L.T.E.R. and the other topic has the current stages of development.
I have a PING sensor on W.A.L.T.E.R.'s turret but it is not yet active. I hope to get code for that in and working within a week or two.
I have been working with the PING sensor and my Basic ATOM on W.A.L.T.E.R. I am starting to get reasonable readings back from it. I have been analyzing the Basic STAMP PING code from the Parallax documentation and I think I am finally understanding how the PING works.
I still need to do some serious distance checking to be sure my readings are as close as they can be to the actual distance. It is looking quite good as I do rough distance checks.
Here is the code I have so far:
[code]’
’ PING Ultrasonic Sonar Ranger
’
PING con p15 ’ PING Ultrasonic Ranger I/O pin
PING_Trigger con 5 ; Trigger pulse length in uS
PING_Threshld con 25 ’ PING detection threshold
’
’ PING Ultrasonic Sonar Ranger
’
PING_Detected var bit ’ 1 = Detected, 0 = Nothing detected
PING_Distance var word ’ PING object detection distance
PING_Echo var word ’ PING echo duration
PING_Scale var long ’ Divisor for distance units conversion
’ Check the Ultrasonic Sonar Ranger on the Pan/Tilt Turret
Read_PING
’ if makenoise then
’ sound speaker,[dur\note13, dur\note14, dur\note15, dur\note16]
’ endif
’
’ Start the PING detection cycle
low PING
' Send the PING sensor pulse
PULSOUT PING, PING_Trigger
' Read the pulse echo return time
PULSIN PING, 1, PING_Echo
' Create the divisor for cm distance conversion
PING_Scale.highword = 0
PING_Scale.lowword = 2251 ' 0.03434 * 65535 cm conversion factor
result = PING_Echo */ PING_Scale
PING_Distance = result / 2
return[/code]
The makenoise variable is just a switch I use to turn sound on and off so the robot can go into and out of “stealth” mode.
I am not sure changing PING_Trigger to 10 is the only required change to convert my code to the PRO.
I am pretty happy with the way this code is working so far, since I had to figure out how the BS2 code worked before I could make mine work properly. I will be fine tuning the code a bit, but there should not be any major changes now.
Hi SpaceJunk, have you tried this code to see if it works? You could simply comment out the noise functions. Depending on which IDE Linuxguy is using you would need to update the durations as the new IDE for the atom is in Microseconds and the Pro IDE is is milliseconds.
The code looks good to me, but I don’t have the Ping sensor to try it with.
On the Pro you could alternatively do something like define PING_RESULT as a floating point and try something like:
I am using the latest v5.3.0.1 IDE for the Basic ATOM and I have the v8.0.0 IDE for the PRO. Isn’t it the other way around with the PRO having better resolution and being in uS?
The code is giving what looks to be reasonable results for the rough checks I have done so far.
My code should at least give a good starting point. Even though I have not fine tuned it yet, I think the returned results are usable as is.
I guess I will have to wait until I can get an Atom PRO starter kit to do more work on my code since I have hit the limit of what I can stuff into a Basic Atom. I have so many things I want to do, that I have to decide which thing I want to do first with limited funds.
Evolution is sending me 4 HS475 servos, so if I get two more I can fill out my BRAT. If I can get two more servos and an Atom PRO starter kit, that would give me two microcontroller brains. I could switch the PRO between W.A.L.T.E.R. and the BRAT (still unamed) when I want to work on each one.
Then I can convert all my current code to the Atom PRO and have versions for both microcontrollers. Increased code base for the Atom PRO will be a good thing.
Yes I did try it out but I have no idea what’s wrong. I am new to the basic atom so it is tough for me. I have used a basic stamp before and I am good at coding with it. Floating point math!?!?!? I can hardly do regular atom math!
All it seems to do is transmit “hello world” over and over again.
This is what I can come up with:
The light on the sonar is flashing. My power supply is stable but this leads me to think the atom pro is reseting. The sonar is connected properly and has power. I have tried 3 diffrent modules but none work. The battery is charged. My ocilliscope tells me the supply isn’t dropping.
While I don’t have this device I did find that program did want to reset over and over again…
So I started a quick debug process. If you simply add additional Serout command after each main statement in the ping function you find that it appears to rest the processor during the pulsin command. Trying the other form of the command syntax caused the code to stop resetting. I am not sure if it is returning anything valid… But you might try changing the function to something like:
[code]PING var word ’ PING Ultrasonic Ranger I/O pin
Read_PING[PING]
’ Start the PING detection cycle
low PING
’ Send the PING sensor pulse
PULSOUT PING, PING_Trigger
’ Read the pulse echo return time
PULSIN PING, 1, RP_TimeOut, 1, PING_Echo
’ Create the divisor for cm distance conversion
PING_Scale.highword = 0
PING_Scale.lowword = 2251 ’ 0.03434 * 65535 cm conversion factor
I looked at the basic micro forum and it looks like there may be problems with the pulsin command. My guess is that you could work around this with the RCTime command. I don’t have the time right now to make this work properly, but you might try something like:
...
low Ping
PULSOUT PING, PING_Trigger
RCTIME PING, 1, PING_Echo ' Wait for the signal to go high
if PING_ECH > SomeTimetout then
goto Error
endif
RCTIME PING, 0, PING_Echo ' Wait for it to go low again - this is our time
...
' Create the divisor...
Thank you very much. It works perfectly. It returns accurate numbers right up to 1cm!
One thing. How does the subroutine take a value on the atom pro? I have used this feture on the SX chip in SX/B. Is it like SX/B where you can use any var as the output?
Here is the code I used:
'
' PING Ultrasonic Sonar Ranger
'
PING_Trigger con 5 ; Trigger pulse length in uS
PING_Threshld con 25 ' PING detection threshold
MyDistance var word
LastDistance var word
LastDistance = 0xffff
serout s_out, i9600, "Hello World", 13, 10]
main
gosub Read_PING[15], MyDistance
if MyDistance <> LastDistance then
serout s_out, i9600, "Distance: ", sdec MyDistance, 13, 10]
LastDistance = MyDistance
endif
pause 250
goto main
'
' PING Ultrasonic Sonar Ranger
'
PING_Distance var word ' PING object detection distance
PING_Echo var word ' PING echo duration
PING_Scale var long ' Divisor for distance units conversion
' Check the Ultrasonic Sonar Ranger on the Pan/Tilt Turret
PING var byte ' PING Ultrasonic Ranger I/O pin
Read_PING[PING]
' Start the PING detection cycle
low Ping
PULSOUT PING, PING_Trigger
RCTIME PING, 1, PING_Echo ' Wait for the signal to go high
if PING_ECHO > 65000 then
goto Error
endif
RCTIME PING, 0, PING_Echo ' Wait for it to go low again - this is our time
' Create the divisor for cm distance conversion
PING_Scale.highword = 0
PING_Scale.lowword = 2251 ' 0.03434 * 65535 cm conversion factor
PING_Distance = (PING_Echo */ PING_Scale ) / 2
return PING_DISTANCE
ERROR
goto Main
Thanks again, I don’t know how long I’ve been working on this. This is the first code that works.
The new Atom PRO IDE does allow parameters to be passed to functions, which I used in this function. It is very primitive in that it does not do any type checking or the like. Also the Parameters are still global variables, so the call (gosub) simply moves the values into the variables… I believe I read somewhere on this forum that new IDE for the Atom may also support this.
One quick look at the code, I see that at your Error lable you do a goto main. This will leave the return address on the stack, which could cause problems. You should instead either slightly restructure the code such that you return a value like 0xffff or use the exception command.