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 ...

Get Raspberry Pi Zero Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.