Computers, Laptops & Tablets Accessories & Hardware 49 49 people found this article helpful A Tour of the Raspberry Pi GPIO What Each Type of GPIO Pin Does by Richard Saville Writer Richard Saville is a former Lifewire writer and computer enthusiast who has invented several add-on boards for Raspberry Pi and has been published in MagPi and other outlets. our editorial process Facebook Twitter Richard Saville Updated on June 05, 2020 Accessories & Hardware Raspberry Pi The Quick Guide to Webcams Keyboards & Mice Monitors Cards HDD & SSD Printers & Scanners Tweet Share Email The Raspberry Pi can be a of things. That's a big part of the appeal. You can use the Pi like a regular PC, only ever connecting up the usual peripheral devices through the board's USB and HDMI ports. If, however, you want to dive into the more technical aspects of the Pi, you'll probably turn your attention to the set of pins along the side of the circuit board. Those pins hold the key to using the Raspberry Pi in IoT, robotics, and other more involved projects. They're not as intimidating as you may think, once they're broken down and explained. An Introduction to the Raspberry Pi's Pins The Raspberry Pi GPIO. Richard Saville The term 'GPIO' (General Purpose Input Output) isn't exclusive to the Raspberry Pi. Input and output pins can be found on most microcontrollers such as the Arduino, Beaglebone and more. When we talk about GPIO with the Raspberry Pi, we're referring to the long block of pins at the top-left corner of the board. Older models had 26 pins; however, most of us will be using a current model with 40. You can connect components and other hardware devices to these pins and use code to control what they do. It's an important part of the Raspberry Pi and an excellent way to learn about electronics. After a few software projects, you'll likely find yourself experimenting with these pins, eager to mix your code with hardware to make things happen in 'real life.' This process can be intimidating if you're new to the scene, and considering that one false move can damage your Raspberry Pi, it's understandable that it's a nervous area for beginners to explore. This article will explain what each type of GPIO pin does and their limitations. The GPIO The GPIO pins are numbered 1 to 40, and can be grouped under different functions. Richard Saville First, let's take a look at the GPIO as a whole. The pins might look the same, but they all have different functions. The image above shows these functions in different colors which we will explain in the following steps. Each pin is numbered from 1 to 40 starting at the bottom left. These are the physical pin numbers; however, there are also numbering/labeling conventions such as 'BCM' which are used when writing code. Power and Ground The Raspberry Pi offers multiple power and ground pins. Richard Saville Highlighted red, are power pins labeled '3' or '5' for 3.3V or 5V. These pins allow you to directly send power to a device without the need for any code. There's no way of turning these off either. There are 2 power rails - 3.3 volts and 5 volts. The 3.3V rail is limited to 50mA current draw, whereas the 5V rail can provide whatever current capacity is left over from your power supply after the Pi has taken what it needs. Highlighted brown are the ground pins (GND). These pins are exactly what they say - ground pins - which are a vital part of any electronics project. (5V GPIO pins are physical numbers 2 and 4. 3.3V GPIO pins are physical numbers 1 and 17. Ground GPIO pins are physical numbers 6, 9, 14, 20, 25, 30, 34 and 39) Input/Output Pins The Input and Output pins allow you to connect hardware such as sensors and switches. Richard Saville The green pins are 'generic' input/output pins. These can be easily used as inputs or outputs without any worries about clashing with other functions such as I2C, SPI or UART. These are the pins that can send power to an LED, buzzer, or other components, or they can be used as an input to read sensors, switches, or other input devices. The output power of these pins is 3.3V. Each pin shouldn't exceed 16mA of current, either sinking or sourcing, and the entire set of GPIO pins shouldn't exceed more than 50mA at any one time. This can be restrictive, so you may have to get creative in certain projects. (Generic GPIO pins are physical numbers 7, 11, 12, 13, 15, 16, 18, 22, 29, 31, 32, 33, 35, 36, 37, 38 and 40) I2C Pins I2C allows you to connect other devices to your Pi with just a couple of pins. Richard Saville In yellow, we have the I2C pins. I2C is a communication protocol that in simple terms allows devices to communicate with the Raspberry Pi. These pins can also be used as 'generic' GPIO pins. A good example of using I2C is the very popular MCP23017 port expander chip, that can give you more input/output pins through this I2C protocol. (I2C GPIO pins are physical pin numbers 3 and 5) UART (Serial) Pins Connect to your Pi over a serial connection with the UART pins. Richard Saville In grey, are the UART pins. These pins are another communication protocol which offers serial connections, and can also be used as 'generic' GPIO inputs/outputs as well. One use for UART is to enable a serial connection from a Pi to a laptop over USB. This can be achieved using add-on boards or simple cables and removes the need for a screen or internet connection to access your Pi. (UART GPIO pins are physical pin numbers 8 and 10) SPI Pins The SPI pins - another useful communication protocol. Richard Saville In pink, we have the SPI pins. SPI is an interface bus that sends data between the Pi and other hardware/peripherals. It's commonly used for chaining of devices such as an LED matrix or display. Like others, these pins can also be used as 'generic' GPIO inputs/outputs as well. (SPI GPIO pins are physical pin numbers 19, 21, 23, 24 and 26) DNC Pins Nothing to see here - the DNC pins serve no function. Richard Saville Lastly are two pins in blue that, currently, are labeled as DNC which stands for 'Do Not Connect'. This may change in the future if the Raspberry Pi Foundation alters the boards/software. (DNC GPIO pins are physical pin numbers 27 and 28) GPIO Numbering Conventions The Portsplus is a handy tool for checking GPIO pin numbers. Richard Saville When coding with the GPIO, you have the choice to import the GPIO library in one of two ways - BCM or BOARD. The first option is GPIO BCM. This is the Broadcom numbering convention and it's used more commonly across projects and hardware add-ons. The second option is GPIO BOARD. This method uses the physical pin numbers instead, which is handy when counting pins, but you'll find it's used less in project examples. The GPIO mode is set when importing the GPIO library: import RPi.GPIO as GPIO To import as BCM: GPIO.setmode(GPIO.BCM) To import as BOARD: GPIO.setmode(GPIO.BOARD) Both of these methods do exactly the same job, it's just a matter of numbering preference. You can make use of handy GPIO label boards such as the RasPiO Portsplus (pictured) to check which pins I'm connecting wires too. One side shows the BCM numbering convention, the other shows BOARD - so you're covered for any project you find.