Plindgren
Posts: 1
Joined: Tue Jul 09, 2013 4:41 pm

Check state of Output channel in RPi.GPIO

Tue Jul 09, 2013 4:47 pm

Hey guys!

I am making a web app to control my raspberries GPIO.

Heres some of the GPIO code i wrote for controling a LED light:

Code: Select all

#import RPi.GPIO library as GPIO
import RPi.GPIO as GPIO
#Set GPIO numbering scheme to pinnumber
GPIO.setmode(GPIO.BOARD)
#setup pin 18 as an output
GPIO.setup(18,GPIO.OUT)
#lights off
GPIO.output(18,GPIO.HIGH)
#lights on
GPIO.output(18,GPIO.LOW)
Now. i want to know how to check for output channel 18's state. (excuse this bolony code) i want to do something like

Code: Select all

if GPIO.output(18) == LOW:
     print "lights on!"
else:
     print "lights off!"
I hope you can understand what i mean with the above bolony code.

How would i acheive this with RPi.GPIO?

DrMag
Posts: 63
Joined: Sat Jun 01, 2013 7:59 pm

Re: Check state of Output channel in RPi.GPIO

Tue Jul 09, 2013 6:40 pm

Just use GPIO.input(18). The pin itself doesn't have to be configured as an input for the function to work.

Code: Select all

GPIO.output(18, GPIO.HIGH)
GPIO.input(18)  # returns 1

GPIO.output(18, GPIO.LOW)
GPIO.input(18)  # returns 0

Return to “Python”