Raspberry Pi and GPIO

Posted: 3rd June 2012 by DExUS in News
Comments Off on Raspberry Pi and GPIO

I had very good time with my RPi (Raspberry Pi) computer, few days with reinstalling and testing it’s performance, however the main reason for my purchase was the available GPIO that can be used for … anything.

My application of the GPIO will be in home security.  Since the RPi will be mainly used as mumble (voice chat like teamspeak) server for my gaming purposes it will be always online and thus why not to add more functions to the home server ? 🙂

I had found old ribbon cable with MIDI PORT at one end and connector that can be used with RPi GPIO port pins on the other end. The midi connector part was cut so I got my cables and since I intend to use only 2 of the GPIO ports it does not matter that my connector is 10 pins short 🙂  The other end will go to magnetic sensors. And with use if the GPIO and RPi I can be notified anytime via e-mail if the security of my home will be breached.

Ribbon cable attached to RPi GPIO pins

You can see in the picture how does my setup look like.

Now I was looking around the net for easy GPIO access software and some suggested some weird stuff that needed just to much guff to be installed, until I found the most easy method using just shell commands.

So I got together some very easy shell script that will show the status of all the GPIO ports of RPi that were ment for such use.

And here it is :

#!/bin/sh
GPIO pin layout
# export all gpio ports
 echo "4" > /sys/class/gpio/export
 echo "17" > /sys/class/gpio/export
 echo "18" > /sys/class/gpio/export
 echo "21" > /sys/class/gpio/export
 echo "22" > /sys/class/gpio/export
 echo "23" > /sys/class/gpio/export
 echo "24" > /sys/class/gpio/export
 echo "25" > /sys/class/gpio/export
# set all gpio ports for reading
 echo "in" > /sys/class/gpio/gpio4/direction
 echo "in" > /sys/class/gpio/gpio18/direction
 echo "in" > /sys/class/gpio/gpio21/direction
 echo "in" > /sys/class/gpio/gpio22/direction
 echo "in" > /sys/class/gpio/gpio23/direction
 echo "in" > /sys/class/gpio/gpio24/direction
 echo "in" > /sys/class/gpio/gpio25/direction
# read from input and display
 echo "Pin 7:" `cat /sys/class/gpio/gpio4/value`
 echo "Pin 11:" `cat /sys/class/gpio/gpio17/value`
 echo "Pin 12:" `cat /sys/class/gpio/gpio18/value`
 echo "Pin 13:" `cat /sys/class/gpio/gpio21/value`
 echo "Pin 15:" `cat /sys/class/gpio/gpio22/value`
 echo "Pin 16:" `cat /sys/class/gpio/gpio23/value`
 echo "Pin 17:" `cat /sys/class/gpio/gpio24/value`
 echo "Pin 21:" `cat /sys/class/gpio/gpio25/value`
# unexport all gpio ports
 echo "4" > /sys/class/gpio/unexport
 echo "17" > /sys/class/gpio/unexport
 echo "18" > /sys/class/gpio/unexport
 echo "21" > /sys/class/gpio/unexport
 echo "22" > /sys/class/gpio/unexport
 echo "23" > /sys/class/gpio/unexport
 echo "24" > /sys/class/gpio/unexport
 echo "25" > /sys/class/gpio/unexport

don’t forget to run this script as root.

More info about RPi’s GPIO at :

http://elinux.org/RPi_Low-level_peripherals