Skip to content

Instantly share code, notes, and snippets.

@bennuttall bennuttall/
Last active Oct 26, 2019

What would you like to do?
Set up a Pi and host PC for remote GPIO access using gpiozero

Remote GPIO

GPIO Zero allows you to create objects representing GPIO devices. As well as running it on a Raspberry Pi, you can also install GPIO Zero on a PC and create objects referencing GPIO pins on a Pi over the network.

To do this, you'll need to do a few things to get set up:

  1. Enable Remote GPIO on the Pi in the Raspberry Pi Configuration Tool.

  2. Run the pigpio daemon on the Pi:

    • sudo pigpiod
  3. Get the Pi's IP address:

    • hostname -I
  4. Install gpiozero and pigpio on your host machine (not necessary on Raspbian or x86 PIXEL):

    • Install pip: sudo apt install python3-pip
    • Install gpiozero and pigpio: sudo pip3 install gpiozero pigpio
  5. Run your Python environment with the PIGPIO_ADDR environment variable set, e.g one of the following:

    • PIGPIO_ADDR= ipython3
    • PIGPIO_ADDR= python3
    • PIGPIO_ADDR= idle3 &

    If running on a Raspberry Pi, you also need to set the pin factory to PiGPIOPin:

  6. Now use GPIO Zero like normal, and the devices will be controlled by GPIO pins on the remote Pi:

    >>> from gpiozero import LED
    >>> led = LED(2)
    >>> led.blink()  # LED on remote Pi's pin 2 now blinking

    Alternatively, use pin objects as described in the pins documentation.


This comment has been minimized.

Copy link
Owner Author

bennuttall commented Dec 20, 2016

Note that this also works on PC and Mac - I'm just not up on how you install pip, git clone and such on those platforms. If anyone can help out and reproduce these instructions for other platforms I'd appreciate it!


This comment has been minimized.

Copy link

alexanderdixon commented Dec 21, 2016

Nice. Would this work accessing more than 1 rpi remotely, i.e. A handful of rpis gpio being used from a central point for event detection or something?


This comment has been minimized.

Copy link
Owner Author

bennuttall commented Dec 21, 2016

Yes - that works too. You can either run different scripts for each Pi, and use the environment variable as above, or to use them in the same script, use one as your "default" IP, and either create pin instances on the IP:

from gpiozero import LED
from gpiozero.pins.pigpiod import PiGPIOPin

pin_a = PiGPIOPin(2, host='')  # reference to pin 2 on a different Pi
pin_b = PiGPIOPin(2, host='')  # reference to pin 2 on another Pi

red = LED(2)  # led on this Pi
green = LED(pin_a)  # led on different Pi
blue = LED(pin_b)  # led on another Pi

or I think you should be able to set the IP when changing the default pin factory in between creating devices, but I'm not certain on how this can be done (see #279).

See and

An example:

from gpiozero import LED, Button
from gpiozero.pins.pigpiod import PiGPIOPin
from signal import pause

# set up references to pins on two different Pis
pin_a = PiGPIOPin(2, "")
pin_b = PiGPIOPin(2, "")

# create buttons connected to remote Pis
button_a = Button(pin_a)
button_b = Button(pin_b)

# create LEDs on this Pi
led_a = LED(2)
led_b = LED(3)

# the LEDs on this Pi should be on when the (remote) buttons are pressed
led_a.source = button_a.values
led_b.source = button_b.values


Not the most thrilling example, but you get the idea!

Note: of course you can nest the pin reference so it's in one line without a separate pin object:

led = LED(PiGPIOPin(2, host=""))

This comment has been minimized.

Copy link

annagat commented Mar 21, 2018


I am trying to run this pigpio in Windows 7. I am confused on #5. Where do I supposed to run them or how do I use those commands. I tried the command in cmd but it says

'PIGPIO_ADDR' is not recognized as an internal or external command,operable program or batch file.

Here is the code I am trying to run.

`from gpiozero.pins.pigpio import PiGPIOFactory
from gpiozero import LED
from time import sleep

device_ip = ''
factory = PiGPIOFactory(device_ip)
remote_gpio = LED(17, pin_factory=factory) # remote button

while True:

Any help will be much appreciated.


This comment has been minimized.

Copy link

k4mrul commented May 25, 2018

For windows, to set environment variable, execute:

set PIGPIO_ADDR=ip_address_of_your_pi

Full code:

import os
from time import sleep
os.environ["PIGPIO_ADDR"] = "ip_address_of_your_pi"
os.environ["GPIOZERO_PIN_FACTORY"] = "pigpio"
from gpiozero import LED

gpio_pin = 26   #we are using gpio 26
led = LED(gpio_pin)  
while True: 

Anyway, thank @bennuttall :)


This comment has been minimized.

Copy link

lemonkey commented Jul 20, 2018

Note: setting the environment variable GPIOZERO_PIN_FACTORY was required on macOS as well, even though the documentation states in that after setting the environment variable PIGPIO_ADDR:

If you are running this from a PC (not a Raspberry Pi) with gpiozero and the pigpio Python library installed, this will work with no further configuration. However, if you are running this from a Raspberry Pi, you will also need to ensure the default pin factory is set to PiGPIOFactory.

Otherwise you'll get something similar when trying to import the gpiozero library from a python script run on macOS, etc.

gpiozero/ PinFactoryFallback: Falling back from rpigpio: No module named 'RPi'
  'Falling back from %s: %s' % (name, str(e))))
gpiozero/ PinFactoryFallback: Falling back from rpio: No module named 'RPIO'
  'Falling back from %s: %s' % (name, str(e))))

This comment has been minimized.

Copy link

lemonkey commented Jul 20, 2018


In I believe there is a typo:

Instead of from gpiozero.pins.pigpiod import PiGPIOPin it should be from gpiozero.pins.pigpio import PiGPIOPin.

Per the docs under

pigpio | gpiozero.pins.pigpio.PiGPIOFactory | gpiozero.pins.pigpio.PiGPIOPin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.