Parallax Ping))) Sensor

ultrasonic

#1

We have the Parallax Ping))) sensor. It has 3 pins, but the constructor for digitalUltrasonic requires two unique numbers for the ping and echo channel. We thought we could beat this by using a Y-cable on the output line to plug it into two ports, but that didn’t appear to work, do we need a custom class written to send start signal and one to listen for return signal? Does anyone have example code for this?


#2

I’ve never seen RIO code for this, only Arduino. The key thing is that you have to switch the data pin from being a digital output (relatively low impedance) to trigger the ping, then to a digital input (high impedance) to receive the return. In arduino, this is changing the mode of the pin. In WPIlib you may have to re-instantiate two objects each ping cycle.


#3

Edit: Sorry, I thought the below had been working with a Y-splitter, but after testing again it doesn’t seem to be working as expected.

I fiddled with one over the holidays. Seems to work fine with the Ultrasonic class.

import edu.wpi.first.wpilibj.Ultrasonic;

Ultrasonic _pingSonar;

_pingSonar = new Ultrasonic(0, 1);
_pingSonar.setAutomaticMode(true);

double range = _pingSonar.getRangeInches();

I used this Arduino code before hooking up to the RIO.


#4

How did you wire it? The constructor uses both pins 0 and 1, but the sensor only has one data pin.


#5

I was wondering this myself. We tried to use a Y-splitter on the cable, but that didn’t give us any values.


#6

The problem with just y-splitting is that the trigger pin holds the return pin low when you’re trying to get the output. Perhaps you could put a diode on the trigger pin so it can send a high pulse but not a low one? Not sure how the sensor is biased.


#7

Good question. I thought I had used a Y-splitter, but I just dug up the sensor again and tried my test code from December, and it’s not working. I swear I had it working before. I tried every wiring and constructor arrangement I could think, but no go. Possibly something changed in the Ultrasonic class, but just as likely I’m crazy and I only ever got it to work with the Arduino. Sorry for the confusion.