Skip to content

Instantly share code, notes, and snippets.

@aitzol
Created February 10, 2015 20:18
Show Gist options
  • Save aitzol/1b1642712146adf5bcd8 to your computer and use it in GitHub Desktop.
Save aitzol/1b1642712146adf5bcd8 to your computer and use it in GitHub Desktop.
Python code to check any Raspberry Pi GPIO status
#!/usr/bin/env python
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
while True:
data = raw_input("Insert GPIO BCN number to check status (blank to quit): ")
if data == '':
break
try:
number = int(data)
except:
continue
GPIO.setup(number, GPIO.IN)
st = GPIO.input(number)
print st
@aitzol
Copy link
Author

aitzol commented Jun 18, 2020

raw_input is a python2 built-in function, python3 has renamed to input. So if you want to use this snipped with python3 you have to change line 7 and use input()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment