In RPi.GPIO 0.5.10 (we’re now on 0.5.11) Ben Croston ‘deprecated’ GPIO.RPI_REVISION, which used to be the preferred way to find out what kind of Raspberry Pi board a program was running on. This was a useful feature to make it possible to write software that will work on any Pi, regardless of how its GPIO pins are arranged. To date, we’ve had three different GPIO pin header layouts for the standard Raspberry Pis (four if you count the compute module).
But GPIO.RPI_REVISION has been deprecated (fallen out of favour) because there is now something better. May I present…
GPIO.RPI_INFO
…which outputs a Python dictionary containing several useful pieces of information. In the screenshot below you can see the output from my Raspberry Pi 2B in a live Python session…
It gives you…
{'P1_REVISION': 3, 'RAM': '1024M', 'REVISION': 'a01041', 'TYPE': 'Pi2 Model B', 'PROCESSOR': 'BCM2836', 'MANUFACTURER': 'Sony'}
…but supposing you only wanted one piece of information. How would you get it? It’s quite simple really. You use the name to get the value. That’s what a Python dictionary is for. Supposing we wanted to know what kind of GPIO header our Pi had, just like we used to use GPIO.RPI_REVISION, we now use…
GPIO.RPI_INFO['P1_REVISION']
…in our case, this would return an integer 3 because the 40 pin Pi2/B+/A+ header is the third revision of the GPIO header. This gives you the exact information you would have previously obtained from GPIO.RPI_REVISION.
If you wanted to put this information into a variable you’d do it like this…
gpio_header_rev = GPIO.RPI_INFO['P1_REVISION']
Additionally, you can now get a whole load of other, new, useful information too.
Here’s A List
You can use each of the following to grab whichever piece of information you’re after from the GPIO.RPI_INFO dictionary…
- GPIO.RPI_INFO[‘P1_REVISION’]
- GPIO.RPI_INFO[‘RAM’]
- GPIO.RPI_INFO[‘REVISION’]
- GPIO.RPI_INFO[‘TYPE’]
- GPIO.RPI_INFO[‘PROCESSOR’]
- GPIO.RPI_INFO[‘MANUFACTURER’]
…but bear in mind that they all return a string apart from P1_REVISION, which returns an integer.
Here’s A Script To Make It Easy
To make it easy, I’ve written a short Python script (in Python 3), which shows the whole dictionary output and then each of its elements in turn.
from RPi import GPIO print("Raw output from GPIO.RPI_INFO:\n",GPIO.RPI_INFO) print("Output from GPIO.RPI_INFO['P1_REVISION']\n",GPIO.RPI_INFO['P1_REVISION']) print("Output from GPIO.RPI_INFO['RAM']\n",GPIO.RPI_INFO['RAM']) print("Output from GPIO.RPI_INFO['REVISION']\n",GPIO.RPI_INFO['REVISION']) print("Output from GPIO.RPI_INFO['TYPE']\n",GPIO.RPI_INFO['TYPE']) print("Output from GPIO.RPI_INFO['PROCESSOR']\n",GPIO.RPI_INFO['PROCESSOR']) print("Output from GPIO.RPI_INFO['MANUFACTURER']\n",GPIO.RPI_INFO['MANUFACTURER'])
You would run this script by typing sudo python3 scriptname.py
, where scriptname.py is whatever you chose to call it. This is what the output from that script looks like…
Why Was This Done?
When the Pi2 came out, things changed a bit. Not only do we now have 3 different kinds of GPIO header on the consumer versions of the Pi, but we also have 3 different quantities of RAM and two different processors. So it’s really sensible to create a mechanism whereby we can find out, programatically, exactly what sort of machine we’re running on. GPIO.RPI_INFO does precisely that. We can now grab the exact information we need about GPIO header, RAM and CPU and even some extras like manufacturer, product name and revision number.
It’s useful. So let’s use it. GPIO.RPI_REVISION still works, for now, but if you have RPi.GPIO 0.5.10 or newer, you should start getting into the habit of using the newer GPIO.RPI_INFO because at some point, GPIO.RPI_REVISION will disappear.
RasPiO® GPIO Reference Aids
Our sister site RasPiO has three really useful reference products for Raspberry Pi GPIO work...
Trying this I found that a lot of the fields return “unknown” only the P1_revision and revision fields were returned. Have I missed something?
Just tried it on a Pi Zero running Jessie and got this…
python3 revtest.py
Raw output from GPIO.RPI_INFO:
{‘RAM’: ‘512M’, ‘PROCESSOR’: ‘BCM2835’, ‘REVISION’: ‘900092’, ‘TYPE’: ‘Unknown’, ‘P1_REVISION’: 3, ‘MANUFACTURER’: ‘Sony’}
Output from GPIO.RPI_INFO[‘P1_REVISION’]
3
Output from GPIO.RPI_INFO[‘RAM’]
512M
Output from GPIO.RPI_INFO[‘REVISION’]
900092
Output from GPIO.RPI_INFO[‘TYPE’]
Unknown
Output from GPIO.RPI_INFO[‘PROCESSOR’]
BCM2835
Output from GPIO.RPI_INFO[‘MANUFACTURER’]
Sony
Here is my output on a B+
pi@raspberrypi ~ $ sudo python3 rpi_info.py
Raw output from GPIO.RPI_INFO:
{‘P1_REVISION’: 3, ‘RAM’: ‘Unknown’, ‘REVISION’: ‘0010’, ‘TYPE’: ‘Unknown’, ‘PROCESSOR’: ‘Unknown’, ‘MANUFACTURER’: ‘Unknown’}
Output from GPIO.RPI_INFO[‘P1_REVISION’]
3
Output from GPIO.RPI_INFO[‘RAM’]
Unknown
Output from GPIO.RPI_INFO[‘REVISION’]
0010
Output from GPIO.RPI_INFO[‘TYPE’]
Unknown
Output from GPIO.RPI_INFO[‘PROCESSOR’]
Unknown
Output from GPIO.RPI_INFO[‘MANUFACTURER’]
Unknown
pi@raspberrypi ~ $
Well that doesn’t look right. Is your Raspbian up to date?
I’ve done the full update recommended in part one of this series
sudo apt-get update && sudo apt-get upgrade
so I presume it is up to date.
Now flashed a new SD card with the latest version of Jessie with the same result. So I guess this is a hardware or firmware fault with my Pi
That is a bit puzzling. Does it happen with the same SD card(s) on your other Pis?
AFAIK there’s nothing going wrong here – the information displayed by GPIO.RPI_INFO is automatically “decoded” from the new-style board revision IDs used by the Pi2 (a01041) and Pi Zero (900092).
Boards using the “old-style” board revision IDs (A, A+, B, B+) don’t have this “extra info” encoded within their revision ID, and so simply get set to “Unknown” by GPIO.RPI_INFO. Strictly speaking, RPi.GPIO shouldn’t even be *trying* to decode the old-style board revision IDs…
See also the comments in http://git.drogon.net/?p=wiringPi;a=blob;f=wiringPi/wiringPi.c#l810