Aug 102015

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…


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

Output from GPIO.RPI_INFO

Output from GPIO.RPI_INFO

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…


P1_REVISION output on Pi2B

P1_REVISION output on Pi2B

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


…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['RAM']\n",GPIO.RPI_INFO['RAM'])
print("Output from GPIO.RPI_INFO['TYPE']\n",GPIO.RPI_INFO['TYPE'])

You would run this script by typing sudo python3, where is whatever you chose to call it. This is what the output from that script looks like…

Output from the script

Output from the script

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® Portsplus is really useful with RPi.GPIO

The RasPiO® Portsplus board labels the GPIO ports clearly for you so that you don't need to count pins. This helps you avoid wiring errors and damage. Click the photo for more information.

RasPiO Portsplus on Pi2

  8 Responses to “RPI.GPIO New Feature GPIO.RPI_INFO replaces GPIO.RPI_REVISION”

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

      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’]
      Output from GPIO.RPI_INFO[‘RAM’]
      Output from GPIO.RPI_INFO[‘REVISION’]
      Output from GPIO.RPI_INFO[‘TYPE’]
      Output from GPIO.RPI_INFO[‘PROCESSOR’]

      • Here is my output on a B+

        pi@raspberrypi ~ $ sudo python3
        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’]
        Output from GPIO.RPI_INFO[‘RAM’]
        Output from GPIO.RPI_INFO[‘REVISION’]
        Output from GPIO.RPI_INFO[‘TYPE’]
        Output from GPIO.RPI_INFO[‘PROCESSOR’]
        Output from GPIO.RPI_INFO[‘MANUFACTURER’]
        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;a=blob;f=wiringPi/wiringPi.c#l810

Leave a Reply