C (WiringPi) Setup
Python is a great GPIO-driving option, especially if you’re used to it. But if you’re a rickety old programmer, unfamiliar with the whitespace-driven scripting language, and would rather live within the happy confines of C, then let me introduce the WiringPi library.
1) Install Wiring Pi
WiringPi is not included with Raspbian, so, to begin, you’ll need to download and install it. That means your Pi will need a connection to the Internet – either via Ethernet or WiFi.
Once your Pi is Internet-enabled, visit the WiringPi homepage for instructions on downloading and installing the library.
We highly recommend using Git to download the latest version. As long as you have Git installed, these commands should be all you need to download and install WiringPi:
pi@raspberrypi ~/code $ git clone git://git.drogon.net/wiringPi
pi@raspberrypi ~/code $ cd wiringPi
pi@raspberrypi ~/code/wiringPi $ git pull origin
pi@raspberrypi pi@raspberrypi ~/code/wiringPi/wiringPi $ ./build
2) Test Wiring Pi
WiringPi is awesome because it’s actually more than just a C library, it includes a command-line utility as well! You can test your installation of WiringPi with the
Open up a terminal, and try some of these system calls:
pi@raspberrypi ~/code $ gpio -g mode 18 output
pi@raspberrypi ~/code $ gpio -g write 18 1
pi@raspberrypi ~/code $ gpio -g write 18 0
As long as your LED is still connected to pin 18 it should blink on and off following the last two commands.
Or, to test the button, type:
pi@raspberrypi ~/code $ gpio -g mode 17 up
pi@raspberrypi ~/code $ gpio -g read 17
Either 0 or 1 will be returned, depending on whether the button is pressed or not. Try typing that last line again while pressing the button.
gpio utility, as stated in the manual, is a “swiss army knife” command-line tool. We highly recommend checking out the man page (type
man gpio) to discover everything it can do.
If you’re ready to get on with some C-style programming, head over to the next page. We’ll overview some of the most useful functions provided by the WiringPi library.