Skip to content

Instantly share code, notes, and snippets.

@miaoski
Created February 21, 2015 07:19
Show Gist options
  • Save miaoski/47aed5954f38871cc58b to your computer and use it in GitHub Desktop.
Save miaoski/47aed5954f38871cc58b to your computer and use it in GitHub Desktop.
Simple GPIO for RPi2 + relay
# -*- coding: utf8 -*-
# sudo python relay.py
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(38, GPIO.OUT)
GPIO.setup(40, GPIO.OUT)
print 'Usage:'
print ' 1 on / 1 off / 2 on / 2 off'
gpios = {'1': 38, '2': 40}
outs = {'on': 1, 'off': 0}
while True:
x = raw_input('> ')
xs = x.strip().split()
if xs[0] in gpios and xs[1] in outs:
GPIO.output(gpios[xs[0]], outs[xs[1]])
else:
print 'Invalid command'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment