eltuxumuxu
Posts: 2
Joined: Mon Dec 22, 2014 8:26 pm

Problem controlling a GPIO with Python

Mon Dec 22, 2014 8:34 pm

I have the Raspberry Pi B with Raspbian installed.
Im trying to control the GPIO27 (number 13) with a script
The script on.py says:
import RPi.GPIO as GPIO
GPIO.setup(13, GPIO.OUT)
GPIO.output(13, True)
and off.py says:
import RPi.GPIO as GPIO
GPIO.setup(13, GPIO.OUT)
GPIO.output(13, False)
The problem is that the LED connected to the GPIO doesn't turn on.
However, if i follow the following commands, it turns on
root@raspberrypi:~# echo 27 > /sys/class/gpio/export
root@raspberrypi:~# echo out > /sys/class/gpio/gpio27/direction
root@raspberrypi:~# echo 1 > /sys/class/gpio/gpio27/value
I have no problem with python using others GPIOs, but i cant using this. What am i doing wrong?

Thanks

vachhaninimiT
Posts: 10
Joined: Sat Apr 12, 2014 5:42 pm

Re: Problem controlling a GPIO with Python

Tue Dec 23, 2014 4:45 am

Hi,
You code should be

import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BOARD) #or you can use GPIO.setmode(GPIO.BCM)

#In board mode it will setup up pin 13 and in BCM mode it will setup GPIO13

GPIO.setup(13, GPIO.OUT)
GPIO.output(13, True)

DirkS
Posts: 10363
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Problem controlling a GPIO with Python

Tue Dec 23, 2014 11:42 am

What am i doing wrong?
Above is correct, but to make it absolutely clear: RPi.GPIO defaults to mode GPIO.BCM.
So if you don't set it explicitly to GPIO.BOARD you should use the same number as you did in the echo commands (27).

Gr
Dirk.

eltuxumuxu
Posts: 2
Joined: Mon Dec 22, 2014 8:26 pm

Re: Problem controlling a GPIO with Python

Tue Dec 23, 2014 11:52 am

Thank you, there was two problems: first was that, i had to set the setmode, and the second one, i had installed RPi.GPIO 0.1.0, when i uninstalled it, it worked like a charm. Thank you again!!

Return to “Python”