Skip to content

Instantly share code, notes, and snippets.

@yoggy
Created October 23, 2013 10:28
Show Gist options
  • Select an option

  • Save yoggy/7116192 to your computer and use it in GitHub Desktop.

Select an option

Save yoggy/7116192 to your computer and use it in GitHub Desktop.
GPIO control sample code for Raspberry Pi
#!/usr/bin/python
#
# GPIO control sample code for Raspberry Pi
#
# setup
# $ sudo apt-get update
# $ sudo apt-get install python-rpi.gpio
#
# see also...
# http://elinux.org/RPi_Low-level_peripherals
# http://code.google.com/p/raspberry-gpio-python/wiki/Main
# http://code.google.com/p/raspberry-gpio-python/wiki/Examples
#
import sys
import signal
from time import sleep
import RPi.GPIO as GPIO
pin = 13 # GPIO27
GPIO.setwarnings(False)
def sigint_handler(signo, frame):
GPIO.output(pin, False)
GPIO.cleanup()
sys.exit(0)
signal.signal(signal.SIGINT, sigint_handler)
# setup
GPIO.setmode(GPIO.BOARD)
GPIO.setup(pin, GPIO.OUT)
while True:
# blink LED
GPIO.output(pin, True)
sleep(0.5)
GPIO.output(pin, False)
sleep(0.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment