Shop OBEX P1 Docs P2 Docs Learn Events
HELP!!! SRF04 Problem — Parallax Forums

HELP!!! SRF04 Problem

AImanAIman Posts: 531
edited 2007-01-04 17:38 in BASIC Stamp
I have toyed with my SRF04 to get it to work and nothing goes. I am running a BS2 and the program will tokenize and download, but I simply can't get a return reading.

I pull 5v from VDD and ground to VSS with P0 as output and P1 as input and have tried many other pins as well. What am I doing wrong?

Heres the code I pulled from Acroname.



' {$STAMP BS2}
' {$PBASIC 2.5}
'
' Devantech SRF04 Example
'
wDist· VAR· Word
INIT· CON· 0
ECHO· CON· 1

' CONVERSION FACTORS:
'
' The PULSIN command returns the round-trip echo time in 2us units
' which is equivalent to the one-way trip time in 1us units.
'
' distance = (echo time) / (conversion factor)
'
' use 74 for inches······ (73.746us per 1 in)
' use 29 for centimeters· (29.033us per 1 cm)
'
convfac· CON· 74· ' use inches


'
main:
· GOSUB sr_sonar
· DEBUG DEC wDist, CR
· PAUSE 200
· GOTO main

sr_sonar:
· PULSOUT INIT,5··· ' 10us init pulse
· PULSIN ECHO,1,wDist· ' measure echo time
· wDist=wDist/convfac· ' convert to inches
· PAUSE 10
· RETURN
sr_sonar_2:
· PULSOUT INIT,5··· ' 10us init pulse
· OUTPUT INIT··· ' dummy command (delay)
· RCTIME ECHO,1,wDist· ' measure echo time
· wDist=wDist/convfac· ' convert to inches
· PAUSE 10
· RETURN

Any help??? I am very frustrated.
·

