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