Using the GPIOs with the WiringPi library
The WiringPi project is a library written in C that makes it easy to work with the GPIO. It has been actively updated with each board revision, includes command-line utilities, and has several wrappers available in higher-level languages such as Ruby and Python.
Getting ready
For this recipe, you will want to install the GPIO libraries for the Raspberry Pi. You might already have them installed, but it is easy enough to make sure it is installed and upgraded, with the following commands:
sudo apt-get install wiringpi sudo apt-get upgrade wiringpi
You'll also want to get the Python wrapper installed, which you can do with this command:
sudo pip install wiringpi2
Note
If this command fails, first try sudo apt-get install python-dev
.
How to do it...
Once you have the libraries installed, you will have a new command-line utility,
gpio
. Unplug anything you have connected to your GPIO pins and give it a test.Let's start with
gpio -v
:pi@rpz14101:~ $ gpio ...