stianeikeland / go-rpio

:electric_plug: Raspberry Pi GPIO library for go-lang
MIT License
2.18k stars 221 forks source link

strangely, does *not* work with sudo #61

Closed dubaxx closed 3 years ago

dubaxx commented 4 years ago

I'm having a very strange issue here, hopefully someone can shed some light on the subject.

go 1.14, raspberry pi 4 B+

using the blinker.go example:

./blinker works just fine sudo ./blinker makes nothing happen.

Why is this? Normally that would be fine, except that I'm trying to use rpio along with a dht11 library that requires root access to run. I find it perplexing that running rpio with heightened privileges causes it to not work.

mlampret commented 4 years ago

Same here - had to switch from root user to pi user to get blinker.go working. Not sure what is the reason for this.

openwrd commented 4 years ago

I also encountered the same problem.

drahoslove commented 4 years ago

This might be some OS-related change. You can try to change this part of code: https://github.com/stianeikeland/go-rpio/blob/master/rpio.go#L630-L637

So that /dev/gpiomem is always used (but only basic gpio functionality will work)

drahoslove commented 4 years ago

Also #50 this might solve your issue, can you please try?

theunkn0wn1 commented 4 years ago

Pulled current master down (commit b62d4be), and built the blinker example as per OP. Can observe voltage consistent with example's intent on output pin when run as normal user (pi), no voltage change is observable when the same program is run as root via sudo.

s00500 commented 3 years ago

Same issue here... can not get it to work on root on and RPI4, go 1.15.3 Only trying to control a single pin at the moment, program works with pi

rami-dabain commented 3 years ago

related https://github.com/stianeikeland/go-rpio/issues/68 [fixed]

drahoslove commented 3 years ago

Should be fixed now - thanks to #70 by @rami-dabain.

Feel free to reopen or create a new issue in case of a problem.