1

I am trying to run the following code on my Raspberry:

import pigpio 
import fileinput

pi = pigpio.pi()

### Define constants 
pwm_range = 255 
pwm_clock_div = 8 

left_motor_dir_pin = 35 
left_motor_pwm_pin = 32 

right_motor_dir_pin = 31 
right_motor_pwm_pin = 33 

left_motor_current_pin = 37
right_motor_current_pin = 29 

for pin in [left_motor_dir_pin, right_motor_dir_pin, left_motor_pwm_pin, right_motor_pwm_pin]:
    pi.set_mode(pin,pigpio.OUTPUT)

However this sends the following error:

 Traceback (most recent call last):
  File "gpio-test.py", line 20, in <module>
    pi.set_mode(pin,pigpio.OUTPUT)
  File "/home/pi/miniconda3/lib/python3.4/site-packages/pigpio.py", line 1296, in set_mode
    return _u2i(_pigpio_command(self.sl, _PI_CMD_MODES, gpio, mode))
  File "/home/pi/miniconda3/lib/python3.4/site-packages/pigpio.py", line 970, in _u2i
    raise error(error_text(v))
pigpio.error: 'no permission to update GPIO'

I started pigpiod with sudo pigpiod, it sends the same error with sudo.

Any idea why it behaves like this?

2

pigpio only uses Broadcom numbering for the GPIO.

You do not mention which Pi you are using but recent Pi's have 28 accessible GPIO numbered 0 to 27.

You appear to be using pin numbering.

You need to change the pin numbers to GPIO numbers.

http://abyz.me.uk/rpi/pigpio/index.html#Type_3

https://pinout.xyz/

0

In order for user pi to be able to access gpios without root permissions on a michine with the device tree disabled, udev rules are needed for both /sys/class/gpio and /sys/devices/virtual/gpio. They are needed for /sys/devices/virtual/gpio because the gpioN directories in /sys/class/gpio are links to the gpioN directories in /sys/devices/virtual/gpio. For example, see directory gpio4 here:

pi@raspberrypi /sys/class/gpio $ echo 4 > export 
pi@raspberrypi /sys/class/gpio $ ls -la
total 0
drwxrwx---  2 root gpio    0 Feb  7 20:11 .
drwxr-xr-x 38 root root    0 Feb  7 19:28 ..
-rwxrwx---  1 root gpio 4096 Feb  7 20:11 export
lrwxrwxrwx  1 root gpio    0 Feb  7 20:11 gpio4 -> ../../devices/virtual/gpio/gpio4
lrwxrwxrwx  1 root gpio    0 Jan  1  1970 gpiochip0 -> ../../devices/virtual/gpio/gpiochip0
-rwxrwx---  1 root gpio 4096 Feb  7 19:40 unexport
pi@raspberrypi /sys/class/gpio $ 

I can't think of a same reason to use /sys/devices/virtual/gpio in source code as /sys/class/gpio can always be used instead, if I'm not mistaken.

Note that this only functions when the device tree is disabled. When the device tree is enabled, /sys/devices/virtual/gpio disappears.

If the device tree is enabled, the udev rules on the Pi 2 need to use /sys/devices/soc/3f200000.gpio/gpio/ instead. The address 3f200000 may be different on the Pi 1, I'm not sure.

Note that /sys/devices/virtual/gpio is used in both /lib/udev/rules.d/60-python3-pifacecommon.rules and /lib/udev/rules.d/60-python-pifacecommon.rules in Raspbian. I've no idea how many users rely on this now.

  • Thanks, in my case it didn't work even with sudo, the answer above fixed it ! – Cendre Aug 10 '18 at 11:47

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.