"Not running on a RPi" message from GPIO.setup(id, GPIO.IN) on new RPi4B
A Python module to control the GPIO on a Raspberry Pi
Brought to you by:
croston
Minmal code example. Happens with Python2 and Python3. Looks to be in the Cython binary.
Produces the message "Not running on an RPi" on the Pi4B.
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM) # Use BCM pins D4 = GPIO #4
GPIO.setwarnings(True) # shh!
id = 18 # BCM GPIO 18 I assume this doesn't matter because we don't get far.
GPIO.setup(id, GPIO.IN) # Hits exception: RuntimeError: Not running on a RPi!
Hmmmm. This goes away when I use sudo. I believe I'm always supposed to use sudo because I haven't used any setuid or group hacks.
You need a new constant for the Pi 4B in py_gpio.c. I don't understand why I get the "not an RPi" message when not using sudo. I suspect some logic is amiss.
I can confirm that behavior on the Raspberry Pi 4 (4GB).
Running with sudo works.
Let me know if I can assist in order to fix this.
I am having this issue too. Here is some information. Let me know if I can provide any additional information (in this case, it is run as root and still failing) - or any suggestions to get running.
John
[root@ff-ast ~]# pip show RPIO | grep Version
Version: 0.10.0
[root@ff-ast ~]# head -9 /proc/cpuinfo
processor : 0
BogoMIPS : 38.40
Features : fp asimd evtstrm crc32 cpuid
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd03
CPU revision : 4
[root@ff-ast ~]# echo $(cat /proc/device-tree/model)
-bash: warning: command substitution: ignored null byte in input
Raspberry Pi 3 Model B
[root@ff-ast ~]# uname -a
Linux ff-ast 5.5.0-1-ARCH #1 SMP Tue Jan 28 02:39:20 UTC 2020 aarch64 GNU/Linux
[root@ff-ast ~]# ./piplatectl
Traceback (most recent call last):
File "./piplatectl", line 7, in <module>
import piplates.RELAYplate as RELAY
File "/usr/lib/python3.8/site-packages/piplates/RELAYplate.py", line 7, in <module>
import RPi.GPIO as GPIO
File "/usr/lib/python3.8/site-packages/RPi/GPIO/init.py", line 23, in <module>
from RPi._GPIO import *
RuntimeError: This module can only be run on a Raspberry Pi!</module></module></module>
Sorry, I pasted the version for the wrong package.
RPi.GPIO=0.7.0
Got the same problem with Ubuntu 20.04 on RPi 4. Resolved it by creating a "gpio" group, and adding an udev rule to give this group access to "/dev/gpiomem" (normally can only be accessed by root).
Create
/etc/udev/rules.d/90-gpio.rules
with:Create the group itself and assign it to an existing user "pi":
"/dev/gpiomem" should be writeable on the next boot.
Thank you! Not only a solution but an explanation!
I am continuing to get the Runtime error: Not running on a RPi. I am using a Raspberry pi 4B with Ubuntu Mate 20.04. I was using the same simple code on my old 3B+ and it worked fine. I have tried adding the username to the gpio group and it did not fix the issue. I have tried gpiozero and get the same error. Not sure what to do now as I read a lot of other people with the same issue but have not yet found a solution that works for me. Thanks.
code is below:
import RPi.GPIO as GPIO
from hx711 import HX711
hx = HX711(5, 6)
hx.set_reading_format("MSB", "MSB")
hx.set_reference_unit(105)
hx.reset()
hx.tare()
abc=input("scale is tared, press enter to start ->")
endloop = 10 #number of times to run the code
for k in range(endloop):
total = 0
endrange = 10 #number of readings to average
for i in range(endrange):
val = hx.get_weight(5)
total = val + total
hx.power_down()
hx.power_up()
time.sleep(0.1)
here is the error:
runfile('/home/4di/.config/spyder-py3/weightgpio.py', wdir='/home/4di/.config/spyder-py3')
/usr/lib/python3/dist-packages/gpiozero/pins/pi.py:129: SPISoftwareFallback: failed to initialize hardware SPI, falling back to software (error was: failed to import spidev)
warnings.warn(
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/gpiozero/devices.py", line 69, in call
self = cls._instances[key]
KeyError: (8,)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/gpiozero/pins/pi.py", line 71, in pin
pin = self.pins[n]
KeyError: 8
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "", line 1, in
runfile('/home/4di/.config/spyder-py3/weightgpio.py', wdir='/home/4di/.config/spyder-py3')
File "/usr/lib/python3/dist-packages/spyder_kernels/customize/spydercustomize.py", line 827, in runfile
execfile(filename, namespace)
File "/usr/lib/python3/dist-packages/spyder_kernels/customize/spydercustomize.py", line 110, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "/home/4di/.config/spyder-py3/weightgpio.py", line 4, in
spi = HX711()
File "/usr/lib/python3/dist-packages/gpiozero/devices.py", line 95, in call
self = super(GPIOMeta, cls).call(args, *kwargs)
File "/home/4di/.local/lib/python3.8/site-packages/hx711_gpiozero/init.py", line 19, in init
super().init(bits, max_voltage, **spi_args)
File "/usr/lib/python3/dist-packages/gpiozero/spi_devices.py", line 128, in init
super(AnalogInputDevice, self).init(shared=True, **spi_args)
File "/usr/lib/python3/dist-packages/gpiozero/spi_devices.py", line 34, in init
self._spi = self.pin_factory.spi(**spi_args)
File "/usr/lib/python3/dist-packages/gpiozero/pins/pi.py", line 142, in spi
return self.spi_classes('software', shared)
File "/usr/lib/python3/dist-packages/gpiozero/devices.py", line 72, in call
self = super(GPIOMeta, cls).call(args, *kwargs)
File "/usr/lib/python3/dist-packages/gpiozero/pins/local.py", line 152, in init
super(LocalPiSoftwareSPI, self).init(select_pin, active_high=False)
File "/usr/lib/python3/dist-packages/gpiozero/output_devices.py", line 47, in init
super(OutputDevice, self).init(pin, pin_factory=pin_factory)
File "/usr/lib/python3/dist-packages/gpiozero/mixins.py", line 69, in init
super(SourceMixin, self).init(args, *kwargs)
File "/usr/lib/python3/dist-packages/gpiozero/devices.py", line 375, in init
pin = self.pin_factory.pin(pin)
File "/usr/lib/python3/dist-packages/gpiozero/pins/pi.py", line 73, in pin
pin = self.pin_class(self, n)
File "/usr/lib/python3/dist-packages/gpiozero/pins/rpigpio.py", line 101, in init
GPIO.setup(self.number, GPIO.IN, self.GPIO_PULL_UPS[self._pull])
RuntimeError: Not running on a RPi!
I've changed the board detection method in 0.7.1a4. Does it work now?
Hi Ben, with Ubuntu 20.04 on RPi 4, the message is now more descriptive:
When running as root or after changing the permissions (see my comment above) GPIO seems to work OK.
The remaining source of confusion might be that
/dev/mem
doesn't actually exist on my system. RPi.GPIO only complains about it because it's what was used as a fallback, but the underlying issue are in fact/dev/gpiomem
permissions.I.e. this assumption in
c_gpio.c
may not be true:// try /dev/gpiomem first - this does not require root privs
So ideally the error should say something like: "No access to /dev/gpiomem or /dev/mem. Try running as root!" Or some more advanced logic could be added.
Good job overall though. :-)
I can confirm that it's fixed in 0.7.1a4 with
Hardware : BCM2711
Revision : c03114
Model : Raspberry Pi 4 Model B Rev 1.4
It wasn't working with 0.7.0
Fixed in 0.7.1