hey, i’m new to this, and i have just joined programming… I was wondering if anone was using an ultrasonic rangefinder or if anyone knew how to write the code. I have a ultrasonic that has only 1 port… it’s the Ping))) ultrasonic distance sensor from Parallax… I was using WPILib, but that has both an echo and ping port, and mine has only a connection for one port, and the sample code is in basic, which I don’t understand… HELP?! thanks oh, and I am working in C programming.

You can wire it two 2 ports from that one set of 3. I wrote some code for that sensor and it works if one of the pins is in port 1 or 2. I am working now to get ports 3-6 working, but with no luck.
Basically what you have to do is send a pulse on a digital output (set one of them to 1 for a couple of seconds) then you wait for an input, which is where you use an interrupt and a timer to time the pulse. Take a look at the datasheet for that sensor

and if you would like I could upload my code that works with ports 1&2.

The WPIlib code works if you use a Y-cable to plug the Ping))) into, say, ports 1 and 7 (the echo port must be one of the first 6). You’ll have to convert the male ends of the Y-cable to female.

Will, I was wondering if you could upload your code so I can check it out as well?

I’ve been trying to get multiple sonars working and I just don’t know how! :confused:

So if you can upload that’d be great, and if anyone else can upload code that they’ve used to get Multiple sonars working that’d be great! It would really help me and possibly many others! :o

  • Rameez


I also have a quad ultrasonic driver that’s not abstracted from the 1024 2008 robot code entirely (as my previous single pin single ultrasonic was). I’ll be releasing my quad ultrasonic driver as early as after ship date or as late as mid season.

Just to give a few specs, my quad ultrasonic driver (usdriver2.c/h) can read up to four simultaneous measurements from four parallax PING))) (or similar) ultrasonic sensors. They can be fired together or in any combination or sequence at any time (provided the individual sensor is not busy). The system makes use of digital I/O pins 3-6 and is not reconfigureable to any other pins, and also uses TMR1. This, also, is not reconfigureable.

If there is enough interest in this driver i’ll make it more of a priority.


My code for port 1 or 2:

I have to get the ones for 3-6 working sometime soon, I cant seem to get it, I have a thread going about my problem here:

I shall look over your code Qbranch, thanks for posting

After the season when I have some time I will play around with using only 1 port (I had mixed results before)