Aug 102015
 
RPi.GPIO-GPIO.RPI_INFO

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…

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…

GPIO.RPI_INFO['P1_REVISION']

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…

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

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® GPIO Reference Aids

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

  1. Portsplus port ID board
  2. GPIO Ruler with RPi.GPIO code
  3. GPIO Zero Ruler with GPIO Zero code

  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…

      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 ~ $

Leave a Reply to alex Cancel reply