Introduction to GPIO : Part 1.

Pins and Modes

This is Part 1 of our guide and will cover the 40 pins, how to identify them and what they do. We will also cover the different GPIO modes and what to look out for.

GPIO (General Purpose Input and Output) allows us to extend the Raspberry Pi beyond the standard hardware. You can use these 40 pins to add buttons, lights, sensors, motors and even communicate with other processors. Our multi part guide will show you everything you need to get started and we will finish off the guide with several practise projects.

The connector

On the newer model Raspberry Pi boards the GPIO connector has 40 pins as do most of the RPi clones these days. Older models had a smaller connector with only 26 pins. We will only cover the newer 40 pin connector in this guide as most people getting started will have these boards and if you do have the old style boards most of the information is still relevant (but this is probably a good time to upgrade to a faster, more capable board).

Pin numbers

First of all you need to identify pin 1, this is the easy part, with the top of the board facing you and the connector running down the right hand side, pin 1 is the top left pin (also shown in the image below). The white outline around the connector has an angled corner to indicate this is pin 1. Also, if you look at the back of the board, you will find pin 1 is the only pin with a square pad, all of the other pads are round (shown in second image).

GPIO Pin One TopGPIO Pin 1 Bottom

Now you know where pin 1 is, you can use this handy pin guide to see how the pins are numbered and what each one does. Note, the left image is for BCM mode and the right is for Wiring Pi. In the centre of each you can see the pin numbers. Pin guides like this come with many electronics kits, the one in the main image at the top of this page came with our rapid prototyping kit which can be found linked at the end of this page.

There is also a PDF version of the pin guide attached to this page which you can download and print.

GPIO Pin Guide‚Äč

GPIO Modes

As you can see from the image above, BCM and Wiring Pi both show different GPIO Pin numbers. These are called modes and depending on which library you use to read and write to GPIO the modes can be different. Some libraries also allow you to set your preferred mode when referencing a pin. This is very useful and allows you as a developer to stick to what you know.

BCM is the standard mode used by a lot of libraries and the one I always use. Most libraries default to this but make sure you check before you start writing code.

Wiring Pi is a library that was started when GPIO only had 26 pins and there was no defined numbering scheme, the creator had to make one up. When it was expanded for 40 pin boards the creator kept the original numbering scheme to avoid confusing users and keep legacy code working. It became so popular that others started to adopt this pin numbering (if you want to read more from the author:

To make matters more confusing, some libraries by default use the actual pin numbers as a reference to the pin you are controlling - although I have never found one of these libraries that does not also allow you to set your own mode.

caution chat check-off check-on close cog-off cog-on down first-page home-off home-on info last-page mail minus mobile more next pdf person play plus prev question radio-off radio-on return search trail up filter facebook google+ LinkedIn twitter YouTube Instagram Share This settings Copy to clipboard