wiringOP icon indicating copy to clipboard operation
wiringOP copied to clipboard

Access gpios without root access

Open HerrMuellerluedenscheid opened this issue 4 years ago • 10 comments

Hey, I have tested wiringOP on armbian running on an orange pi zero LTS. I tried to access GPIOs as a non-root user but can't seem to do so.

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?

Running user space software with sudo is clearly not what I want. I tried already adding the group gpio and adding the user to that. I also changed permissions of /dev/mem from

crw-r----- 1 root kmem 1, 1 Nov  3 16:59 /dev/mem

to

crw-rw---- 1 root gpio 1, 1 Nov  3 16:59 /dev/mem

as I read in some post but that also didn't fix it. So how can I fix this?

HerrMuellerluedenscheid avatar Nov 03 '20 17:11 HerrMuellerluedenscheid

I suggest @orangepi-xunlong make /dev/gpio in their Ubuntu release. At this time I need access to /dev/mem to get GPIO adresses: open ("/dev/mem", O_RDWR | O_SYNC | O_CLOEXEC). This is wrong way because badboy can read ram... But at this time this is only one way to call wiringPiSetup() in my app. My executable app has name test; I am in their folder. 0 sudo userchmod -aG kmem and reboot 1 sudo setcap cap_sys_rawio,cap_dac_override=ep ./test 2 @orangepi-xunlong you should close /dev/mem after mmap registers, isn't it? So you should add

int wiringPiSetup (void)
...
  initialiseEpoch () ;
  close(fd); //close /dev/mem
  return 0 ;
}

P.S. I use Orange Pi 4B

AndreiCherniaev avatar Mar 30 '21 23:03 AndreiCherniaev

@HerrMuellerluedenscheid Were you able to solve this issue, I just get the OrangePi and as well as you I need to run Gpio without root permissions.

MrrEdgar avatar Oct 13 '22 05:10 MrrEdgar

Has anyone been able to solve the problem?

Cutaneus avatar Nov 09 '22 12:11 Cutaneus

Anyone solved this? @orangepi-xunlong we need user access to GPIO in wiringPi not sudo on the OrangePi 5b.

Chambana avatar Jun 25 '23 22:06 Chambana

Anyone solved this? @orangepi-xunlong we need user access to GPIO in wiringPi not sudo on the OrangePi 5b.

@orangepi-xunlong

AndreiCherniaev avatar Aug 11 '23 14:08 AndreiCherniaev

+1

hidara2000 avatar Aug 28 '23 09:08 hidara2000

PS for the moment I'm using the following launch.json in vscode. Not ideal but it does allow for debugging break points

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug-Python",
            "type": "python",
            "request": "launch",
            "stopOnEntry": false,
            "program": "${file}",
            "cwd": "${workspaceFolder}",
            "console": "integratedTerminal",
            "debugOptions": [
                "RedirectOutput",
                "Sudo"
            ]
        },
    ]
}

hidara2000 avatar Aug 29 '23 00:08 hidara2000

https://github.com/orangepi-xunlong/wiringOP/issues/28 sudo setcap cap_sys_rawio,cap_dac_override=ep ./test

zjmirving avatar Apr 13 '24 05:04 zjmirving

Any update?

mertcelenk avatar May 06 '24 01:05 mertcelenk

Having issues with this trying to access gpio pins from a ros 2 node.

Bag132 avatar Sep 30 '24 00:09 Bag132