Connecting three Sharp digital distance sensors

I bought a 3pi with expansion board and 3 of these: pololu.com/product/1134
I’m a newbie to hobby robotics and was wondering how I should be connecting these up to the 3pi / expansion board.

My guess is I could connect ‘OUT’ on two of them to PD0 and PD1 on the 3PI and ‘GND’ to the two ‘GND’ sockets beneath PD0 and PD1. But then how could I connect the third sensor, what do I connect ‘VIN’ to? I’m really out of my depth here and would appreciate some hand-holding.

It would probably be easiest to make your three sets of connections for power (VIN and GND on those distance sensors) to the 3pi’s VCC & GND pins located in between the batteries and the front edge of the robot. This should provide a regulated 5V with enough current for each of the sensors. You could use PD0 and PD1 to read the outputs like you mentioned for two of those sensors. Then for the third, you could use one of the jumpered I/Os (AD6, AD7, and PC5), but you would first have to remove the jumpers (and you would lose their functionality). You can read more about using the available I/O under the “Available I/O on the 3pi’s ATmegaxx8” section of the 3pi’s user’s guide, which you can find under the Resources tab of its product page.

-Jon

Just want to stress again how much of a newbie I am to robotics and electronics in general. I’ve never done any electronics before and only used a soldering iron for the first time about a week ago, so sorry if I frustrate you :stuck_out_tongue:

My questions:

  1. In the documentation, it states:

I can’t see PD0 or PD1 noted anywhere on the expansion PCB.

  1. For the IO (PD0, PD1, AD6, AD7, PC5 etc) I can understand why there would be two connections for each, input and output. But I don’t understand why there are two sockets for VCC, GND and the others.

  2. What is a ‘jumpered’ IO and what would I lose if I removed the jumper?

I made an image to try and explain some of my confusion.

The black/red block is what my expansion board plugs into, do these function pretty much the same as the circular, metal sockets but allow stuff to be plugged into them more easily?

The green shows one of the free IO connections, how can I tell which of these two sockets is input and which is output?

The orange rectangles are where I want to place my sharp digital sensors and the lines are my guess as to where I would have to solder the wires. I’m not sure how I would connect up the other two sensors at all.

Sorry, I did not notice you said you were using the expansion board. We have several expansion boards for the 3pi, but from your latest picture it looks like you have the m3pi expansion kit.

I have numbered my responses according to your numbered questions:

  1. PD0 and PD1 are not labeled on the m3pi expansion board, but they are accessible. You can learn more about their location under the “3pi Base Pins” section of the “Pololu m3pi User’s Guide”, which you can find under the Resources tab of the m3pi expansion kit’s product page. You could also attach wires directly to the bottom (3pi base) board, if that is more convenient for you.

  2. It is not correct to say that “PD0, PD1, AD6, AD7, PC5 etc” have two pins for input and output. There is only a single pin by those names on the AVR microcontroller on the 3pi, and in software you can designate those pins as either an input or an output. We provide multiple access points for convenience in case user’s need more than one connection point for their robot.

  3. The jumpered I/O pins, PC5, ADC6, and ADC7, are all connected to 3pi hardware via removable blue shorting blocks. By removing the shorting block, you can use these pins for your own electronics. You can also refer to the “3pi Base Pins” section of the m3pi’s user’s guide to learn more about what 3pi hardware those pins are connected to.

- Jon

Ah, yeah, now I see the diagram showing the PD0 and PD1 holes on the m3pi expansion board. There are 3 available out of the 5, so I assume I can just use one of of these 3 for connecting to the OUT of one of digital sensors?

Also, it states this about PC5:

I can’t understand if it’s telling me that PC5 is ok to use for my digital sensors or not :confused:

So if I remove the shorting block will I lose both the remaining voltage monitor displayed on the LCD and the functionality of the potentiometer? I think I’m really misunderstanding a) whether I will lose any important functionality if I use AD6, AD7 and PC5 and b) if I do use them, does it matter which of the multiple holes I use that each have?

Also, if I need to connect 3 digital sensors to 3 different VCC holes, where is the third? I only see two available.

