3

I am attempting to get a c++ program to access the gpio as non-root. I am on a raspi 2 running Jessie. I followed the instructions on issue: Access GPIO pins without root. No access to /dev/mem. Try running as root! For some reason, it still doesn't work after adding user to the gpio group and ensuring the correct permissions/owners. It says

can't open /dev/mem: : Permission denied

Am i supposed to change permissions to /dev/mem? I've read that it is a security concern so I would like to avoid it. The only think i didn't do was update the kernel to 4.4 (at 4.1.19-v7+) since it looks like it can cause issues with some drivers. Maybe i should risk that?

Any insight would be helpful.

Cole
  • 133
  • 1
  • 1
  • 3

1 Answers1

4

You need root privileges to access /dev/mem.

To allow access to the GPIO a new device was created called /dev/gpiomem.

/dev/gpiomem can be accessed by members of the gpio group and grants access to the memory used by the GPIO.

I give example code at http://abyz.me.uk/rpi/pigpio/examples.html#Misc_tiny_gpio

joan
  • 71,852
  • 5
  • 76
  • 108