I need 2 raspberry pi for my project (i'll use all pins on both pi's) and i want to control them with an interface on my laptop (used python tkinter) but i couldn't figured how to use both pi's. Maybe a cluster can solve my problem?

Someone Deleted the main question so I'm editing again : How can I use pins in a cluster ? What will be the pin numbers (like GPIO 20) ? If i connect two rasperry pi, second one's pin numbers start from 41 or what ? I'll use only one lan cable to control raspberrys so I want to know how would I name the pins.

The main goal is making an rc submarine so i need control 4-5 l298n motor driver and lots of sensors like temperature or distance.

An example code for controlling l298n motor driver :

import RPi.GPIO as gpio
import time

def init():
 gpio.setup(17, gpio.OUT)
 gpio.setup(22, gpio.OUT)

 gpio.setup(23, gpio.OUT)
 gpio.setup(24, gpio.OUT)

def pump():
 print ("Motor1 Forward Motor2 Off")
 #Motor1 (Forward)
 gpio.output(17, True)
 gpio.output(22, False)

#Motor2 (Off)
 gpio.output(23, False) 
 gpio.output(24, False)

def depump():
 print ("Motor1 Reverse Motor2 Off")
 #Motor 1 (Reverse)
 gpio.output(17, False)
 gpio.output(22, True)

#Motor2 (off)
 gpio.output(23, False) 
 gpio.output(24, False)

def stoppump():

As we see for two motor we need 4 pins, I need 8-10 motors.

  • You need to explain exactly what you want to do with all the pins -- clustering is probably not the answer, but we need to understand the goal before we can suggest a solution. – goldilocks Jul 15 '18 at 12:56
  • @goldilocks Thank you for your respond, i added more information i hope i explained clearly this time, if not please let me know. Greetings, Can – Can Jul 15 '18 at 15:10
  • Normally you are better off with three pins per motor (enable, A, and B - pwm goes to EN, A and B control the direction and type of braking), but I don't know if the extra control works well with a submarine. – NomadMaker Jul 15 '18 at 20:36
  • This is an XY problem you have an improbable solution to an ill-defined problem and want us to tell you how to implement it! – Milliways Jul 16 '18 at 0:06
  • If you can connect to one RPi, why can't you connect to a second one? – Dmitry Grigoryev Jul 17 '18 at 10:11

My suggestion would be to use sensors that communicate with i2c, with sensors that can have a different address assigned. Not all i2c devices can do this, so read the datasheet before you buy it.

You will have to make a small script, put one sensor in, assign it a new address, then repeat until you're finished. If possible mark each new sensor as soon as you've changed it.

If you really need more pins, I would get an Arduino clone to deal with the other sensors.

Two Raspberry Pi's in a cluster are still two Raspberry Pi's. They each would have their own pin numbers. I don't see that you gain anything by clustering them but a lot of overhead.

I would not try clustering just two Pi's. For one thing, it would probably end up being very expensive and not very effective. To build a cluster connected via Ethernet, you would need to get an Ethernet switch or router, plus cabling. If you wanted to share a monitor and keyboard, you'd need a KVM switch (Keyboard, Monitor, Mouse). Though once you have the cluster built and working, then you wouldn't need the keyboard, mouse, or monitor, except for debugging.

A single older PC would be more powerful and less costly. There are USB devices that have GPIO on them.

For motor control you would probably be better off with an Arduino clone or a dedicated PWM driver board. The Pi only 1 or 2 PWM pins that are accessible. You can use Pigpio or piblaster in order to create software pwm pins.

Have fun with your project!


Use (my) pigpio or gpiozero with pigpio as the back end.

Both will allow you to use a Python script on a laptop (Windows, Mac, Linux, Android, etc.) to control the GPIO of one or more Pis.

  • Thank you for your respond, someone edited the question and deleted the main object : How can I use pins in a cluster ? If i connect two rasperry pi, second one's pin numbers start from 41 or what ? I'll use only one lan cable to control raspberrys so I want to know how would I name the pins. Thanks ! – Can Jul 15 '18 at 18:25
  • The GPIO are numbered using Broadcom numbering, in effect GPIO 2-27 per Pi. In Python you instantiate a version of the GPIO for each Pi. pi1 might be, pi2 might be In each command you specify the Pi to be used (pi1, pi2 in this example), e.g. pi1.read(4), pi2.write(7, 0) – joan Jul 15 '18 at 18:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.