GPIO doesn't work

3 posts
by petertrueman » Wed Nov 13, 2013 6:49 pm
Hi All

I am a complete beginner with the RPi.
I can get "number-type" programs to run OK, but trying to use the GPIO
is driving me mad!

My mini-program:-

import RPi.GPIO as GPIO
except Runtime error:
print ("import error") #doesn't print, so I assume import was OK
GPIO.setmode (GPIO.board)
GPIO.setup (7, GPIO.OUT) #runtime error "No access to /dev/mem Try running as root!"
GPIO.output (7, true) #hoped to see some volts on pin7 but prog. doesn't get this far!

I have tried all the fixes I can find on the internet without any joy.
I don't understand "/dev/mem" or "root" in this context, so what to do???
Posts: 2
Joined: Wed Nov 06, 2013 10:41 am
by mahjongg » Wed Nov 13, 2013 11:24 pm
run your program with moderator (super user) access by prefixing the command with "sudo" (super user do).

GPIO's are accessed as if they were memory locations, via the /dev/mem mechanism, but to access memory directly you must have the right (super user) access rights.

so instead of starting

python myprogram


sudo python myprogram

sudo will ask for the password, then run python with super user rights (with "myprogram" as parameter, which is the python code file to run.)
User avatar
Forum Moderator
Forum Moderator
Posts: 4944
Joined: Sun Mar 11, 2012 12:19 am
by petertrueman » Wed Nov 13, 2013 11:40 pm
Thanks guys.

I eventually discovered:-
1. must run the program from the LXterminal, not from Python shell
2. the pin listings in my book are for BCM, and I was using BOARD.

Volts have now appeared on my pin - hooray!

Posts: 2
Joined: Wed Nov 06, 2013 10:41 am