0

I'm coding on Rpi3 using python3. When trying to run a code, containing a gpiozero lib - it fails when running on RpiZero, while succeeds on Rpi3.

RpiZero contains gpiozero lib

Trying to find the reason- I simplified the code into:

#import LocalSwitch
import time
import gpiozero
from signal import pause
#time.sleep(3)

for x in range(10):
    print(x)

a = gpiozero.Button(11)
#b = gpiozero.Buzzer(4)


pause()

EDIT 1 OS installed:

Linux rpi2 4.9.59+ #1047 Sun Oct 29 11:47:10 GMT 2017 armv6l GNU/Linux

EDIT 2 - Run as SU

Runs as needed

yields this error:

guy@rpi2:~/Documents/github/Rpi/SmartHome $ python3 tst.py 
0
1
2
3
4
5
6
7
8
9
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/gpiozero/pins/pi.py", line 71, in pin
    pin = self.pins[n]
KeyError: 11

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "tst.py", line 13, in <module>
    a = gpiozero.Button(11)
  File "/usr/lib/python3/dist-packages/gpiozero/devices.py", line 95, in __call__
    self = super(GPIOMeta, cls).__call__(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/gpiozero/input_devices.py", line 303, in __init__
    pin, pull_up, bounce_time, pin_factory=pin_factory
  File "/usr/lib/python3/dist-packages/gpiozero/mixins.py", line 338, in __init__
    super(HoldMixin, self).__init__(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/gpiozero/input_devices.py", line 95, in __init__
    pin, pull_up, pin_factory=pin_factory
  File "/usr/lib/python3/dist-packages/gpiozero/mixins.py", line 164, in __init__
    super(EventsMixin, self).__init__(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/gpiozero/input_devices.py", line 46, in __init__
    super(InputDevice, self).__init__(pin, pin_factory=pin_factory)
  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: No access to /dev/mem.  Try running as root!

Any ideas why ??

guyd
  • 578
  • 3
  • 13
  • 28
  • Did you see this message? RuntimeError: No access to /dev/mem. Try running as root!. Try to run this program as root – bierschi Mar 01 '18 at 07:38
  • And why should it be run as root? – guyd Mar 01 '18 at 08:46
  • It should't need to be run as root. However the error log suggests you try that. If it runs as root it may help in knowing what is wrong. If you use the SD card from the one which works does it work in the other? What operating system are you using on each? – joan Mar 01 '18 at 08:48
  • @joan - I don't same SD since one is RPi3 and other is RpiZero. I use git. as you can see code is as simple as it can be. OS type is added to Q. – guyd Mar 01 '18 at 11:51
  • That doesn't address the question. Does it work when run as root? Does it work properly when the SD card from the Pi3 is inserted in the Pi Zero. Presumably you are using a recent Raspbian? – joan Mar 01 '18 at 11:55
  • @joan 1) as root it is working as expected. 2) recent Raspbian it is. 3) about the SD - not same SD – guyd Mar 01 '18 at 12:12
  • https://raspberrypi.stackexchange.com/questions/40105/access-gpio-pins-without-root-no-access-to-dev-mem-try-running-as-root – guyd Mar 01 '18 at 13:11

0 Answers0