Skip to content

Instantly share code, notes, and snippets.

@jhass
Created July 7, 2012 13:04
Show Gist options
  • Select an option

  • Save jhass/3066412 to your computer and use it in GitHub Desktop.

Select an option

Save jhass/3066412 to your computer and use it in GitHub Desktop.
Some helper functions to work with the GPIO ports of the RPi
function export() {
echo "$1" | sudo tee /sys/class/gpio/export
sudo chgrp -RH --dereference users /sys/class/gpio/*
sudo chmod -R g+w+r /sys/class/gpio/*/*
}
function unexport() {
echo "$1" | sudo tee /sys/class/gpio/unexport
}
function output() {
export $1
echo "out" > /sys/class/gpio/gpio$1/direction
}
function input() {
export $1
echo "in" > /sys/class/gpio/gpio$1/direction
}
function enable() {
echo "1" > /sys/class/gpio/gpio$1/value
}
function disable() {
echo "0" > /sys/class/gpio/gpio$1/value
}
function display() {
cat /sys/class/gpio/gpio$1/value
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment