Let's Make Robots!

Getting Parallax Ping))) to work with a PICAXE 28x1 board

Make your Ping))) sonar work!

So you've made your first robot with an infra red sensor and decide to upgrade it to ultra sonic. after a trip to Radioshack you look at the sensor you bought and realize it only has 3 pins instead of 4. That's because the signal pin on your Parallax Ping))) serves as both an input and output. How economical! The only problem is, as both input and output, where the hell do you hook it up, and how?

 

The pixaxe 28x1 and most other picaxe chips have some pins that can serve as both digital input and output at the same time. In my case I use input pin 0. (pin 11)

28x1

Hook up your Ping)))'s signal to the pin shown above. Just like how it is shown in the image below...

ping28x1connect.jpg

 

Now that your signal is hooked up to "in 0", You can make this pin both input or output at any time. Since by default, in 0 is an input pin you must call either:

HIGH PORTC 0 or LOW PORTC 0 to make in 0 an output pin.

Why do we care about input/output? It's because the sensor needs your permission to send out an ultrasonic pulse, like a bat. You give it permission by having the board send your sonar a short signal on pin 'in 0'. but you cant "send" stuff through this pin if it currently an input pin. so first we make it an output pin and send the signal like so...

LOW PORTC 0 

HIGH PORTC 0

PAUSE 1

LOW PORTC 0

 

notice the signal stays on HIGH for 1 millisecond, according to Ping)) documentation, this is enough time for the sonar to confirm that it needs to send out its ultrasonic pulse. Normally there is a command called PULSOUT that does the low-high-low for us, but sadly this cannot work on 28x1's pins 11 through 18. Which is why getting the Parallax Ping))) to work is a pain since it has only 1 pin for both input and output.

Cool so the pulse is send and is out there in the world bouncing off nearby objects...

now we need to convert pin in 0 back to input to receive the ultrasonic waves we sent out. Do this by calling...

LET DIRSC = %00000000

This resets all input pins back to... input pins! Now all we need to do is determine the time it takes before our waves make their round trip back to the sonar. The time it takes these waves come back determines the distance of the object ahead.

PULSIN 0, 1, W0  '(make sure the second parameter is 1!)

 when this command has been executed we now have our distance stored in W0!

 


Troubleshooting:

If you get bad readings heres a couple of thigs to check:

if your range seems too short (in my case W0 never had a value over 84), it means that your sonar is somehow detecting residual waves from the pulse it just sent before the waves make their round trip... or residual waves from the previous pulse it sent out form the last iteration. Try placing a cloth over the sonar or a thin layer of packaging foam like this...

pack2.jpg ------> foamyeyes2.jpg

then see if there is improvement.

 

if you get no readings..

1. check your pin connections

2. make sure you high state stays on long enough (1 millisecond) for the sonar to confirm it needs to send out a wave pulse.

3. see if you pulsins are happening one after another too quickly, try putting some kind of delay after each pulsin.

4. see if your sonar is getting 5v of power, use a multimeter. It could be underpowered.. (mine is getting about 5.4V)

5. Are your batteries are dead?

6. Try a Low-high only instead of a low-high-low...

 LOW PORTC 0
 HIGH PORTC 0
 PAUSE 1
 LOW PORTC 0
 LET DIRSC = %00000000
 PULSIN 0, 1, W0

 

 

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Hi Guys.

Just got my 28X2 to run with the following code.

Note the need to identify the port and pin with the current model picaxe 28 pin.

Main:
 LOW C.0
 HIGH C.0
 PAUSE 1
 LET DIRSC = %00000000
 PULSIN C.0, 1, W0 debug
 goto Main

How do I debug with the ping to determine distance?

I am using this code:

Main:

 LOW PORTC 0 

 HIGH PORTC 0

 PAUSE 1

 LOW PORTC 0

 LET DIRSC = %00000000

 PULSIN 0, 1, what goes here?

 debug

 goto Main

 

But I dont know what the input label is.

 

any ideas? 

 

W zero goes there

 

like this: W0

Sorry im a tad bit new to soldering, the pins on the ping))) are soldered to wires, but how are the other ends of the wire attached to the pins? should i just use an empty servo plug and solder the connections in?
I also reccomend you to check "Soldering" under the Tips section at the top.

805-00012-M.jpg

No Soldering Required on Either End

Here is my code...  I am sure I am just doing something silly wrong.

 

Symbol dangerlevel = 70 ' how far away should thing be, before we react?
symbol turn = 300 ' this sets how much should be turned
symbol servo_turn = 700 ' This sets for how long time we should wait for the servo to turn (depending on it´s speed) before we measure distance

main: ' the main loop
' read how much distance ahead
low portc 0
 high portc 0
 pause 1
 let dirsc = %00000000
 pulsin 0, 1, w0
return
 

if w0 < dangerlevel then
gosub nodanger ' if nothing ahead, drive forward
else
gosub whichway ' if obstacle ahead then decide which way is better
end if
goto main ' this ends the loop, the rest are only sub-routines

nodanger:' this should be your combination to make the robot drive forward, these you most likely need to adjust to fit the way you have wired your robots motors
high 4 : high 7 : low 5 : low 6
return


whichway:
gosub totalhalt ' first stop!

'Look one way:
gosub lturn ' look to one side
pause servo_turn ' wait for the servo to be finished turning
low portc 0
 high portc 0
 pause 1
 let dirsc = %00000000
 pulsin 0, 1, w0

return
gosub totalhalt


'Look the other way:
gosub rturn ' look to another side
pause servo_turn ' wait for the servo to be finished turning
low portc 0
 high portc 0
 pause 1
 let dirsc = %00000000
 pulsin 0, 1, w1
return
gosub totalhalt

' Decide which is the better way:
if w0<w1 then
gosub body_lturn
else
gosub body_rturn
end if
return

body_lturn:
high 7 : low 4 : low 6 : high 5 ' this should be your combination that turns the robot one way
pause turn : gosub totalhalt
return

body_rturn:
high 4 : low 7 : low 5 : high 6 ' this should be your combination that turns the robot the other way
pause turn : gosub totalhalt
return

rturn:
servo 0, 100 ' look to one side
return

lturn:
servo 0, 200 ' look to the other side
return

totalhalt:
low 4 : low 5 : low 6 : low 7 ' low on all 4 halts the robot!
Servo 0,150 ' face forward
wait 1 ' freeze all for one second
return
 

I did tried the low and high port thing mention above.

I try so many thing but my ping sensor won't work for me. The little led on the sonsor lid up is that mean its good? it lid up whe the wire from the signal and power cross each other. can someone give me a sample of their code of ping sensor with picaxe 28x1. I am using 4 AA batter which also indicate 1.2V. I have 2 ping and I don't want to waste it. Thank you in advance.

Anyone try this on the wall racer? have you had any success?Or I can trade my ping for the srf05 because I have 2 of them.