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

Vince v2.0's picture
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

 

 

 

Your rating: None Average: 5 (3 votes)
fritsl's picture

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!!

CaptainTuna's picture

thank you so much!!! i will

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

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.

Vince v2.0's picture

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

CaptainTuna's picture

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 :D 

Vince v2.0's picture

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...
Casca's picture

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.

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 

 

voodoobot's picture

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. 

fritsl's picture

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

voodoobot's picture

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!

 

Casca's picture

That's my next purchase - I

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

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.
CaptainTuna's picture

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?
Vansu's picture

hope it works.

hope it works.

Comment viewing options

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