Shop OBEX P1 Docs P2 Docs Learn Events
Sonar Rangefinder Question — Parallax Forums

Sonar Rangefinder Question

Randy StadhamRandy Stadham Posts: 17
edited 2005-01-28 08:42 in BASIC Stamp
Hi,

I am trying to make the sonar rangefinder circuit from the BS1 app notes page 123. I want to use it with·my BS2.· I am not very good with PBasic. Below is the BS1 code and then my attempt at BS2 code. Could anyone give me some help?
I am hoping that my circuit works. When I hook up the stamp to it I get nothing from the debug window.

Thanks,

Randy
PS if any one has any better ideas I am open to them except for buying one already made. I would like to do that but I am from out of town. Way out Beijing China to be exact.

' Program: SONAR.BAS
' The Stamp runs a sonar transceiver to measure distances
' up to 12 feet.
Symbol echo_time = w2 ' Variable to hold delay time
setup: let pins = 0 ' All pins low
output 0 ' Controls sonar xmitter
input 1 ' Listens to sonar receiver
ping: pulsout 0,50 ' Send a 0.5-ms ping
pulsin 1,1,echo_time ' Listen for return
debug echo_time ' Display time measurement
pause 500 ' Wait 1/2 second
goto ping
My BS2 Conversion
'{$STAMP BS2}
'{$PBASIC 2.5}
echo_time VAR Word
·······
······· OUTPUT 0
······· INPUT 1
ping:
····· PULSOUT 0,50
····· PULSIN 1,1,echo_time
····· DEBUG echo_time
····· PAUSE 500
····· GOTO ping

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-12-29 14:26
    You need to crack open the help file and make adjustments in your parameters -- the BS1 is slower than the BS2 so the parameter values will be different. For example, a 0.5 ms pulse on the BS2 would be:

    PULSOUT 0, 250

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • Randy StadhamRandy Stadham Posts: 17
    edited 2005-01-27 12:14
    Hi,

    I am back still trying to get this home made sonar to work.
    I get readings from the Debug window all over the place one is 172 the next 34 then 1 then 923 and it is pointing at the celing. I can get the led to light up but it makes no difference if there is someting in the way or not. I have a kHz setting on my DMM and I get readings in the 38-42 kHz range.
    Any help would be appreciated.

    Randy

    Below is my new program

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

    echo_time VAR Word


    OUTPUT 0 'This is connected to the 555
    INPUT 6 'This is connected to the 567

    high 0
    low 6


    Do

    PULSOUT 0,250
    PULSIN 6,1,echo_time
    DEBUG "echo time ", DEC echo_time, CR
    PAUSE 500

    LOOP

    END
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-01-27 13:25
    Randy -

    I sure hope you have access to an oscilliscope to troubleshoot this sonar system.

    At the moment you're presuming the problem is in the software, which may or may not be the case. If we follow with that presumption, I'd try adding a brief PAUSE between the PULSEOUT and and PULSIN commands. That will give the transmititer time to stop "ringing" before you check for the return pulse. I'd start with something like PAUSE 1 and work my way up, until your echo_time readings begin to stabilize. If you had an oscilliscope you could check to see when the transmitter output has competely decayed.

    I also suspect that there will have to be some accomodations made in the area of timing, The BS-1 and BS-2 run at completely different speeds. This suggested change above MAY start you in the right direction however.

    You might also consider a fixed distance test bed, so you know ahead of time approximately what the correct echo time should be. This way you'll know if you're headed in the right direction or not, with any changes you make. Pointing the transceiver off in various directions isn't really all that helpful.

    Regards,

    Bruce Bates
  • Randy StadhamRandy Stadham Posts: 17
    edited 2005-01-28 06:54
    Thanks Bruce,

    I will give that a try this weekend. I do not have a scope but·I may use the one at the school I teach at. Would a DMM with a setting for kHz work?

    I also want to know it building circuit on a breadboard is OK? I heard that might not be a good thing.

    Thanks for all your help,



    Randy
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-01-28 08:21
    Randy -

    I've never used a DMM in that manner, so I really can't say. The proper and easiest tool is certainly a 'scope. Once you use the one at school, I think you'll see for yourself how much easier diagnosing problems will be.

    Although this may be a marvelous learning experience, I'm not sure all the hair-pulling you may end up going through is really worth it in constructing your own sonar board. Sonar modules from places like Acroname:
    http://www.acroname.com/robotics/parts/R93-SRF04.html

    are less that $40.00 US and are ready for use without fooling around with breadboards, etc. I guess it depends on where you want to spend your time - tracing potential wiring problems, or debugging software code. Just so that I show my own bias, I'm a software oriented guy myself and am allergic to solder fumes smile.gif

    Bruce
  • Randy StadhamRandy Stadham Posts: 17
    edited 2005-01-28 08:42
    Bruce,

    You are right I need to think of the time and effort I have put in to this project. I might be better buying a unit. That seems to be the best wasy to go. Well in the mean time I will work with what I have. Thanks for your help.

    Randy
Sign In or Register to comment.