Yes, you could use pin AD6, AD7, or PC5. You would have to modify the 3pi base firmware if you want to connect the output from one of your sensors to PC5, so it would probably be easier to use AD6 or AD7 instead of PC5. It should not matter which of the two pin holes you use. There are three shorting blocks, one each for AD6, AD7, and PC5. Removing one of those blocks disconnects the hardware that specific pin is connecting to, so you lose that particular feature (not all of them).

To create more connection points for VCC, you can solder a single wire from either of the VCC pin holes into the prototyping space on the m3pi expansion PCB. You can learn more about that space under the “Prototyping Space” section of the “Pololu m3pi User’s Guide”. If that is appealing to you, I recommend soldering to one of the two long horizontal strips shown in the picture in that section. (You could also do the same for GND.)

-Jon

[quote=“JonathanKosh”]Yes, you could use pin AD6, AD7, or PC5. You would have to modify the 3pi base firmware if you want to connect the output from one of your sensors to PC5, so it would probably be easier to use AD6 or AD7 instead of PC5. It should not matter which of the two pin holes you use. There are three shorting blocks, one each for AD6, AD7, and PC5. Removing one of those blocks disconnects the hardware that specific pin is connecting to, so you lose that particular feature (not all of them).
[/quote]

Ahh I see now! I think I’ll remove AD6’s shorting block and use that and sacrifice the battery reading (which is a shame but I guess it’s not vital).

That’s awesome, can I just connect any of the VCC holes to any hole along one of these two strips and connect the VIN from each digital sensor to any hole along that same strip as well?

It’s starting to make a lot more sense now, you’re being a great help, thanks.

Yep!

-Jon

Just want to confirm that I’ve got the wiring down, then I’ll actually start soldering!

Does this look right to you? Anything else I’ll need to be able to get at the sensor’s data or is this everything?

I don’t see anything obviously wrong with those connections, and I can’t think of anything else you might need to get started.

-Jon

Now I have my digital distance sensors connected, I want to jump into the software but don’t really know where to start. How can I go about getting the readings from the sensors in PD0, PD1 and AV6? I can’t seem find any decent documentation for this :frowning:

Since you are using sensors with digital outputs, you could use the is_digital_input_high function. You can learn more about that under the “Orangutan Digital I/O” section of the “Pololu AVR Library Command Reference” and see an example program that uses that function under the “Orangutan Digital I/O Functions” section of the “Pololu AVR C/C++ Library User’s Guide”. Both of those guides are resources you can find linked to under the “Resources” tab of the 3pi’s product page.

-Jon

From what I understand I could use the following code for one of the sensors:

which will return a 0 if the sensor detects something in its range or a 1 if not - or vice-versa?

If this is the case, I’m quite sad as I tried the following code:

[code]int main(){

play_from_program_space(PSTR(">g32>>c32"));  // Play welcoming notes.

set_digital_input(IO_D1, PULL_UP_ENABLED);

while(1){
	clear();
	
	if (is_digital_input_high(IO_D1)){
		red_led(1);
	} else {
		red_led(0);
	}
}

}
[/code]

And moving an obstacle in front of the sensor didn’t change the LED at all :frowning:

The red LED on the carrier lights up if I call red_led(0) directly which is strange, but lets me know it’s at least powered correctly so that’s something I guess.

Edit: I just tried changing IO_D1 to IO_D0 and it did the opposite. So to clarify:

is_digital_input_high(IO_D1) returns 1 and is_digital_input_high(IO_D0) returns 0. But neither change when I move an obstacle in front of the sensor…

PD1 is connected to the red user LED by a pull-down resistor, so whenever PD1 is 5V, the user LED will be lit. If you want to turn the red user LED off and on like that, you cannot use PD1 as an input to your distance sensor, since the output of your sensor will be influencing that circuit and turning off and on the red user LED. You can see the LED circuit inside the “3pi simplified schematic diagram”, which you can also find under the Resources tab of the 3pi’s product page.

The output of that sensor is low when an object is detected, so when your Sharp distance sensor is directly connected to the PD0, is_digital_input_high(IO_D0) should return 1 when nothing is detected and 0 when the sensor detects something.

-Jon

It’s working! Didn’t realise the user LED is connected to PD1 like that.

This is a pretty great feeling now I’ve soldered my own electronics and it works and I can get information software-side, thanks so much!