Skip to content

Instantly share code, notes, and snippets.

@choowilson
Created December 11, 2019 03:26
Show Gist options
  • Save choowilson/81c651ea7296d111bcb685ca560cbbb1 to your computer and use it in GitHub Desktop.
Save choowilson/81c651ea7296d111bcb685ca560cbbb1 to your computer and use it in GitHub Desktop.
example python script to switch on GPIO pin on Raspi
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD) # Raspi board GPIO Pin Number
GPIO.setup(11, GPIO.OUT) # Output pin is GPIO Pin 17
# Initial state for LEDs:
print("Testing GPIO Pin11 out, Press CTRL+C to exit")
try:
print("Set GPIO 17 HIGH")
GPIO.output(11, GPIO.HIGH)
time.sleep(5)
except KeyboardInterrupt: # If CTRL+C is pressed, exit cleanly:
print("Keyboard interrupt")
except:
print("some error")
finally:
print("clean up")
GPIO.cleanup() # cleanup all GPIO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment