Raspberry Pi New User Cannot Access GPIO

When a new Raspberry Pi user tries to access GPIO through WiringPi, the program may stop with an error like this:

wiringPiSetup: Unable to open /dev/mem or /dev/gpiomem: Permission denied.
Aborting your program because if it can not access the GPIO
hardware then it most certainly won't work
Try running with sudo?

The usual fix is to add the user to the gpio group:

sudo usermod -a -G gpio user_name

Replace user_name with the actual login name. After changing group membership, log out and log back in, or reboot, so the new group is applied. You can check the active groups with:

groups

If /dev/gpiomem still has the wrong permissions, reset its owner, group, and group write permission:

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

If the problem is still unsolved and you are running the script inside a Python virtual environment, deactivate the virtual environment and test again from a normal shell. The issue may be caused by how the script is being launched rather than by GPIO permissions themselves.

As a last resort, some programs try to access /dev/mem directly instead of /dev/gpiomem. In that case, you can apply the same group ownership and permission pattern to /dev/mem:

sudo chown root:gpio /dev/mem
sudo chmod g+rw /dev/mem

Be careful with /dev/mem: it gives much broader access to system memory than /dev/gpiomem. Prefer /dev/gpiomem when the library supports it.

These two commands are equivalent ways to add a user to a group:

sudo usermod -a -G target_group user_name
sudo adduser user_name target_group

For example, these commands both add user_name to the gpio group:

sudo usermod -a -G gpio user_name
sudo adduser user_name gpio

Leave a Reply