clint9090
Posts: 7
Joined: Thu Jan 17, 2013 3:40 pm

gpio to gpio

Sun Oct 11, 2015 5:15 pm

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

User avatar
buja
Posts: 506
Joined: Wed Dec 31, 2014 8:21 am
Location: Netherlands

Re: gpio to gpio

Sun Oct 11, 2015 5:35 pm

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.
Last edited by buja on Sun Oct 11, 2015 7:54 pm, edited 1 time in total.

User avatar
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

Re: gpio to gpio

Sun Oct 11, 2015 6:07 pm

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).
Microcontroller addon boards and software for Raspberry Pi A+/B+/Pi2:
- ARMinARM: ARM Cortex-M3 (STM32)
- AVRPi: ATmega32U4 & ATmega328 ("Arduino")
http://www.onandoffables.com

clint9090
Posts: 7
Joined: Thu Jan 17, 2013 3:40 pm

Re: gpio to gpio

Sun Oct 11, 2015 6:51 pm

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!!!

User avatar
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

Re: gpio to gpio

Sun Oct 11, 2015 6:59 pm

Correct. Theoretically that should also work.
3.3V is high enough for the 5V pins to register as high.
Microcontroller addon boards and software for Raspberry Pi A+/B+/Pi2:
- ARMinARM: ARM Cortex-M3 (STM32)
- AVRPi: ATmega32U4 & ATmega328 ("Arduino")
http://www.onandoffables.com

clint9090
Posts: 7
Joined: Thu Jan 17, 2013 3:40 pm

Re: gpio to gpio

Fri Nov 13, 2015 5:35 am

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

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

Re: gpio to gpio

Fri Nov 13, 2015 8:54 am

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.

User avatar
DougieLawson
Posts: 36331
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: gpio to gpio

Fri Nov 13, 2015 11:04 am

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).
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Return to “General discussion”