Can't get SR04 working on robot control board
Olivierw
Posts: 4
Hello forum,
I got an old "Propeller Robot Control Board" here, and recently i bought some HC-RS04 ultrasonic sensors.
I want to test them, but can't seem to get it to work.
I use following code I found on this forum, provided by Duane:
And code executes just upto
there it just stops.
i tried with several sizes resistors on echo, ranging from 4.7K up to 33K, nothing changes.
I got 10 SR04's and none of them works.
any idea what could be the problem?
Many thanks in advance ...
Olivier
I got an old "Propeller Robot Control Board" here, and recently i bought some HC-RS04 ultrasonic sensors.
I want to test them, but can't seem to get it to work.
I use following code I found on this forum, provided by Duane:
{{ UltrasoundSR04MultiSensorDemo121018d An attempt to share the echo lines of multiple ultrasound sensors. So far, using 4.7K resistors on each echo line allows a single Prop pin to monitor up to three sensors. No resistor on the trigger seems to work okay. A 1K resistor on the trigger lines also works. I'm using a 4.7k ohm on each echo line. }} CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 ECHO_PIN = 9 ' All sensors share a single pin for echo return. FIRST_TRIGGER_PIN = 8 ' Each sensor connects to a different pin. ULTRASOUND_DEVICES_USED = 1 DEBUG_BAUD = 115_200 ' Debug Baud TITLE_X = 3 ' Location for title TITLE_Y = 3 DISPLAY_X = 3 ' Location for range info DISPLAY_Y = 5 READING_X = 14 ' Range value printed here VAR long range[4], previousRange[4] long interPingDelay, refreshDelay byte triggerPin[4] OBJ Debug : "Parallax Serial Terminal" Ultra : "UltrasoundSR04_121018a" PUB Setup interPingDelay := clkfreq / 50 refreshDelay := clkfreq / 10 Debug.Start(DEBUG_BAUD) waitcnt(clkfreq * 3 + cnt) ' Time to open serial window. Debug.Clear Debug.Position(TITLE_X, TITLE_Y) Debug.str(string("Ultrasound Demo")) repeat result from 0 to ULTRASOUND_DEVICES_USED - 1 Debug.Position(DISPLAY_X, DISPLAY_Y + result) Debug.str(string("Range[")) Debug.dec(result) Debug.str(string("] = ")) triggerPin[result] := FIRST_TRIGGER_PIN + result previousRange[result] := -1 ' set to impossible range to make ' sure first new range is displayed MainLoop PUB MainLoop repeat repeat result from 0 to ULTRASOUND_DEVICES_USED - 1 previousRange[result] := range[result] range[result] := Ultra.Millimeters(ECHO_PIN, TriggerPin[result]) ' Get Range In Millimeters if previousRange[result] <> range[result] Debug.Position(READING_X, DISPLAY_Y + result) Debug.dec(range[result]) Debug.str(string(" mm ")) waitcnt(interPingDelay + cnt) waitcnt(refreshDelay + cnt)
{{ Modified for SR04 Ultrasound sensors By Duane Degn Updated June 12, 2012 *************************************** * Ping))) Object V1.1 * * Author: Chris Savage & Jeff Martin * * Copyright (c) 2006 Parallax, Inc. * * See end of file for terms of use. * * Started: 05-08-2006 * *************************************** Interface to sensor and measure its ultrasonic travel time. Measurements can be in units of time or distance. Each method requires two parameters, echo and trigger pins. ┌───────────────────┐ │┌───┐ ┌───┐│ Connection To Propeller ││ ‣ │ SR04 │ ‣ ││ Remember SR04 Requires │└───┘ └───┘│ +5V Power Supply │ Vcc Trig Echo Gnd │ └──┬────┬────┬───┬──┘ 5V │ │ │ │  │ │ 10K │ └───┘ │ │ │ │ │ │ trigger ┘ │ │ echo ─────┘ │  }} CON TO_IN = 73_746 ' Inches TO_CM = 29_034 ' Centimeters PUB Ticks(echo, trigger) : Microseconds | timer ''Return Ping)))'s one-way ultrasonic travel time in microseconds outa[trigger]~ ' trigger pin low (still and input) dira[trigger]~~ ' trigger output pulling trigger line low waitcnt(2000 + cnt) ' This delay is left over from Ping driver. It might be possible to shorten the delay. outa[trigger]~~ ' trigger high dira[trigger]~ ' trigger back to input. It should be okay to just leave ' the trigger pin an output. waitpne(0, |< echo, 0) ' Wait echo pin to go high timer := -cnt ' Start timer waitpeq(0, |< echo, 0) ' Wait echo pin to go low timer += cnt ' Stop timer Microseconds := (||timer / (clkfreq / 1_000_000)) >> 1 ' Return Time in µs PUB Inches(echo, trigger) : Distance ''Measure object distance in inches Distance := Ticks(echo, trigger) * 1_000 / TO_IN ' Distance In Inches PUB Centimeters(echo, trigger) : Distance ''Measure object distance in centimeters Distance := Millimeters(echo, trigger) / 10 ' Distance In Centimeters PUB Millimeters(echo, trigger) : Distance ''Measure object distance in millimeters Distance := Ticks(echo, trigger) * 10_000 / TO_CM ' Distance In Millimeters
And code executes just upto
waitpne(0, |< echo, 0) ' Wait echo pin to go high timer := -cnt ' Start timer waitpeq(0, |< echo, 0) ' Wait echo pin to go low timer += cnt ' Stop timer
there it just stops.
i tried with several sizes resistors on echo, ranging from 4.7K up to 33K, nothing changes.
I got 10 SR04's and none of them works.
any idea what could be the problem?
Many thanks in advance ...
Olivier
Comments
Is it: MSR1:
http://www.google.com/imgres?imgurl=http://api.ning.com/files/FC3LjHskJXw5G1YhL*jPwFzl1RZNFgvww8IEdz4s5XUNkWxEohVjAqYYuwip3DzljwgGx5D4PnoUpnPmzepHTxadmkucvhPg/propellerrobotcontrolboardtopports.jpg%3Fwidth%3D600&imgrefurl=http://www.rugcommunity.org/page/parallax-propeller-robot&h=450&w=600&sz=195&tbnid=xn4w2zK-9m0zdM:&tbnh=95&tbnw=127&zoom=1&usg=__MWwAdaJKlZSOCFmllkFi2uQnyCw=&docid=us0E2GLMSwGW2M&sa=X&ei=LQbWUcDrE7Gz4AP-yoCQBQ&ved=0CGMQ9QEwBQ&dur=426
or Quadrover Controller:
https://www.google.com/search?q=Propeller%20Robot%20Control%20Board&rlz=1C1AVSC_enUS435US437&um=1&ie=UTF-8&hl=en&tbm=isch&source=og&sa=N&tab=wi&ei=LQbWUcDrE7Gz4AP-yoCQBQ&biw=1280&bih=886&sei=pAfWUZPtHbGq4AOd7YDAAQ#facrc=_&imgdii=_&imgrc=fDV7OMlpgSdOQM%3A%3Bjf_sHQXeNZ9QoM%3Bhttp%253A%252F%252Fwww.igniteautomation.com%252F_ia_images%252Fpropcb.jpg%3Bhttp%253A%252F%252Fwww.igniteautomation.com%252Fprop-cb.html%3B667%3B451
or Eddie Platform:
http://www.robotshop.com/content/images/parallax-eddie-robot-platform-control-board-large.jpg
My board is the MSR1 board (Rev A).
And indeed, there are voltage translators on there,
I didn't know what those were for actually, but i'm reading a bit about those, and am starting to get the picture.
The only thing in your reply i don't really get is this: Does this mean, when i disable the translator (solder the jumper on), 8 inputs will be affected,
And are you saying i can only connect 1 SR04 on one of these 8 inputs?
So if i understand right, I got 2 options:
1. disable translator (solder jumper), and use the SR02 like in all tutorials WITH a series resistor.
2. leave the voltage translator as is, and get rid of the series resistor. (didn't dare to try it yet, was affraid to damage the inputs.)
this is what i found in a pdf manual for the board.
but i didn't know what this was.
Thanks for the board type.
The original schematic by Duane has the 10K resistor in line because the it was directly connected to the Propeller chip. The sensor is a 5 volt device and the Propeller is a 3.3 volt device, so this was necessary.
The reason for the translator is to interface to a 5 volt device. (Translate 5 volts to 3.3 volts) In theory, the 10K resistor is not needed on that line if the translator is enabled. This means you should connect to the three pin headers. In reality, some of us have found you need a 3.3K resistor inline to run servos, reference the 4.3K impedance quote).
It would be OK to try without the resistor with the translator enabled, but if it does not work, try it with a 3.3K resistor.
It's always fun for me to hear about someone using code I help with (even though the mod from one pin to two was pretty simple).
I just wanted to clarify about resistor values a bit. Often the actual value of a resistor isn't very important. Often a wide range of resistor values will work for a giving application. Prop pins have clamping diodes (don't ask me what a clamping diode is). Apparently these diodes protect the Propeller from voltages higher than 3.3V but they can only handle very small amounts of current. So if you're connecting something with higher than 3.3V to a Propeller pin you need to make sure the current is limited to about half of a milliAmp. At 5V 3.3K ohms is the lowest common resistor value that will limit the current to this safe level. I generally use 10K ohm resistors since I have a lot of them. I'm not sure what the upper limit is on a resistance value that would still work but I'm sure it well above 10K ohm.
Since the resistor just needs to be 3.3K or higher this is why it's common to see all sorts of different resistor values (3.3K, 4.7K, 10K) on schematics with 5V devices. I'm guessing others have more of one particular value and use that's handy so that's the value they put on the schematic.
Propeller pins being used as outputs have different requirements. A resistor on an output pin may interfere with signal. I find this is particularly true when interfacing with 5V devices. I haven't found many 5V devices that wont read the Prop's 3.3V logic as logic high but I have found many 5V devices that won't see the Prop's output as logic high if a resistor is added to the line.
In this particular case (SR04), if I added a 10K resistor to the trigger line then the device would never trigger. A 1K resistor didn't seem to interfere with the trigger.
Since the echo line uses 5V logic a resistor of 3.3K or higher (I don't know the upper limit but it's higher than 10K) is needed.
One thing myself and others have noticed about these cheap SR04 sensors is there's about a 20% dud rate. If your sensor doesn't seem to be working, try one of your other sensors.
Another area to check is a breadboard, if you're using one. If you're having trouble with a circuit, Pull it out and build it in another location on the board. I've been surprised how many times this has worked for myself and others.
BTW, Welcome to the forums. The Prop is a great microcontroller for robotics.
Also welcome to the forums!
didn't have time yet to test this out, but will do this weekend.
I also always start out on a breadboard for things like this. lol, imagine resoldering everytime i change a resistor value. I actually know people who do this.
Your explenations are realy clear, got me started and learned a lot.
Also thanks for the welcome
I'll keep you informed on the progress.
And about using your code , why should i try and mess up some code, if there's some perfectly working code available, code where someone, or some people worked hard on, and that has been tested and approved by many users.
If only everyone was so good to share, ...
My first job is to get some working examples for every sensor i got,
Afterwards, the biggest fun begins. trying to combine all in one project
I had the prop board still lying arround, together with some old door-opener-motors-with-encoder.
And now we're in the new house, with garden and two young kids, i want to make some kind of soccer-playing-ball-following-robot.
It's allready driving arround, but still only in pre-programmed paths. So now come the SR04 for some simple wall and tree avoiding random driving.
Next i'll try to add some old camera to look for a colored ball.
At first i wanted to make a lawnmower, but when i started to think about the kids running arround in the garden, I don't even want to think about what could happen to them. So i'll be mowing myself for another few years (and actually enjoy doing that, so no problem). Didn't really WANT one, just wanted to make one as "proof of concept"
Hope the kids will enjoy this, but i'm sure I myself will have a great time trying to build this ;-)