User avatar
DrZWave
Posts: 11
Joined: Mon Jul 15, 2013 6:45 pm

Access GPIOs without sudo with 1 time setup

Sat Apr 05, 2014 2:36 pm

I've spent a couple of hours reading all sorts of postings on how to control the GPIOs without being root - but none of it makes sense (sorry for being dense).
http://elinux.org/RPi_Low-level_periphe ... .28GPIO.29 has the basic details - but still doesn't explain how to control them.

What I want to do is control a couple of GPIOs via Python without being root (sudo).
All I need is to read the current value, then set it low, then set it high, then release again to being an input.
Nothing fancy, no tight timing (I'd use a dedicated micro for accurate timing), I just want something simple that does not require root access.

I'm fine with changing permissions of the /sys/class/gpio/ or whatever but this still doesn't make sense - does a file being in these directories result in the OS changing the state of the GPIO? Where is this explained?

While I'm generally OK with using RPi.GPIO, it has way more functionality than I need and requires yet another download of a python package that I'd rather not bother with. Using this package would force everything connecting to my RPi to also have RPi.GPIO installed which is a pain for such a simple little thing.

User avatar
joan
Posts: 14024
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Access GPIOs without sudo with 1 time setup

Sat Apr 05, 2014 2:47 pm

pigpio can be started (by root) as a daemon at system start-up. Thereafter you can access the gpios (via the daemon) from e.g. Python or the command line without being root. It is another download though.

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: Access GPIOs without sudo with 1 time setup

Sun Apr 06, 2014 4:27 am

What is the problem with running stuff as root? Assign a password to root, login and go.

The first thing I do when bringing up a new system is to assign a root password. The second thing is to install ksh and change root's shell to /bin/ksh.
Beats type sudo blah blah all the time. With unrestricted access to root, might as well type sudo bash. As far as that goes, might as well edit /etc/passwd and change the UID of pi to 0.
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip


User avatar
yv1hx
Posts: 372
Joined: Sat Jul 21, 2012 10:09 pm
Location: Zulia, Venezuela
Contact: Website

Re: Access GPIOs without sudo with 1 time setup

Tue Apr 15, 2014 6:20 pm

Hello DrZWave:

This solution works for me: http://www.raspberrypi.org/forums/viewt ... 33#p131069

Good Luck!
Marco-Luis
Telecom Specialist (Now Available for Hire!)

http://www.meteoven.org
http://yv1hx.ddns.net
http://twitter.com/yv1hx

jabss
Posts: 65
Joined: Thu May 09, 2013 11:47 am

Re: Access GPIOs without sudo with 1 time setup

Mon May 05, 2014 4:07 pm

Hi,

In 3.12.18+ I was able to do it with the following entries in /etc/group
[email protected]:~# cat /etc/group | grep www-data
root:x:0:www-data
www-data:x:33:
gpio:x:1003:pi,www-data
i2c:x:111:pi,www-data
This way, the user pi can change the GPIOs as well as the webpage I have built to change it.

Hope this helps,
Jabss

stockton
Posts: 99
Joined: Mon Aug 24, 2015 6:06 am
Location: South Africa

Re: Access GPIOs without sudo with 1 time setup

Sun Jan 10, 2016 1:40 pm

Please tell me what command you used to get those users into /usr/group.
I have created a C cgi and I am having the same issue, wiringpi insists that it should be run as root.

User avatar
DougieLawson
Posts: 35381
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Access GPIOs without sudo with 1 time setup

Sun Jan 10, 2016 2:26 pm

Adding users to groups is done with the usermod command.

Wiring Pi doesn't always need sudo/root access: http://wiringpi.com/wiringpi-update-to-2-29/
Note: Having anything remotely humorous in your signature is completely banned on this forum.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

stockton
Posts: 99
Joined: Mon Aug 24, 2015 6:06 am
Location: South Africa

Re: Access GPIOs without sudo with 1 time setup

Mon Jan 11, 2016 4:58 am

Thank you.
Got it working by changing owner/user back to root:root and setting the s bit.

multimedia
Posts: 7
Joined: Thu Feb 13, 2014 10:52 am

Re: Access GPIOs without sudo with 1 time setup

Sun Mar 27, 2016 12:31 pm

What is the command (sudo install) to allow access to gpio pins from inside raspbian (i cant remember or find it but had it)

Return to “Interfacing (DSI, CSI, I2C, etc.)”