It struck me the other day that I’ve published some fairly advanced RPi.GPIO tutorials, (e.g. interrupts and PWM) but not done anything more basic, apart from the Gertboard examples. So here’s an attempt to remedy that situation.

Over the next few days, we’re going to have a walk around Ben Croston’s RPi.GPIO, which is now at version 0.5.3a. Some of this stuff may be new to you even if you’ve been using RPi.GPIO’s more advanced features, so it’s worth having a look.

What is RPi.GPIO?

It’s an easy way of controlling the Pi’s General Purpose Input Output ports in Python. Control the world with your Raspberry Pi.

How to check what RPi.GPIO version you have

This works for all versions of RPi.GPIO

find /usr | grep -i gpio

And the output will look something like this (although there will be more of it)…



You can see all those lines with 0.5.3a.egg-info telling me I have version 0.5.3a.

How to check RPi.GPIO version in Python (works with 0.4.1a +)

While the above works without even using Python, from RPi.GPIO 0.4.1 onwards (September 2012), you can check the version in your Python programs.

It’s quite useful to be able to find out what version of RPi.GPIO you have. Some features require a recent version, whereas others work with older versions. For example, interrupts were added at 0.5.1, PWM at 0.5.2 and with 0.5.3 some bugs have been squashed.

You don’t have to write or run any programs to find out which version you have. You can do it very quickly in a live Python session. If you don’t know how to do that, it’s a great way of testing things out in Python.

Running a live Python session

In the command line environment (either before typing startx or, if you’re in LXDE, start LXTerminal) type…

sudo python run python as super user (needed for RPi.GPIO to work)

Ignore the “help” “copyright” “credits” “license” notice. Just type the next line at the >>> prompt

import RPi.GPIO as GPIO loads the RPi.GPIO library so we can use it

GPIO.VERSION this returns the version number of RPi.GPIO

CTRL+D ends the python session cleanly (it won’t appear on the screen).

Watch out for RPi.GPIO. The i in RPi, is lowercase. All the rest is uppercase. Get it wrong and it won’t work.

So next time someone publishes a python script “that requires RPi.GPIO 0.5.3 or higher”, you’ll know how to check which version you have.

If you want to make it into a little program…

import RPi.GPIO as GPIO a = GPIO.VERSION print a

If you don’t like live python environments, you could make it into a little script using the code above.

cd ~

nano version.py

copy and paste or retype the above script

CTRL+O save

ENTER confirm

CTRL+X exit

Then, to run it, type sudo python version.py

…and this is what you should see…



How to update your RPi.GPIO

If you find your RPi.GPIO version is horribly out of date, you can update it to the latest version with…

sudo apt-get update && sudo apt-get upgrade

But, if you haven’t updated for a while it could take quite a long time to update all your packages (>1hr).

If you don’t want to do it that way, you could use this, which updates your package list and installs the latest RPi.GPIO

sudo apt-get update && sudo apt-get install python-rpi.gpio python3-rpi.gpio

Coming soon…

In the next part, we’ll cover how to check what revision of Raspberry Pi you have. Currently there’s only Rev 1 and Rev 2, but there are some GPIO differences (e.g. i2c and port 21/27) between them, so it’s worthwhile being able to check, so you can make sure your programs will work on any Pi.

RasPiO® GPIO Reference Aids

Our sister site RasPiO has three really useful reference products for Raspberry Pi GPIO work...