Shop OBEX P1 Docs P2 Docs Learn Events
Javelin with Parallax Ping))) Ultrasonic Sensor — Parallax Forums

Javelin with Parallax Ping))) Ultrasonic Sensor

klddxklddx Posts: 8
edited 2006-04-10 07:47 in General Discussion
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

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-04-01 20:41
    What is the url for the parallax javelin code for the Ping?

    regards peter
  • klddxklddx Posts: 8
    edited 2006-04-01 21:14
    The Parallax code is in the pdf file found in this URL
    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.
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-04-01 21:35
    I copied the code from the document,
    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
  • klddxklddx Posts: 8
    edited 2006-04-01 22:05
    They compiled fine Peter, however, the three variables (range, msg, distance) still go "out of scope" when you go to the Debug option.
    The code is still always returning a 0 even if there is an object in front.
    Thanks for all the help.
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-04-01 22:22
    pulseIn: returns the length of the pulse in 8.68us units. A value of 0 indicates that no start edge was detected. A value of -1 indicates that no stop edge was detected.


    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
  • klddxklddx Posts: 8
    edited 2006-04-01 22:38
    After many hours wasted, we decided to try the 2nd of our Parallax Ping sensors and it worked perfectly. The first sensor we had apparantly came broken. Thanks for all the help.
  • Randy HootmanRandy Hootman Posts: 9
    edited 2006-04-10 07:43
    I, too, got 0s from my ping (it did work for a while which was confusing). I rewrote the code to use Float32s and still had the problem. Then I tried a different ping asensor and it worked perfectly. Yep, a bad ping sensor too. Are others finding this the case? Just with the Javelin maybe? If Parallax wants, I saved my broken ping sensor and I could send it back to be checked out.
  • Randy HootmanRandy Hootman Posts: 9
    edited 2006-04-10 07:47
    Another thing came to mind after my last post. Does there have to be a certain delay between pulses? In other words, could pulsing the ping sensor too often cause it to burn out? I am only thinking this as there is a mention of a time delay in the documentation but it wasn't clear if the hardware puts it in for you or you have to do it. Tech support?
Sign In or Register to comment.