Unable to use hardware PWM without sudo due to permissions for /dev/gpiomem


#1

I am trying to use wiringPi and also wiringPi python to generate hardware PWM. However, I get a permissions error with this code:

import wiringpi
wiringpi.pinMode(1, wiringpi.GPIO.PWM_OUTPUT)
wiringpi.pwmWrite(1, 0)

here is the error:

pinMode PWM: Unable to do this when using /dev/gpiomem. Try sudo?

Looking at the permissions with ls -al /dev/gpiomem, I get

crw-rw---- 1 root gpio 243, 0 Feb 11 2016 /dev/gpiomem

That says the rw permissions are there for the group. That is consistent with the udev rule that should extend those permissions within 99-com.rules:

SUBSYSTEM=="bcm2835-gpiomem", GROUP="gpio", MODE="0660"

and I am a member of the gpio group.

adm dialout sudo video input netdev ssl-cert nopasswdlogin spi i2c gpio

Any suggestions?


#2

I switched to RPi.GPIO and it works out-of-the-box without sudo. I don’t know why wiringPi has an issue.


#3

Not sure either.

But that error message seems to imply that whatever mechanism used by wiring pi for PWM requires /dev/mem (root only) not just /dev/gpiomem

Rohan


#4

Even changing permissions on all of /dev/mem did not resolve the problem for wiringPi, but since RPi.GPIO works, it is a non-issue.