1

I am running Ubuntu Server 20.04.02 LTS in my RPi 4b. I ran into the problem that I couldn't access the GPIO without sudo/root with my python scripts so I changed the /dev/gpiomem group ownership to my user's groups with

sudo chown root:$USER /dev/gpiomem

and allowed read and write access to /dev/gpiomem with

sudo chmod g+rw /dev/gpiomem

which solved the problem. However once I reboot these changes somehow get undone and I have to redo them in order to run my code without root access. Can someone help me with this? Thanks!

2
  • Oh okay, thanks for the info. I added what I did in the post now. But I don't really know about the groups (I'm VERY new to this). I don't really know what would be relevant as additional information here. Apr 28, 2021 at 9:17
  • The "files" in /dev aren't real files. They only exist in memory, which is to say, when the system is running. When you (re)boot, the kernel creates them appropriately (we hope). So you have to automate the change you want.
    – goldilocks
    May 28, 2021 at 16:14

2 Answers 2

1

The correct solution is probably to add your user to the group which is allowed to access /dev/gpiomem

$ ls -l /dev/gpiomem
crw-rw---- 1 root gpio 246, 0 Apr 28 13:17 /dev/gpiomem

On Raspbian it is gpio.

Hopefully it is similar on Ubuntu.

Then add your user to that group.

Assuming the Ubuntu equivalent to Raspbian's gpio is ubuntu-gpio do the following command.

sudo adduser pi ubuntu-gpio

Note you have to log out afterwards and log back in for the group change to take effect.

If that doesn't make sense please edit your question and include the output of the ls -l /dev/gpiomem command.

0

EDIT 2022-10-24 I recently installed Ubuntu 22.04.1 LTS on my 2GiB Pi4 (as there was finally a "supported" image which would run).

I have adapted most of my gpio code to run on this.

One major difference was /dev/gpiomem which has permissions crw-rw---- 1 root dialout - there is NO gpio group (why is a mystery as it has nothing to do with dialout).

Rather than trying to modify Ubuntu I just included my gpio users in dialout.


You really haven't provided enough information to make any reasonable deduction. In particular you haven't said what the permissions of /dev/gpiomem are.

Changing permissions on a /dev/ doesn't change anything for future boots. This needs to be set in kernel or Device Tree

I am not familiar with Ubuntu Server, while I have been a Ubuntu user for 20 years, their Pi implementation uses their own kernel which has limitations compared to the Foundation implementation and while the last Server I tried works OK it is a resource hog so I have given up and just use Raspberry Pi OS - which works and strangely is well adapted to the Pi hardware.

It would seem to be unusual for a Server to implement GPIO access. At least they do seem to have implemented /dev/gpiomem (which has been in Raspbian since 2015) but not set permissions to make it usable.

Raspberry Pi OS sets groups/ownership to group gpio using udev

crw-rw---- 1 root gpio 246, 0 2021-04-26 11:46 /dev/gpiomem

See http://wiringpi.com/wiringpi-update-to-2-29/ for an example which you could adapt.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.