Open Chambana opened 1 year ago
Your steps look correct at a glance. Have you rebooted your system or reloaded the udev rules? Try a simple reboot and the udev rule to grant GPIO access should be loaded.
This is something I can not fix, sadly. WiringOP must access /dev/mem, which requires root because it can directly read the system memory. From what I see, Orange Pi needs to update the wiringOP to read from /dev/gpiochip*.
Understood, was just going to provide an update that this is reproducible -- see below. I added the udev rule and rebooted (no dice). I added my user to the gpio group and even made that group owner of /dev/mem. I was surpised that even adding the gpio group as the group owner of the /dev/mem file didn't do the trick.
ubuntu@orangepi:~/scratch$ more /etc/udev/rules.d/99-gpio.rules
SUBSYSTEM==”gpio”, KERNEL==”gpiochip*”, ACTION==”add”, PROGRAM=”/bin/sh -c ‘chown root:gpio /sys/class/gpio/export /sys/clas
s/gpio/unexport ; chmod 220 /sys/class/gpio/export /sys/class/gpio/unexport’” SUBSYSTEM==”gpio”, KERNEL==”gpio*”, ACTION==”a
dd”, PROGRAM=”/bin/sh -c ‘chown root:gpio /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value ; chmod 660 /sys%p/act
ive_low /sys%p/direction /sys%p/edge /sys%p/value’”
ubuntu@orangepi:~/scratch$ groups ubuntu
ubuntu : ubuntu adm dialout cdrom floppy sudo audio dip video plugdev netdev lxd gpio
ubuntu@orangepi:~/scratch$ ls -la /dev/mem
crw-rw---- 1 root gpio 1, 1 Jun 25 22:21 /dev/mem
ubuntu@orangepi:~/scratch$ python3
Python 3.10.6 (main, May 29 2023, 11:10:38) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import wiringpi
>>> wiringpi.wiringPiSetupPhys()
wiringPiSetup: Unable to open /dev/mem or /dev/gpiomem: No such file or directory.
Aborting your program because if it can not access the GPIO
hardware then it most certianly won't work
Try running with sudo?
ubuntu@orangepi:~/scratch$ sudo python3
Python 3.10.6 (main, May 29 2023, 11:10:38) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import wiringpi
>>> wiringpi.wiringPiSetupPhys()
0
>>>
After chasing around a little with this myself, I came to the conclusion that another solution to this is to use libgpiod and move on. I am using C, so I don't know about Python, etc. The GPIOs I have gotten to work are split between gpiochip1 and gpiochip3 You just have to add a udev rule to sort out access to /dev/gpiochipX pin 40 on the connector is gpiochip3, pin 3 38 is gpiochip3, pin 4 36 is gpiochip3, pin 5 32 is gpiochip1, pin 3 I only needed a few - these are the ones I worked out but it seems like the rest are following a similar convention. according to wiringpi, 'gpio readall' the name of pin 40 is GPIO3_A3 and that is gpiochip3 pin 3. Hope this helps someone trying to work around this. Cheers.
I've tried a few methods to enable user level access to GPIO and they're not working with the latest image of 22.04 from this repo running on an Orange Pi 5b.
I'm only able to run wiringPi python scripts as sudo. If I run as user, this is the error:
I followed this guide from the OPi.GPIO docs:
I've tried a few other suggestions, but nothing has worked. Please post a method for enabling user-level access to GPIO on the OrangePi using this repo. Happy to wipe my install and do a clean test if there are documented steps to do so.