Comments

  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2006-12-24 15:09
    Hi AIman, just a thought but did you try useing the second subroutine (sr_sonar_2) the docs do mention there may be a timing issue.

    Jeff T.
  • AImanAIman Posts: 531
    edited 2006-12-24 15:16
    I tried the second sub and it didn't work either. I also tried this code:

    'Parallax, INC. • Devantech SRF04 Ultrasonic Range Finder (#28015) • 10/2003 Page 4
    ' =========================================================================
    '
    ' File....... SRF04_Demo.BS2
    ' Purpose.... Devantech SRF04 Ultrasonic Range Finder
    ' Author..... Parallax, Inc. (Copyright 2003 - All Rights Reserved)
    ' E-mail..... support@parallax.com
    ' Started.... 06 MAR 2002
    ' Updated.... 01 OCT 2003
    '
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    '
    ' =========================================================================
    '
    [noparse][[/noparse] Program Description ]
    '
    ' This program uses the Devantech SRF04 to measure the distance between the
    ' unit and a target. Display is raw value, centimeters, and inches.
    '
    [noparse][[/noparse] Revision History ]
    '
    ' 01 OCT 2003 : Updated for PBASIC 2.5 and for any BASIC Stamp module
    '
    [noparse][[/noparse] I/O Definitions ]
    '
    Trigger PIN 0
    Echo PIN 1
    '
    [noparse][[/noparse] Constants ]
    #SELECT $STAMP
    #CASE BS2, BS2E
    Trig10 CON 5 ' trigger pulse = 10 uS
    ToCm CON 30 ' conversion factor to cm
    #CASE BS2SX, BS2P
    Trig10 CON 13
    ToCm CON 78
    #CASE BS2PE
    Trig10 CON 5
    ToCm CON 31
    #ENDSELECT
    '
    [noparse][[/noparse] Variables ]
    samples VAR Nib ' loop counter
    pWidth VAR Word ' pulse width from sensor
    rawDist VAR Word ' filtered measurment
    cm VAR Word ' centimeters
    inches VAR Word
    '
    [noparse][[/noparse] Initialization ]
    Setup:
    LOW Trigger
    DEBUG CLS,
    "Devantech SRF04 Demo", CR,
    "
    ", CR,
    "Raw........... ", CR,
    "Centimeters... ", CR,
    "Inches........ "
    '
    [noparse][[/noparse] Program Code ]
    Main:
    DO
    GOSUB Get_Sonar ' take sonar reading
    DEBUG CRSRXY, 15, 2, DEC rawDist, CLREOL
    cm = rawDist / ToCm ' convert to centimeters
    DEBUG CRSRXY, 15, 3, DEC cm, CLREOL
    inches = cm */ $03EF ' x 3.937 (to 0.1 inches)
    DEBUG CRSRXY, 15, 4,
    DEC inches / 10, ".", DEC1 inches,
    CLREOL
    PAUSE 250 ' delay between readings
    LOOP
    END
    '
    [noparse][[/noparse] Subroutines ]
    Get_Sonar:
    rawDist = 0 ' clear measurement
    FOR samples = 1 TO 5 ' take five samples
    PULSOUT Trigger, Trig10 ' 10 uS trigger pulse
    #SELECT $STamp
    #CASE BS2, BS2E
    RCTIME Echo, 1, pWidth ' measure pulse
    #CASE #ELSE
    PULSIN Echo, 1, pWidth ' measure pulse
    #ENDSELECT
    rawDist = rawDist + (pWidth / 5) ' simple digital filter
    PAUSE 10 ' minimum period between
    NEXT
    RETURN



    This does the same thing. It will tokenize and download but not return anything other then zeros.

    I have different sonar and used SRF04 just to be sure·everything was·exact·and still got·the·zero's so I doubt its the unit.
  • Mike GreenMike Green Posts: 23,101
    edited 2006-12-24 18:00
    What board are you using? Exactly what are the connections between the Stamp and the SRF04? Read this description of the unit www.robot-electronics.co.uk/htm/srf04tech.htm. What do you have for power filtering for the SRF04? A large (100uF to 1000uF) electrolytic capacitor across the +5V/Gnd wires near the SRF04 may help.

    In general, when you've tried several different programs to operate a device and at least one of them is already tested and works successfully with someone else's unit, there must be something wrong with your unit or your connections, probably not the software itself.
  • AImanAIman Posts: 531
    edited 2006-12-24 20:53
    I am running Board of Education Rev C with a 9v AC power supply. It is hooked up to the desktop via USB adapter. The "manual" I got with the sonar didn't say anything about a capacitor it just showed to hook up the unit to a 5v supply. I have added nothing to the VDD.

    Volts pull from·VDD
    P0 for creates a pulse
    P1 is echo return
    Ground is to VSS

    Nothing else is hooked up and the LED power light for the BOE comes on without a problem.
    My servo programs works to run 4 servos so I know power flows but this returns nothing but zero's.
  • ForrestForrest Posts: 1,341
    edited 2006-12-24 21:22
    I hope you mean a 9V DC power supply, because a 9V AC power supply may destroy your Stamp.
  • AImanAIman Posts: 531
    edited 2006-12-24 23:06
    Your right, I was meaning a wall plug in adapter from·AC to 9v DC
  • AImanAIman Posts: 531
    edited 2006-12-24 23:50
    Ya know,

    I have tried several different versions of code and everything comes back with a steady stream of unchanging numbers. I've run several different sonar of varying types and all get the same result, so lets look at this from a hardware view point.

    Assume I know nothing -

    How should I do my wiring?
  • Mike GreenMike Green Posts: 23,101
    edited 2006-12-25 00:32
    The wiring looks correct from your description. From the article mentioned earlier, the connections are : Ground, Do-Not-Connect, Trigger (P0), Echo(P1), and +5V (Vdd). The program from Parallax should work. The article mentions grounding Do-Not-Connect to delay the ultrasound pulse by about 300us for use with slow Stamps and other slow processors. You could try that although the SRF04 is supposed to work with a Stamp.
    I don't know what to suggest other than to borrow an oscilloscope from someone and try to find out what's actually happening with the SRF04.
  • edited 2006-12-25 01:15
    Use RCTIME instead of PULSIN to measure the echo time.

    <Add>The reason for this suggestion is I remember overhearing conversations related to the BASIC Stamp 2 missing the leading edge of the pulse it's supposed to measure, so the PULSIN command hangs.· RCTIME measures from the time the command is executed until the edge it's looking for.· If it's a positive pulse, you'll want to measure to the negative edge with RCTIME pin, 1, timeVariable.· If it's a negative pulse, it would be RCTIME pin, 0, timeVariable to measure to the positve edge.</Add>

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andy Lindsay

    Education Department
    Parallax, Inc.

    Post Edited (Andy Lindsay (Parallax)) : 12/25/2006 1:24:03 AM GMT
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-12-25 07:32
    AIMan -

    The SRF-04 requires 5 VDC and 30-60 mA of current. Are you supplying that to the SRF-04 board? If you're taking it fom the Stamp regulator, you may well be causing a brown out.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • ZactlyZactly Posts: 7
    edited 2006-12-26 15:11
    I had a very similar problem, it turned out that my wires were off one hole. I would suggest checking your wiring and look for something minor like a lose wire or a jumper in the wrong hole. My problem was solved when I striped the ciruit from the bread board and started over.
  • AImanAIman Posts: 531
    edited 2006-12-26 15:34
    It could be a lose or broken wire. I will check to make sure all the connections are tight.
  • AImanAIman Posts: 531
    edited 2006-12-27 14:43
    I pushed everything down into the bread board as far as I could and that didn't do anything and then I tried rewiring everything and that didn't do anything. Then I tried moving to different pins and that didn't work. It turned out that I was running a bad jumper wire. Not bad in the sense of broken, bad in the meaning that the end wasn't stripped back far enough for a solid connection.



    Thanks to everyone for the help.
  • AImanAIman Posts: 531
    edited 2006-12-28 17:34
    Thanks all for the help

    Andy, I will update the code to RCtime. I have a version with that somewhere I think.

    Currently the code has been adapted to run 2 sonar (tested to handle 3), 2 servos, 2 dc motors and will have 6 IR added in (thats 14 pins by my count). That pretty much uses up my BS2, the thought of getting a stamp with more pins is serious, either that or linking in my other BS2. Especially considering there is supposed to be more 1 more sonar, 1 more IR, 4 more motors and 4 solenoids. If possible I want to use legs instead of wheels which would mean adding in parts for 6 legs. One of my robots uses co-processors but that board doesn't allow for prototyping on some pins leaving me short handed regarding available hookups.

    ... one problem at a time ...

    Anyway, Thanks again all.
  • AImanAIman Posts: 531
    edited 2007-01-04 14:25
    It appears that the SRF04 is the problem. I don't mean the unit itself, I mean the way it was made. Factory specs show a variance of 3 - 4 cm for each signal, that is grossly exagerated in this case. 3 - 4 cm is enough of a difference the robot could entirely misjudge a wall.

    PING))) did not show this variance in the documentation, so PING))) appears to be a much superior sonar unit with much greater stability and accuracy.

    Solution to my problem?

    Use Ping))) and use SRF04 for readings that don't matter much.
  • Steve JoblinSteve Joblin Posts: 784
    edited 2007-01-04 16:11
    AIman: Interesting... seems that the dummy "output" command (as referenced in posting http://forums.parallax.com/forums/default.aspx?f=10&m=162746) does help, but as you note the Ping))) is just a better overall product... doesn't surprise me as Parallax used to sell the SRF04 before coming out with their own version... It would be interesting for someome to to an unbiased comparison of the accuracy of the Ping))), the Maxbotix EZ1 Ultrasonic Range Finder, and the Devantec SRF series to compare and contrast the accuracy... sounds like a good idea for an article for Nuts & Volts or Servo magazine!
  • ForrestForrest Posts: 1,341
    edited 2007-01-04 17:38
    Check out this robot that uses just 1 Ping))) sensor to keep the robot balanced http://forums.parallax.com/showthread.php?p=623316
Sign In or Register to comment.