SteveRobey
Posts: 20
Joined: Wed Jan 07, 2015 11:53 am

Multiple sensors on a Rev B

Tue Mar 24, 2015 9:27 am

I'm working on a robot using a Rev B board that will move around autonimously and avoid collision using HC-SR04 ultrasonic range finders. I've already got it working with a single sensor facing directly ahead but I want to add two more looking 90 degrees to the left and right as well so the robot can make a decision based on which direction determines an obstacle to be farthest away. I'm already starting to sort out the code as that part is pretty easy after getting it to work with a single sensor, but what I'm wondering is if I can connect all three pulse pins to a single GPIO out and have the Echo pins connected to their own GPIO in. The thought is that I would run some code to "Look around" and pulse once and listen on the left echo, grab that number, pulse again and listen on the center echo, grab that number and pulse again and listen on the right echo and return each of those values. If I'm only listening on one echo, am I still going to get weird numbers with all of them pulsing at the same time and bouncing the signal or is it safe to assume that I'm not going to pick up an echo from the ultrasound on the right before the one on the left assuming left is what I am listening on?

If I'm going to connect these each to their own GPIO out and GPIO in, obviously I will need a total of six GPIO pins for the three sensors. I'm already using a total of six for my H-Bridge motor driver using an L293D to drive two 6-vold DC motors for the wheels. It looks like it's possible but I'm still pretty new to the GPIO so I want to make sure there's not some reason i can't use certain pins. The H-bridge has already been soldered to a perf board, but I have the L293D in a socket so it can be taken out if I need to go back to a breadboard for this. It's currently set up to use GPIO 19, 21 and 23 for one side of the bridge, and GPIO 16,18 and 22 for the other side. Could I, for example use GPIO 3 as my pulse pin and use 5, 7 and 11 for all of my echo pins or would it be better to just do dedicated pulse and echo pins for each of the HC-SR04 range finders?

I would greatly appreciate any feedback anybody has on this though I will say, for this project I want to stick to a 26 pin GPIO bus rather than upgrading to a B+ or one of the other boards with a 40 pin bus. I intend to use the knowledge to teach others how to build a basic robot at my local maker space this summer provided we get all of our non-profit stuff settled in time.

Thanks everybody.

User avatar
davidcoton
Posts: 5026
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK
Contact: Website

Re: Multiple sensors on a Rev B

Tue Mar 24, 2015 10:32 am

Sounds like a case for experiment. Try the common pulse, and see if you get clean signals back. My guess would be that the first echo on any given sensor must be from its own pulse, as any path from another sensor must be longer.
Signature retired

User avatar
DougieLawson
Posts: 39120
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Multiple sensors on a Rev B

Tue Mar 24, 2015 10:33 am

You've got 17 pins to play with, plus 4 if you solder pins into the P5 header.
Image
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

SteveRobey
Posts: 20
Joined: Wed Jan 07, 2015 11:53 am

Re: Multiple sensors on a Rev B

Tue Mar 24, 2015 10:47 am

thanks for the updates guys, I feel like it makes sense that the first pulse received by the listening sensor would be the one it sent as the other pulses would leave in other directions and have to bounce around before that sensor picked them up. There's also the argument that these particular sensors are only accurate up to around 22 degrees so it might not pick up the other pulses anyway.

Like you said, I'll have to play around with it. I'll post back here with my findings if somebody hasn't beat me to it.

SteveRobey
Posts: 20
Joined: Wed Jan 07, 2015 11:53 am

Re: Multiple sensors on a Rev B

Thu Mar 26, 2015 7:08 am

I just received a set of male to female jumper wires in the mail today and have a third HC-SR04 and some other stuff coming in about a week, up to this point I have been using a GPIO breakout to breadboard things and I would honestly rather work directly with the GPIO header pins themselves. I'm hoping to wire up the two HC-SR04s that I have Thursday or Friday and will comment on my results after that. I feel like this may already be being discussed in another thread someplace because I'm not seeing any responses here, but I'll post here anyway.

User avatar
DougieLawson
Posts: 39120
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Multiple sensors on a Rev B

