aywizard
Posts: 3
Joined: Thu Aug 06, 2015 12:03 am

How to connect 2 raspberry pi by their GPIO Pins?

Thu Aug 06, 2015 12:28 am

I tried to connect two raspberry pi by their GPIO pins, using one as input, another one as output. This is how I connected them:
Image
I simply connect two Raspberry Pi's GPIO Pin 9 with a 10K resistor.

I am using python to test the connection, the problem is the input side can not get the correct input, does anyone know why?

The python code for input side(on python console):

Code: Select all

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(9, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.input(9) 
The python code for output side(on python console):

Code: Select all

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(9, GPIO.OUT, initial=GPIO.LOW)
GPIO.output(9, GPIO.HIGH) 
The problem is when I set the pull_up_down parameter in input side to GPIO.PUD_DOWN, no matter how I change the output pin, the input always get 0. If I change the pull_up_down parameter to GPIO.PUD_OFF, the input is floating. It seems the input GPIO pin can not get any input from the output pin side, is there anything wrong with my connecting or my code?

Thank you!

ghp
Posts: 1667
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: How to connect 2 raspberry pi by there GPIO Pins?

Thu Aug 06, 2015 12:05 pm

Hello,
you need also to connect the ground lines.
Regards,
Gerhard

aywizard
Posts: 3
Joined: Thu Aug 06, 2015 12:03 am

Re: How to connect 2 raspberry pi by there GPIO Pins?

Fri Aug 07, 2015 8:30 am

ghp wrote:Hello,
you need also to connect the ground lines.
Regards,
Gerhard
Wow, that works!
Would you mind explaining to me why their ground lines need to be connected? I think all ground pins are 0V, why we need to connect them?

Thank you very much!

User avatar
rpdom
Posts: 17951
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: How to connect 2 raspberry pi by there GPIO Pins?

Fri Aug 07, 2015 8:35 am

aywizard wrote:Would you mind explaining to me why their ground lines need to be connected? I think all ground pins are 0V, why we need to connect them?
0V on one circuit needs to be connected to 0V on the other circuit to make sure they are both measuring from the same point.

User avatar
GerardWassink
Posts: 103
Joined: Sun Aug 02, 2015 5:57 pm
Location: Ulrum (Gr), Netherlands
Contact: Website

Re: How to connect 2 raspberry pi by there GPIO Pins?

Fri Aug 07, 2015 8:48 am

For the receiving RPi to be able to 'see' a signal, there must be a certain voltage on it's input. Every voltage, also in this case, is measured between two points. In this case one must be the 'Common Ground' or GND. That's why they must be connected.

HTH,

Gerard
---------ooooO----- \\\\\|/// -----Oooo--------
Hacker on ELF-II, ZX80/1, Commodore 64, 8080, x86,
IBM 370 family mainframes
Machine code! Assembly! C good second.
Running Pi's with Hercules and S/370 OS's

-------------oooO-----------Oooo-------------

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

Re: How to connect 2 raspberry pi by there GPIO Pins?

Fri Aug 07, 2015 9:08 am

aywizard wrote: Would you mind explaining to me why their ground lines need to be connected? I think all ground pins are 0V, why we need to connect them?
Because electrons flow in circles. If you have electrons going out on one wire they need another wire to come back.
Any language using left-hand whitespace for syntax is ridiculous

Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.

Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

aywizard
Posts: 3
Joined: Thu Aug 06, 2015 12:03 am

Re: How to connect 2 raspberry pi by their GPIO Pins?

Sat Aug 08, 2015 9:35 pm

I think I understand it now. Thanks a lot for all of you!

mikerr
Posts: 2826
Joined: Thu Jan 12, 2012 12:46 pm
Location: UK
Contact: Website

Re: How to connect 2 raspberry pi by their GPIO Pins?

Sat Aug 08, 2015 9:51 pm

See also connecting them via the serial pins,
before writing python-serial code:
viewtopic.php?f=44&t=51633
Android app - Raspi Card Imager - download and image SD cards - No PC required !

boyoh
Posts: 1567
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

Re: How to connect 2 raspberry pi by their GPIO Pins?

Sat Aug 08, 2015 11:13 pm

aywizard wrote:I tried to connect two raspberry pi by their GPIO pins, using one as input, another one as output. This is how I connected them:
Image
I simply connect two Raspberry Pi's GPIO Pin 9 with a 10K resistor.

I am using python to test the connection, the problem is the input side can not get the correct input, does anyone know why?

The python code for input side(on python console):

Code: Select all

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(9, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.input(9) 
The python code for output side(on python console):

Code: Select all

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(9, GPIO.OUT, initial=GPIO.LOW)
GPIO.output(9, GPIO.HIGH) 
The problem is when I set the pull_up_down parameter in input side to GPIO.PUD_DOWN, no matter how I change the output pin, the input always get 0. If I change the pull_up_down parameter to GPIO.PUD_OFF, the input is floating. It seems the input GPIO pin can not get any input from the output pin side, is there anything wrong with my connecting or my code?

Thank you!
Your reason for connecting two Pi's
Is it for a project,t or for experimenting
Yes you have to common the 0-of each
Pi's, If it is for a project, I suggest you
you use Opto Isolators, you will not need
to common the 0- There will be no physical
connection between Pi's
The other alternative would to use one
power supply for both Pi's.
I would like to know what is you reason
for inter connecting two Pi's
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

baksteen-13
Posts: 2
Joined: Mon Jun 19, 2017 8:49 am

Re: How to connect 2 raspberry pi by their GPIO Pins?

Mon Jun 19, 2017 10:06 am

do you need a 10K resistor or can it be less?
i have a 3k3 one. will that work?

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 13544
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: How to connect 2 raspberry pi by their GPIO Pins?

Mon Jun 19, 2017 11:44 am

No it doesn't matter the resistor is there purely for safety in case one PI decides to program the GPIO as an output.
When programmed as input the input resistance is very very high, so using 1K 10K or even 100K doesn't matter much.

Prajwal MR
Posts: 1
Joined: Fri Apr 24, 2020 9:43 pm

Re: How to connect 2 raspberry pi by their GPIO Pins?

Sat Apr 25, 2020 10:40 am

One thing is worrying me soo much here ! During boot up, some gpio's will go high(pulled up). Now what if both the pins on each raspberry pi (input pin and output pin) that are connected, go high during bootup, will it no lead to an exceeding voltage and damage the pi ?

Return to “Python”