Pin numbering of the BCM2835 GPIO port(s) on the Raspberry Pi has been a source of great confusion since the designs for the Pi were first published. In the early days (even before hardware was available) the default usable GPIO pins were simply referred to by number as GPIO0 through GPIO7. Additionally there were pins for other purposes, SPI, I2C and serial. This was highlighted on the original image on the eLinux Raspberry Pi Wiki site too.

So when initially writing wiringPi, I chose to have the same default pin numbering scheme and numbered them from 0 upwards. This is no different to how the Arduino operates – “Pin 13” on the Arduino is Port B, bit 5 for example. The underlying hardware definitions are hidden by a simplified numbering scheme. On the Pi, using wiringPi, pin 0 is BCM_GPIO pin 17 for example)

However this has subsequently been viewed as “wrong” and several people have expressed concern about my numbering scheme, however I’ve stuck with it (as by then people were using wiringPi). and it’s proven its worth over the hardware board revisions where some pins changed their hardware definitions, however wiringPi was able to hide this from the user. As a result (for example) a program that uses wiringPi pin 2 on a Rev. 1 Pi will work unchanged on a Rev 2. Pi, however someone using BCM_GPIO pin 21 on a Rev 1 Pi will need to change their program to use BCM_GPIO pin 27 on a Rev 2.

So wiringPi supports its own pin numbering scheme as well as the BCM_GPIO pin numbering scheme, and as of Version 2, it also supports the physical hardware pin numbers (for the P1 connector only), but I would like to suggest you stick to the simplified wiringPi pin numbers. That way your programs will be portable over different hardware revisions without needing any changes.

The following tables give the mapping of the Raspberry Pi GPIO Pins to the (P1) GPIO connector in relation to the pin numbers and the physical location on the connector. This is a representation of the GPIO connector as viewed looking at the board from above. The GPIO connector is to the top-right of the board with the Ethernet and USB sockets to the bottom.

gpio1Board Revisions: Please note the differences between board revisions 1 and 2 (Rv1 and Rv2 above) The Revision 2 is readily identifiable by the presence of the 2 mounting holes.

gpio2The P5 connector is designed to have the header soldered on the underside of the board. Pin 1 is identified by the square solder pad. So if you solder the header on the top of the board be aware that the pin locations will be the other way round!

For a printable version of these tables, click here.

Since the 26-pin GPIO connectors, a new 40-pin connector has appeared on newer Pi’s. There is also the compute Module boards. The best way to get a description of the GPIO connector on whatever Pi you’re currently running on is to use the gpio command:

$ gpio readall

This will give you a complete picture of your Pi’s GPIO connector(s) with all the numbering schemes present.