Lasersocks
Posts: 4
Joined: Fri Dec 07, 2012 5:54 pm

Check GPIO state (how to set it up?)

Fri Dec 07, 2012 5:59 pm

Is there anyway to check a GPIO's high or low state?

I know I could set it to low at the start and assign a variable based on that, but I am wondering if there is a way to ask what a GPIO's state is at any time.

I was hoping something like print(GPIO.output(11)) would tell me whether the state is true or false, but obviously that doesn't work.

Thanks!

User avatar
croston
Posts: 708
Joined: Sat Nov 26, 2011 12:33 pm
Location: Blackpool
Contact: Website

Re: Check GPIO state

Fri Dec 07, 2012 6:23 pm

You can read the state of output channels using GPIO.input()

Lasersocks
Posts: 4
Joined: Fri Dec 07, 2012 5:54 pm

Re: Check GPIO state

Fri Dec 07, 2012 6:28 pm

Well that was easy, thanks!

sbderf
Posts: 1
Joined: Wed Jun 18, 2014 2:52 pm

Re: Check GPIO state

Wed Jun 18, 2014 2:56 pm

I am using GPIO.input() to try and read the pins state and keep reciving "GPIO not set up or setup in wrong direction."

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

Re: Check GPIO state

Wed Jun 18, 2014 5:21 pm

sbderf wrote:I am using GPIO.input() to try and read the pins state and keep reciving "GPIO not set up or setup in wrong direction."
The pigpio Python module will let you read the level of the gpios. It doesn't matter if they are set as inputs or outputs (or any of the other possible modes).

Return to “Python”