WiringPi2 for Python – installation instructions for Raspbian
What is WiringPi2 and why do I need it?
WiringPi2 for Python is an excellent GPIO handling system written by Gordon ‘Drogon’ Henderson and packaged for Python by Phil ‘Gadgetoid’ Howard. It uses Arduino-like scripting language. For simple GPIO work, I use RPi.GPIO because that’s what I first got started with.
But, aside from hardware PWM, one thing I love about WiringPi2 is that it also has some extra built-in drivers for various chips – e.g. the MCP23x17 & x8 port expanders. This makes handling expanded ports as easy as…
- defining a pin
- setting it as input or output
- reading or writing to the pin
All the low level heavy lifting is done for us. :) You’ve still got to hook up your own wires though. I think Gordon’s working on that for V3 :p
Installing WiringPi2 for Python
Installing WiringPi2 for Python is very simple, but there are a couple of required packages, so we’ll install those first. Before we install anything, though, let’s update the package lists…
sudo apt-get update
This is what should happen…
Now we need the following. If they’re already installed, no harm will be done…
sudo apt-get install python-dev python-pip
If asked, confirm that you want to go ahead with the installation with
This will take several minutes. When it’s finished, you should see this…
Now we’re ready to install WiringPi2 for Python itself
sudo pip install wiringpi2
You will see lots of messages. pip, the python package installer that you just installed, is compiling WiringPi2 and installing it all for you. After lots of messages starting with “gcc – pthread”, you should see this…
Let’s check it
Now you should be good to go. Let’s check that it works with a live Python environment
We just imported wiringpi2 and used one of its new functions piBoardRev() which is the built-in Raspberry Pi revision checker. Notice it returned a 2, which is good because I’m using a Rev 2 board. ;) If that all works as it should…
ctrl+d to exit python
You are installed and ready for action with WiringPi2’s GPIO features.
I will be creating a page for simple WiringPi2 usage instructions in the near future.