Jonners49
Posts: 7
Joined: Fri Dec 12, 2014 11:14 am

Need to run RPi.GPIO as root, why??

Fri Feb 13, 2015 1:40 pm

Hi-

Running into a two-pronged problem:
If I need to use the line:

Code: Select all

from Tkinter import *
I need to run IDLe as a normal user, otherwise I get the error - ImportError: no module names Tkinter

If I use the line:

Code: Select all

import RPi.GPIO as GPIO
I need to run IDLE as root. otherwise I get the error - NameError : name "GPIO" is not defined

This must be something others have run up against!

Jon.

User avatar
r3d4
Posts: 983
Joined: Sat Jul 30, 2011 8:21 am
Location: ./

Re: Need to run RPi.GPIO as root, why??

Fri Feb 13, 2015 1:49 pm

Could be wrong but, I think it is because think because every thing is a file and root own's the gpio files .
Last edited by r3d4 on Fri Feb 13, 2015 2:56 pm, edited 1 time in total.

Jonners49
Posts: 7
Joined: Fri Dec 12, 2014 11:14 am

Re: Need to run RPi.GPIO as root, why??

Fri Feb 13, 2015 2:00 pm

I've just read that Linux likes to be running as root when accessing the GPIO. Seems a little odd, but there you go. Therefore have to work out how to overcome Tkinter problem. May re-post with a title that describes this approach.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 26716
Joined: Sat Jul 30, 2011 7:41 pm

Re: Need to run RPi.GPIO as root, why??

Fri Feb 13, 2015 3:54 pm

It's the security model.

Linux will not let you access hardware directly unless you have the right permissions. This is a 'good thing'. Stops hackers getting direct access to the HW from a normal account otherwise they could cause complete chaos. GPIO's are HW when accessed directly rather than through a driver.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed.
I've been saying "Mucho" to my Spanish friend a lot more lately. It means a lot to him.

User avatar
DougieLawson
Posts: 39304
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Need to run RPi.GPIO as root, why??

Fri Feb 13, 2015 5:38 pm

Try running sudo idle
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

PiGraham
Posts: 3971
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Need to run RPi.GPIO as root, why??

Fri Feb 13, 2015 6:24 pm

WiringPi or Joan's pigpiod (access via python interface library) will allow user code to run without elevated priveledges and talk to GPIO. Run a daemon from startup and you can control gpio from user code that way.

Return to “Beginners”