WiringPi and the Raspberry Pi Revision 2

So the big news is that there is going to be (or already is!) a 2nd revision of the Raspberry Pi PCB, and even bigger is that it’s going to be manufactured (well, assembled) in the UK.

That’s great, but what else? Some of the GPIO pins have changed and that’s not so good for some…

In essence:

  • The I2C pins which used to be GPIO 0 and 1 are now GPIO 2 and 3.
  • The pin that was GPIO 21 on the edge connector is now GPIO 27.
  • There are 4 more GPIO pins available – if you solder on a new connector!

If you are using wiringPi’s native pin numbers then you don’t have to worry. Just get the latest version off the GIT site, install it and re-link your programs.

If you are using the native GPIO pin numbers, then you will need to change your programs – swap GPIOs 0 and 1 for 2 and 3, and 21 for 27.

The 4 new GPIO pins have numbers in the wiringPi scheme of 17, 18, 19 and 20. They are BCM_GPIO pin numbers 28, 29, 30 and 31.

And that’s more or less that!

Comments

WiringPi and the Raspberry Pi Revision 2 — 21 Comments

  1. Is there any way of telling programatically what version you are on. I know that cat /proc/cpuinfo will print out a load of stuff where you can get the revision. So to do that in a program I would have to open the file and parse the results? Is there another way?

    Is this file recreated every time the Pi boots up?

    • Yes.
      Get the latest wiringPi via GIT and look at the source code – it’s not hard to extract the bits that detect the board revision (out of /proc/cpuinfo)

      But if writing your own, then note that if a board has been overclocked then the number in /proc/cpuinfo will have 100000 added onto it!

      -Gordon

    • Actually, not really answered your question, but yes, it’s created at boot-time (it’s not a real file), and I don’t know of any other way, other than writing a program to read it…
      -Gordon

  2. Hi Gordon

    I only have version 1 boards and will be getting version 2 soon I am sure. Will your new version of WiringPi work on both board versions (limited to no extra GPIO on V1).

    Paul

    • Make sure you get the latest via GIT:

      git clone git://git.drogon.net/wiringPi

      and it’ll understand the different board revisions OK

      -Gordon

  3. I wrote this snippet of Python for detecting the board revision:

    for line in open(‘/proc/cpuinfo’).readlines():
    m = re.match(‘(.*?)\s*:\s*(.*)’, line)
    if m:
    (name, value) = (m.group(1), m.group(2))
    if name == “Revision”:
    if value [-4:] in (’0002′, ’0003′):
    board_revision = 1
    else:
    board_revision = 2
    break

    • Looks fine! I don’t program in Python myself, so wiringPi now has a C version. Do note that there may be boards with a revision of 0000 and if the board has been deliberately overvolted (ie. not using the new turbo mode!) then the revieion will have 100000 added to it…

      -Gordon

  4. “there may be boards with a revision of 0000″
    Oh? I wasn’t aware of that – would they be “revision 1″ boards? Or simply “unknown revision”?

    “the revieion will have 100000 added to it”
    Yeah, that’s why I check just the last 4 digits of the revision :)

    The comments-system has stripped out the indentation, so anybody wanting to use the above Python code will need to re-insert indentation as appropriate.

  5. Hi Gordon,

    I really like your work, yet it would be much easier when the source package was in an automake/autoconf style.
    Crosscompiling is my only option and converting your project to autoconf would really help.

    • I’m quite confused by this. wiringPi compiles just fine on a real Raspberry Pi – and takes under a minute to do so.

      Please feel free to fork and convert witingPi to autoconf, but I’ve no plans to do so at present.

      -Gordon

  6. Hi Gordon,
    I have been playing with your wiringpi. Recently I got a GertBoard. I’m pretty now to this all. Is there any problem using the wiringpi with the GertBoard? Limitations etc.?

    • Should have no problems at all with the Gertboard – there is also some code in wiringPi to drive the SPI devices on the Gertboard too – both the A/D and the D/A. (as well as the separate stuff to let you program the ATmega)

      Go for it!

      -Gordon

  7. Is there any way to use WiringPi to create a headless web server for web control of GPIO without root access? It looks like all of the GPIO control methods require root privs at some point. The application would be for home automation, where the PI should boot and start the web server without any intervention. Everything except GPIO seems to work fine.

    • The “easy” way is to use the GPIO program to export the pins that you need to use – input or output – you can do this in a shell script at startup time, then the next bit depends on your application – you can call the gpio program from most languages, but it’s not that efficient, otherwise you can write a C program to do what you need by using wiringPiSetupSys() – this will import all the pins you exported via the gpio program.

      There are some PHP libraries avalable, but you don’t say what back-end CGI scripts you’re using from the web server..

      -Gordon