Skip to content

Instantly share code, notes, and snippets.

@jeremywrnr
Created October 1, 2016 01:24
Show Gist options
  • Save jeremywrnr/7909654ca0a6c7534f8e6e4ce856be21 to your computer and use it in GitHub Desktop.
Save jeremywrnr/7909654ca0a6c7534f8e6e4ce856be21 to your computer and use it in GitHub Desktop.
start controlling gpio on rpi w/ python
#!/bin/bash
# python gpio setup from:
# http://raspberry.io/projects/view/reading-and-writing-from-gpio-ports-from-python/
# Install Python development tools
sudo apt-get update
sudo apt-get install python-dev python-pip
sudo pip install --upgrade distribute
sudo pip install ipython
# Install GPIO
sudo pip install --upgrade RPi.GPIO
# Control GPIO example
echo "
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(25, GPIO.OUT, initial=GPIO.LOW)
GPIO.add_event_detect(4, GPIO.BOTH)
def my_callback():
GPIO.output(25, GPIO.input(4))
GPIO.add_event_callback(4, my_callback)
" > test_gpio.py && ls
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment