Understanding the Raspberry Pi GPIO Pinout Using the wiringPi Library


Raspberry Pi LogoThe Raspberry comes fully loaded with a general-purpose input/output (GPIO) port to interface with a multitude of devices/sensors/expansion boards. Unfortunately, there could be many different ways to refer to the same pin, especially if you are using the wiringPi library. In this post I will attempt to show you how to make sense of it all. Be aware, this is not for the faint of heart!




Pin Layout diagrams

These are the Pin layout diagrams for bothe the Raspberry Pi and Raspberry Pi 2.

Keep the pin layout diagram close by when doing any interfacing with the GPIO ports.

It could all get really confusing, really quickly. Surprisingly, there are three ways to refer to the same pin: the wiringPi number, GPIO number and physical number!

As an example, I will take my recent project MyPi Home Control, specifically the section where I discuss connecting the 433MHz Transmitter/Receiver to the Raspberry Pi.

I use the 433Utils library, which in turn depends on the wiringPi library.

On the transmitter end of things, the main data pin (the voltage and ground pins are easy to figure out), I used GPIO 17 (or pin 11 — if you’re counting from left to right/bottom to top). To understand why, you need to know how the wiringPi library maps to that specific pin. Use the command below to see the mapping (of course you need to install wiringPi first).

$ gpio readall
wiringPi GPIO Readall Command

wiringPi GPIO Readall Command

Look under the BCM column (those are the GPIO numbers). BCM 17 maps to wPi (or wiringPi pin 0).

Now if you look at the emitter code, specifically in 433Utils/RPi_utils/codesend.cpp, line 24 (which is what I use to send the codes to the wireless power switches), you’ll see:

int PIN = 0;

So wiringPi pin 0 maps to GPIO 17.

Similarly, for the sniffer (or receiver) code (see 433Utils/RPi_utils/RFSniffer.cpp, line 23). You’ll notice:

int PIN = 2;

Which maps to GPIO 27 (pin 13).

As far as I know, the RPi2 is exactly the same pinout (minus the new pins).

Good luck and happy hacking!

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.