Shop OBEX P1 Docs P2 Docs Learn Events
A off brand PING issue — Parallax Forums

A off brand PING issue

__da__boss____da__boss__ Posts: 9
edited 2014-02-05 03:35 in BASIC Stamp
Hey! Just a simple question for the smart ones. I gave up because I cannot get this to work correctly.


I have this _(http://www.amazon.com/SainSmart-HC-SR04-Ranging-Detector-Distance/dp/B004U8TOE6/ref=sr_1_5?ie=UTF8&qid=1391193537&sr=8-5&keywords=ping#productDetails)_
and as you see it has four prongs instead of three. I hear the ping clicking when I run this

***
' {$STAMP BS2}' {$PBASIC 2.5}


Ping_Pin CON 0
InConstant CON 890
inDistance VAR Word
time VAR Word


DO
PULSOUT Ping_Pin, 5 ' Send short pulse to Ping
PULSIN Ping_Pin, 1, time ' Wait for echo
inDistance = inConstant ** time ' Convert to inches
DEBUG CR, DEC inDistance ' Display result
PAUSE 200 ' Short delay until next read
LOOP
***

But it is not sending feedback on the prompt that comes up it is just '0's
There is one port that I dont have hooked up cause I don't know where to wire it to it's called " Echo "

This is how I have it wired
Right to left -
GND ( Ground ) to Vss
Echo ( Not sure ) to no where
Trig ( Trigger ) to P0 ( Next to X2 )
VCC ( Positive Power ) to VDD ( Next to X3 )

Comments

  • ZootZoot Posts: 2,227
    edited 2014-01-31 11:48
    This device is not like a Ping, but more like an SR04 -- another 4 pin sonar unit.

    You need to hook up the ECHO pin to an INPUT pin on your Stamp. When the ECHO line goes high after a trigger, that's what your PULSIN measures. This should probably work (presuming you hook ECHO up to PIN 1, but you can use any pin).

    Also, you are much better off defining pins as PIN, not CON. There are reasons to do the latter, but not in the case.
    
    Sonar_Trigger PIN 0
    Sonar_Recv PIN 1
    InConstant CON 890
    inDistance VAR Word
    time VAR Word
    
    DO
    PULSOUT Sonar_Trigger, 5 ' Send short pulse to Ping
    PULSIN Sonar_Recv, 1, time ' Wait for echo
    inDistance = inConstant ** time ' Convert to inches
    DEBUG CR, DEC inDistance ' Display result
    PAUSE 200 ' Short delay until next read
    LOOP
    
    This is how I have it wired
    Right to left -
    GND ( Ground ) to Vss
    Echo ( Not sure ) --- to P0/Sonar_Trigger
    Trig ( Trigger ) -- to P1/Sonar_Recv
    VCC ( Positive Power ) to VDD
    
    
  • 72sonett72sonett Posts: 82
    edited 2014-01-31 14:45
    You need to read the echo from the sensor on an I/O pin.

    I use the same 4pin HC-SR04 sensor and it works OK with this subroutine, as in the PING example code;
    distance               VAR           Word                    ' distance to object
    pingtrig                PIN  1                                    '  I/O pin to send trigger pulse
    pingecho              PIN  2                                    '  I/O pin to read echo
    
    ...
    
    measuredistance:
      DEBUG "ping... "
      LOW pingtrig                                                    ' make trigger 0-1-0
      PULSOUT pingtrig, 5                                         ' activate sensor with short (10μs) pulse
      PULSIN  pingecho, 1, distance                           ' measure echo pulse
      IF distance > 0 THEN
         distance = distance */ $0CD                            ' convert to μs
         distance = distance / 2                                   ' half time (puls go / return)
         distance = distance ** 2257                            ' in cm
         DEBUG DEC distance, " cm", CR
      ELSE
         distance = 1000
         DEBUG " timeout", CR
      ENDIF
    RETURN
    

    Foto550-MY88LA6Z.jpg
  • prof_brainoprof_braino Posts: 4,313
    edited 2014-01-31 18:03
    Get the SR04 on Ebay, they are much cheaper than $7
  • ercoerco Posts: 20,256
    edited 2014-01-31 18:30
    Jeepers 72sonnett, no one stands a chance of sneaking up on your contraption. Stereo microphones, twin PIR sensors, plus an ultrasonic sensor. Did I miss anything? Is it self-aware?:)

    Is that the burglar alarm for your Saab?
  • 72sonett72sonett Posts: 82
    edited 2014-02-01 05:00
    erco wrote: »
    ...Did I miss anything?
    3 LDRs and an ADC chip to see if there´s any light shining at it, a couple of bi color LEDs for fun, a buzzer, and control for 3 servos.
    I do not want to hijack this topic, but I started this thing as an extension of a project elsewhere on this forum, where somebody built a ´Solar Flower´ out of a vegetable cooker.
    Is it self-aware?
    I would like to think it is, but since I programmed it, it´s like me, so it hardly is.

    solarflower2.jpg



    What it does in short;

    - see if it´s light or dark,
    :if it´s dark, close flower and show randomly blinking bi color LEDS
    :if it´s light, open flower, turn to light source, listen for sound, look for IR movement
    :: if there´s a sound or IR movement, turn to source, measure distance to object in front of solar flower
    :: if distance is less than 30 cm, close flower, keep measuring distance and make beeping sounds while distance is less than 30 cm
    loop forever

    @prof braino; yes, a lot cheaper on ebay, less than $7.

    Is that the burglar alarm for your Saab?
    Hm... that´s an idea, but who would want to steal a 40+ year old Saab Sonett?
    512 x 385 - 257K
  • GadgetmanGadgetman Posts: 2,436
    edited 2014-02-01 09:52
    Is it the Sonett III ?

    Then the answer is 'no one'. If it's one of the earlier models, then the answer is 'everyone'.
    The earlier ones can give a Jaguar E-type a run for its money in the looks department. The later ones, only if the Jaguar fell from a high-rise...
    I'm a Citro
  • __da__boss____da__boss__ Posts: 9
    edited 2014-02-04 20:14
    I'm not sure what you mean. Where do I place the echo connection to? I have the SRO4, and I got it for X-mas, so no need to buy it from eBay. I appreciate your and everyone's replly. What exactly is a I/O port?

    Once I get this set up, I want to have it roam freely and dodge stuff, where is a simple script to do this?
  • FranklinFranklin Posts: 4,747
    edited 2014-02-04 21:09
    This should get you started http://www.parallax.com/product/28123 Look at the downloads toward the bottom.
  • 72sonett72sonett Posts: 82
    edited 2014-02-05 03:35
    Where do I place the echo connection to?
    ...
    What exactly is a I/O port?
    A connection on the BStamp, another pin (e.g. #1) on the BStamp, like you did with Ping_Pin on #0;
    Ping_Pin CON 0
    ...
    Echo ( Not sure ) to no where
    Trig ( Trigger ) to P0 ( Next to X2 )

    The PING(( has 3 pins, it uses 1 pin for both trigger and echo. The SRO4 has 4, it uses separate pins for trigger and echo so you need to connect those pins to separate ports on the BStamp and rewrite the PING(( code accordingly, as indicated earlier by Zoot and me.
    ... I want to have it roam freely and dodge stuff, where is a simple script to do this?
    'Simple' is a subjective term... My guess is that you'll have to do a lot of reading before you'll be able to do that.:tongue:
    Start with a tutorial and first build simple things, like making an LED blink.:smile:
Sign In or Register to comment.