Javelin with Parallax Ping))) Ultrasonic Sensor
klddx
Posts: 8
I've recently started using the Parallax Ping sensor with my javelin and found out that the code on the Parallax Website for it did not seem to work. I'm constantly getting 0 for my output. When I debug, three variables are "out of scope" (distance, msg, range). Does anyone know what this means? Since the parallax code doesnt seem to work, I've made my own code based on their documentation but is also constantly returning 0. Thanks in advance.
Here is the code that I am using:
package stamp.peripheral.sensor;
import stamp.core.*;
public class ping1 {
static int echoRaw = 0;
public static void main() {
while (true) {
CPU.writePin(CPU.pin0,false); // setup for high-going pulse
CPU.pulseOut(1,CPU.pin0); // send trigger pulse
echoRaw = CPU.pulseIn(2171,CPU.pin0,true); // measure echo return
System.out.println(echoRaw); //show value of echoRaw
CPU.delay(5000);
} //while
} //main
} //class
The parallax code can be found here http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.2.pdf
Here is the code that I am using:
package stamp.peripheral.sensor;
import stamp.core.*;
public class ping1 {
static int echoRaw = 0;
public static void main() {
while (true) {
CPU.writePin(CPU.pin0,false); // setup for high-going pulse
CPU.pulseOut(1,CPU.pin0); // send trigger pulse
echoRaw = CPU.pulseIn(2171,CPU.pin0,true); // measure echo return
System.out.println(echoRaw); //show value of echoRaw
CPU.delay(5000);
} //while
} //main
} //class
The parallax code can be found here http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.2.pdf
Comments
regards peter
http://www.parallax.com/detail.asp?product_id=28015
It is towards the end of the PDF file past the BASIC code, I believe it is on page 11
Thanks again peter.
changed the package to
stamp.peripheral.sensor.range.ping
Both classes compile just fine, no
out of scope errors (which usually occur
when brackets { and } don't match)
Try this program
and report the results
regards peter
The code is still always returning a 0 even if there is an object in front.
Thanks for all the help.
If your code (your 4 lines) only returns 0, then no start edge is detected,
so either the Ping does not sends out a sound wave (check power and/or try other I/O pin),
or the reflected wave is not received (hold a reflective object in front of ping).
You may try increasing the 2171 (but this should be ok) or increasing the pulseOut pulselength.
regards peter