Uncategorized

gpiozero discussions

gpiozero on a pi4?

Ask QuestionAsked todayActive todayViewed 23 times0

Working on getting some working samples setup for my son on his RPI4 so he can play with the GPIO’s, breadboard, and some various pieces to use with the breadboard. Right now we’re trying to test out a RGB LED, and are using the gpiozero library in python3

Note that I did not install the gpiozero library, I was just playing with some code samples I found online to get it up and running for him quickly and realized the library came packaged with the PI OS already. However, now I’m confused as to why it thinks it’s not running on a RPI? Looking at the docs it appears that gpiozero should run on all Pi’s, but it has zero in the name, is this only compatible with a Pi zero?

This is what I’m running. Note that this is a snippet of the full script, I reduced it to 2 lines to reproduce the error, but the error below lists it as line 10 from the file(10 = 2 in my sample below)

from gpiozero import RGBLED
led = RGBLED(red=18, green=23, blue=24)

And getting this error

Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/gpiozero/pins/pi.py", line 109, in pin
    pin = self.pins[n]
KeyError: 18

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "04_cheerlights.py", line 10, in <module>
    led = RGBLED(red=18, green=23, blue=24)
  File "/usr/lib/python3/dist-packages/gpiozero/devices.py", line 124, 
in __call__
    self = super(GPIOMeta, cls).__call__(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/gpiozero/output_devices.py", 
line 901, in __init__
    for pin in (red, green, blue)
  File "/usr/lib/python3/dist-packages/gpiozero/output_devices.py", 
line 901, in <genexpr>
    for pin in (red, green, blue)
  File "/usr/lib/python3/dist-packages/gpiozero/devices.py", line 124, 
in __call__
    self = super(GPIOMeta, cls).__call__(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/gpiozero/output_devices.py", 
line 414, in __init__
    pin, active_high, initial_value=None, pin_factory=pin_factory
  File "/usr/lib/python3/dist-packages/gpiozero/output_devices.py", 
line 93, in __init__
    super(OutputDevice, self).__init__(pin, pin_factory=pin_factory)
  File "/usr/lib/python3/dist-packages/gpiozero/mixins.py", line 106, 
in __init__
    super(SourceMixin, self).__init__(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/gpiozero/devices.py", line 521, 
in __init__
    pin = self.pin_factory.pin(pin)
  File "/usr/lib/python3/dist-packages/gpiozero/pins/pi.py", line 111, 
in pin
    pin = self.pin_class(self, n)
  File "/usr/lib/python3/dist-packages/gpiozero/pins/rpigpio.py", line 
132, in __init__
     GPIO.setup(self.number, GPIO.IN, self.GPIO_PULL_UPS[self._pull])
RuntimeError: Not running on a RPi!

Also, here’s my OS version info

cat /etc/os-release 
PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

uname

uname -a
Linux *hostname* 4.19.97-v7l+ #1294 SMP Thu Jan 30 13:21:14 GMT 2020 armv7l GNU/Linux

gpiopythonpi-4gpiozeroshareedit  follow  close 1flagedited 5 hours agoasked 5 hours agouser324669310922 bronze badges

  • 1If you want help you have to LIST YOUR CODE. You also should explain what you have connected. – Milliways 4 hours ago
  • 1the 2 lines of code that generate the error are included in the post. What else are you looking for? – user3246693 3 hours ago
  • 1As an experiment try using a different backend – joan 3 hours ago
  • 1Those 2 lines of code are insufficient for anyone to run your code and test – they run BUT DO NOTHING! Unless you post a working piece of code (which can be a minimal set to demonstrate the problem) no one can help. – Milliways 3 hours ago
  • 1yeah, I get that they do nothing, however on my system they generate the error I am trying to fix, which makes the rest of the code irrelevant. – user3246693 3 hours ago
  • 1They run on my Pi. Mayne you need to explain HOW you are trying to run them. – Milliways 3 hours ago
  • 1Joan, when you say use a different backend, what are you referring to by “backend”? – user3246693 3 hours ago
  • 1python3 myscript.py – user3246693 3 hours ago
  • 1The backend actually talks to the GPIO. Typically it would be RPi.GPIO or pigpio. Try setting a different pin factory. – joan 2 hours ago
  • $user3246693 , Welcome and nice to meet you. Ah, let me see. I agree with you that two lines of code is just enough. More lines more trouble. – tlfong01 1 hour ago   
  • $user3246693, you might like to see how my two lines run: imgur.com/CVW6yfk. PS – I don’t have any RGB LED. I just did a fake run. 🙂 Cheers. – tlfong01 1 hour ago    
  • $user3246693, I skimmed the error message and found the last line interesting: “RuntimeError: Not running on a RPi!“. Is your Rpi a fake one? 🙂 – tlfong01 1 hour ago   
  • 2Is your OS fully updated? ‘sudo apt update‘ ‘sudo apt full-upgrade -y’ I suspect RPi.GPIO is out of date. – CoderMike 1 hour ago
  • 1@Milliways they are (you can see it in the stack trace). gpiozero uses RPi.GPIO underneath (by default). As the author of gpiozero I’d agree this is the most likely issue. – ben_nuttall 13 mins ago

add a comment

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.