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

pixaxeplusping.jpg

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)

28x1pin.jpg

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

 

 

 

YES, boy!! SO many people

YES, boy!! SO many people have asked for this!! Thanks from all of us. I hope it will become a very popular post!!

Very nice, pictures and all, nice!!

thank you so much!!! i will

thank you so much!!! i will finally get it working :smiley:

ahh won’t work for me but…i’m only using 3 batteries and that’s not 5 volts…shall i switch to 4? oh by the way my motors won’t work too with 3 batts, they turn very slow.

4xAA rechargable batteries

4xAA rechargable batteries does it for me, i use recharagable bateries which say 1.2v on the sides.

non-rechargables say 1.5v, dunno why theyd have a 0.3v difference. As long as your voltage reading is 5v -/+10%it should work

yay!! i got it to work with

yay!! i got it to work with the

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

code! thank you mate! i’m so happy :smiley:

it may sound odd but… if
it may sound odd but… if in mid project it stops working again: put the LOW PORTC 0 back in…

That is weird - So far, my

That is weird -

So far, my readings are stable at the moment. I’ll try to add troubleshoot some more code after I get done with customer projects.

Wow thats a pita… so I’m

Wow thats a pita…

so I’m curious, this would possibly work on a 08m with the pulsout/pulsin commands, correctly…or is that not even worth trying?

I was going to test it when I got another 08m that I could spare…hopefully it’ll come in the mail tomorrow.

The 8M is much simpler, it

The 8M is much simpler, it is made for using just one pin:

symbol trig = 1 ‘ Define output pin for Trigger pulse

main:
pulsout trig,2 ‘ produce 20uS trigger pulse (must be minimum of 10uS)
pulsin trig,1,range ‘ measures the range in 10uS steps
debug range ‘ display range via debug command
goto main ‘ and around forever

thanks fritsl, I actually

thanks fritsl,

 

I actually have some code ready(with int and serout to send the data to a stamp), just nothing to test it on. my question was more of whether there were any exclusions to the 8m that should be known, but seeing as you have multiple pin banks(a,b,c) with the 28x thats not quite an issue with the 8m. I found a pdf online that had all the more interesting info on the axes.

Thanks again!

 

That’s my next purchase - I
That’s my next purchase - I wanted to play with the ping, but it’s a little funky.

Anyone try this on the wall
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.

why shouldn’t it work on a
why shouldn’t it work on a wall racer? I don’t see many differences between wall racers and other types of robots. Maybe you are concerned with response times?

I connected my Ping))) to my

I connected my Ping))) to my 28X1 for the first time today.

Like CaptainTuna, I wasn’t getting any results until I eliminated the second “Low PortC 0” command.

Thanks guys !

Duane S

Wilson, NC USA

 

Help!

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.

I did tried the low and high

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

I am using the same PING sensor but failing…

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

Sorry im a tad bit new to
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 think this is what you’re looking for

No Soldering Required on Either End

I also reccomend you to
I also reccomend you to check "Soldering" under the Tips section at the top.