1

I'm trying to run a remote GPIO code from a Linux machine to operate on RPI3.

Code is running OK on another RPI3 to control each other, but when trying to do so from a PC, it fails.

I followed the gpiozero doc, and install as described, with no success.

As an example, I try to run this simple code on RPI3 with an IP address 192.168.2.113:

from gpiozero import LED, Button
from gpiozero.pins.pigpio import PiGPIOFactory
from signal import pause

factory = PiGPIOFactory(host='192.168.2.113')

button = Button(2)
led = LED(17, pin_factory=factory)

led.source = button.values

pause()

and I get this error:

/home/guy/venv/untitled/bin/python /home/guy/Documents/github/Rpi/GPIO_Projects/gpio_from_desktop.py
/home/guy/venv/untitled/lib/python3.6/site-packages/gpiozero/devices.py:452: PinFactoryFallback: Falling back from rpigpio: No module named 'RPi'
  'Falling back from %s: %s' % (name, str(e))))
/home/guy/venv/untitled/lib/python3.6/site-packages/gpiozero/devices.py:452: PinFactoryFallback: Falling back from rpio: No module named 'RPIO'
  'Falling back from %s: %s' % (name, str(e))))
/home/guy/venv/untitled/lib/python3.6/site-packages/gpiozero/devices.py:452: PinFactoryFallback: Falling back from pigpio: No module named 'pigpio'
  'Falling back from %s: %s' % (name, str(e))))
/home/guy/venv/untitled/lib/python3.6/site-packages/gpiozero/devices.py:452: PinFactoryFallback: Falling back from native: unable to open /dev/gpiomem or /dev/mem; upgrade your kernel or run as root
  'Falling back from %s: %s' % (name, str(e))))
Traceback (most recent call last):
  File "/home/guy/Documents/github/Rpi/GPIO_Projects/gpio_from_desktop.py", line 1, in <module>
    from gpiozero import LED, Button
  File "/home/guy/venv/untitled/lib/python3.6/site-packages/gpiozero/__init__.py", line 22, in <module>
    from .devices import (
  File "/home/guy/venv/untitled/lib/python3.6/site-packages/gpiozero/devices.py", line 486, in <module>
    Device.pin_factory = _default_pin_factory()
  File "/home/guy/venv/untitled/lib/python3.6/site-packages/gpiozero/devices.py", line 453, in _default_pin_factory
    raise BadPinFactory('Unable to load any default pin factory!')
gpiozero.exc.BadPinFactory: Unable to load any default pin factory!

Process finished with exit code 1

What is missing here?

  • Did you pip install pigpio on the WIndows box? Did you set the needed environment variables? – joan May 19 '18 at 13:54
  • @joan- a) pigpio: installed using pip. b) it is a linux machine c)enviroment vars- no. how ? – Guy . D May 19 '18 at 14:32
  • 1
    No module named 'RPi' .... you do not have the correct modules installed – jsotola May 19 '18 at 22:39
  • @jsotola - after installation on RPI.GPIO and RPIO - still same error – Guy . D May 20 '18 at 4:48
  • @joan - can you please exaplain how to use those enviroment variables? – Guy . D May 20 '18 at 4:49
1

You say that you have installed the modules on your Linux box, but not set the Environment variables.

From 4. Configuring Remote GPIO

4.3. Environment variables

The simplest way to use devices with remote pins is to set the PIGPIO_ADDR environment variable to the IP address of the desired Raspberry Pi. You must run your Python script or launch your development environment with the environment variable set using the command line. For example, one of the following:

$ PIGPIO_ADDR=192.168.1.3 python3 hello.py
$ PIGPIO_ADDR=192.168.1.3 python3
$ PIGPIO_ADDR=192.168.1.3 ipython3
$ PIGPIO_ADDR=192.168.1.3 idle3 &

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. If RPi.GPIO is installed, this will be selected as the default pin factory, so either uninstall it, or use another environment variable to set it to PiGPIOFactory:

$ GPIOZERO_PIN_FACTORY=pigpio PIGPIO_ADDR=192.168.1.3 python3 hello.py

This usage will set the pin factory to PiGPIOFactory with a default host of 192.168.1.3. The pin factory can be changed inline in the code, as seen in the following sections.

With this usage, you can write gpiozero code like you would on a Raspberry Pi, with no modifications needed. For example:

from gpiozero import LED
from time import sleep

red = LED(17)

while True:
    red.on()
    sleep(1)
    red.off()
    sleep(1)

When run with:

$ PIGPIO_ADDR=192.168.1.3 python3 led.py

will flash the LED connected to pin 17 of the Raspberry Pi with the IP address 192.168.1.3. And:

$ PIGPIO_ADDR=192.168.1.4 python3 led.py

will flash the LED connected to pin 17 of the Raspberry Pi with the IP address 192.168.1.4, without any code changes, as long as the Raspberry Pi has the pigpio daemon running.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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