Page 1 of 1

gpio to gpio

Posted: Sun Oct 11, 2015 5:15 pm
by clint9090
Can I wire a pin from the gpio of a raspberry pi to a pin of a sparkfun pro micro (Arduino micro)? If so how?

1) Would I need to connect the ground from the pi to the pro micro?
2) Does it matter which micro I get, the 3.3v or 5v, since I'm only communicating in one way (pi to micro)? I only need to communicate in on/offs.
3) If this type of gpio to gpio is possible would it be faster or slower than something more complex like i2c?

Btw: the plan is to get the micro to send key (HID) commands to a connected computer when the pi receives some input. I only need to send about 5 distinct keys, so I was planning on just using the gpio to gpio wiring. Feel fee to let me know if that's a wrong headed approach. I know very little about any of this.

Thanks!
Clint

Re: gpio to gpio

Posted: Sun Oct 11, 2015 5:35 pm
by buja
Please find my answers below in RED.
clint9090 wrote:Can I wire a pin from the gpio of a raspberry pi to a pin of a sparkfun pro micro (Arduino micro)? If so how?

1) Would I need to connect the ground from the pi to the pro micro? YES, very important!
2) Does it matter which micro I get, the 3.3v or 5v, since I'm only communicating in one way (pi to micro)? I only need to communicate in on/offs. YES it does matter: use the 3.3V. Connecting 5 Volt to a Pi GPIO will probably destroy the Pi. You could use a level convertor, but that's a bit more complicated.
3) If this type of gpio to gpio is possible would it be faster or slower than something more complex like i2c? If you use 5 GPIO's to communicate 5 distinct keys, then this is the fastest way in theory, but I don't think you will notice the difference in practice.

Re: gpio to gpio

Posted: Sun Oct 11, 2015 6:07 pm
by panik
Feel fee to let me know if that's a wrong headed approach. I know very little about any of this.
Makes perfect sense. I agree with what @buja said.

If you're looking for software to program the '3.3V Sparkfun Arduino Pro Micro' from the Pi itself (with the Arduino IDE or a Makefile or LUFA) you can make the following extra connections and use AVRPi software.

Code: Select all

AVR MOSI - Pi GPIO 10
AVR MISO - Pi GPIO 9
AVR SCK - Pi GPIO 11
AVR RST - Pi GPIO 8
AVR GND - Pi GND
Just pretend your 3.3V Pro Micro is an AVRPi-32U4 and use the software as is: http://www.onandoffables.com/index.php? ... t=software.

The alternative is to program the Pro Micro through the USB port, but that would mean a lot of swapping USB cables around all the time. Also, you can choose to power the Pro Micro from USB, or the Pi 3.3V pins. 5V pins to RAW on the Pro Micro (edit).

Re: gpio to gpio

Posted: Sun Oct 11, 2015 6:51 pm
by clint9090
Thanks! I'm feeling a bit more confident now! But out of curiosity I have to ask: if I'm only sending on pins from the pi to the micro (in that direction only) then does it still matter if the micro is the 5v version rather than the 3.3v?

Thanks again!!!

Re: gpio to gpio

Posted: Sun Oct 11, 2015 6:59 pm
by panik
Correct. Theoretically that should also work.
3.3V is high enough for the 5V pins to register as high.

Re: gpio to gpio

Posted: Fri Nov 13, 2015 5:35 am
by clint9090
Okay, so I've got it all wired together now: Output pins on the Raspberry Pi going directly to the input pins on an Adafruit Atmega32u4 breakout, nothing in-between. I also have a ground pin connected from the Pi to a ground pin of the Atmega32u4. So far it all works... but I've run into a strange issue... I've setup a 'shutdown' button on the Pi (pin 22, IN, pull_up_down) which also works perfectly. However, if I disconnect the Atmega32u4 from the computer and plug it back in, it triggers the shutdown pin on the Pi. This is making me nervous, because the only connection between the shutdown pin and the Atmega32u4 is the 'shared/linked' ground. Is their a way to prevent this from happening? Do I need to use a diode or something between the Pi's ground and the Atmega's ground? Sorry for the rambling. I can provide a Fritzing of my current setup, if necessary. Any ideas?

Thanks!
Clint

Re: gpio to gpio

Posted: Fri Nov 13, 2015 8:54 am
by joan
Is this a glitch at power-up or does the Arduino hold the line high until you lower it in software?

If it's just a glitch then perhaps adopt a software solution at the Pi end. Sample the line again after a second to see if it's still low - only in that case shut down.

Re: gpio to gpio

Posted: Fri Nov 13, 2015 11:04 am
by DougieLawson
clint9090 wrote: 3) If this type of gpio to gpio is possible would it be faster or slower than something more complex like i2c?
I2C is easier, it's also 5V0 safe and you'll only use two GPIOs on your RPi and two on your Arduino (three wires including GND).