GPIO permission problem [SOLVED]

This forum is for topics dealing with problems with software specifically in the AArch64 repo.

GPIO permission problem [SOLVED]

Postby surdo » Fri Apr 05, 2024 6:19 pm

I recently upgraded an old project and I'm running into problems with the following python script:

[code]import RPi.GPIO as GPIO
import time
import subprocess

GPIO.setmode(GPIO.BCM)

GPIO.setup(27, GPIO.IN, pull_up_down=GPIO.PUD_UP)

while True:
input_state = GPIO.input(27)
if input_state == False:
print('Button Pressed')
subprocess.call(['sh', '/home/me/scripts/calibrate.sh'])
time.sleep(0.9)

[/code]


The script balks on the line:

[code]GPIO.setup(27, GPIO.IN, pull_up_down=GPIO.PUD_UP)[/code]

And shows the following error message:

[code]RuntimeError: No access to /dev/mem. Try running as root![/code]

I tired the following. It fixes the problem however the permissions get reset on reboot.

[code]
sudo chown root:gpio /dev/gpiomem
sudo chmod g+rw /dev/gpiomem[/code]

Any suggestions, please?
Last edited by surdo on Mon Apr 08, 2024 11:07 am, edited 1 time in total.
surdo
 
Posts: 8
Joined: Thu Mar 18, 2021 4:20 pm

Re: GPIO permission problem

Postby mkbodanu4 » Sun Apr 07, 2024 9:44 pm

I had the same problem and found this info:
make_clickable_callback(MAGIC_URL_FULL, '
', 'https://github.com/raspberrypi/linux/issues/5625', '', ' class="postlink"')

Update your udev rules to the next to get it working.

[code]SUBSYSTEM=="gpiomem", GROUP="gpio", MODE="0660"[/code]

GROUP must be gpio or tty, depends how your system was configured earlier.
mkbodanu4
 
Posts: 1
Joined: Sun Apr 07, 2024 9:40 pm

Re: GPIO permission problem [SOLVED]

Postby surdo » Mon Apr 08, 2024 11:07 am

Thanks a lot @mkbodanu4. That fixed it. Yes, my user is in the gpio group. I created the file /usr/lib/udev/rules.d/99-spi-permissions.rules and added the following as per the updated udev rule file in the first post of the link you sent:

[code]
SUBSYSTEM=="*gpiomem*", GROUP="gpio", MODE="0660"

SUBSYSTEM=="gpio", GROUP="gpio", MODE="0660"
SUBSYSTEM=="gpio*", PROGRAM="/bin/sh -c '\
chown -R root:gpio /sys/class/gpio && chmod -R 770 /sys/class/gpio; \
chown -R root:gpio /sys/devices/virtual/gpio && \
chmod -R 770 /sys/devices/virtual/gpio; \
chown -R root:gpio /sys$devpath && chmod -R 770 /sys$devpath \
'"
[/code]
surdo
 
Posts: 8
Joined: Thu Mar 18, 2021 4:20 pm


Return to ARMv8

Who is online

Users browsing this forum: No registered users and 8 guests