HELP!!! SRF04 Problem
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.
·
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
Jeff T.
'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.
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.
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.
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?
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.
<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
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 -->
Thanks to everyone 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.
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.