Thu Mar 26, 2015 8:30 am

HC-SR04's are a five volt device, you need a 1K0 & 2K0 resistor for each to make a voltage divider or you could fry your GPIO pins.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

SteveRobey
Posts: 20
Joined: Wed Jan 07, 2015 11:53 am

Re: Multiple sensors on a Rev B

Fri Mar 27, 2015 3:18 am

HC-SR04's are a five volt device, you need a 1K0 & 2K0 resistor for each to make a voltage divider or you could fry your GPIO pins.
You literally copied and pasted that from the other thread where you told me the exact same thing.

Anyway. My findings are that yes, you can connect the pulse pin on these together but you're going to get weird numbers back, or at least I did. At any rate, it's possible and you don't need to do it because you have enough pins. Also there's shift registers which has me wondering why they bothered to add more GPIO pins.

User avatar
joan
Posts: 14935
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Multiple sensors on a Rev B

Fri Mar 27, 2015 9:27 am

SteveRobey wrote: ...
Anyway. My findings are that yes, you can connect the pulse pin on these together but you're going to get weird numbers back, or at least I did. At any rate, it's possible and you don't need to do it because you have enough pins.
...
I couldn't foresee what you suggested not working unless you were trying to sample too fast. You'd have to make sure enough time had elapsed for all the echoes around the room to have dissipated before sending the next trigger.

What sample rate were you using?

SteveRobey
Posts: 20
Joined: Wed Jan 07, 2015 11:53 am

Re: Multiple sensors on a Rev B

Sat Mar 28, 2015 5:19 am

I may have been trying to sample too fast. The other thing is the particular testing code I was using doesn't wait for the sensor to settle. I honestly didn't see different numbers what I did that. Either way, I was able to implement slightly better code along with the code for my motor driver and some if statements and timing and ended up with a robot that doesn't run into walls anymore. Sometimes it swings around near a wall and hits it's butt but that's not a big deal. I did learn that it tends to not see the curtain hanging in the doorway to my laundry room which makes sense when you consider the fabric is probably absorbing some of the sound and letting some through. Wall mazes are not made of cloth that I'm aware of so this shouldn't be a problem either. All in all, I'm using a total of 10 GPIO pins and have a more or less complete robot with room to add things so saving one pin is neither here nor there. Next I'm planning to build another H-bridge and make a line tracer robot since I have another chassis and a line tracer sensor.

SteveRobey
Posts: 20
Joined: Wed Jan 07, 2015 11:53 am

Re: Multiple sensors on a Rev B

Thu Apr 02, 2015 10:28 am

So far I have been having good results with the robot in my house with the two sensors, still planning on installing a third front and center this weekend, I also plan on placing it as low as possible to make sure it picks up objects that the robot would otherwise get high-centered on as it's only got two wheels and a caster and not enough torque to climb over the toe of s shoe. Anyway, all this asside, I decided to take my bot to work with me tonight so I could test it out during my lunch break in a much larger area with no cats. I immediately noticed something weird. One of my sensors seems to be getting odd numbers. I've got my program set up so that on regular intervals the robot grabs a reading from each sensor, one after the other and if an object is sensed within 15 cm, the motor on the opposite side reverses, causing the robot to pivot away from the object. If both sense an object within 15 cm, it backs up and then pivots a little to one side and looks again. This has worked relatively well to navigate out of corners. It does, however, look a bit like a new driver trying to parallel park. Once I started my robot out in a large room, it began behving as if there was an object directly to the right, quite regularly and would more or less continue pivoting to the left. One thing I will note is that once it nears a long wall on the left it will usually happily follow it for quite a while.

I ran some tests of the two sensors, holding the robot up in a large room, pointing in the general direction of a wall about 100 feet or so away. I usually got numbers I expected, but every once in a while, the sensor on the right would return an extremely low value like 3-5 cm. I do have my voltage divider set up on each sensor so I don't think I've damaged a GPIO but what else could be the problem? Do I have a bad or damaged sensor? Is it at all possible that because of the complexity of the room, the sensor is picking up an echo from the other one or maybe a previous signal still bouncing around?

Return to “Advanced users”