Electronics All-in-One For Dummies
Book image
Explore Book Buy On Amazon
General-purpose input/output (GPIO) ports make Raspberry Pi much more than just a very small computer. GPIO ports allow you to control your own electronic circuits directly from the Pi. The 40-pin GPIO header on the Raspberry Pi 2 and 3 provides access to a total of 17 GPIO ports that can be controlled from programs you write in Python or other languages.

To use a GPIO port, you must first configure the port for input or output. When configured for output, a GPIO port can be set to a HIGH (+3.3 V) or LOW (0 V) condition by your programs. When configured for input, a program can easily determine the current state (HIGH or LOW).

The figure lists the function of each pin on the Raspberry Pi 2 and 3 40-pin header block.

electronics-gpio
Raspberry Pi 2 and 3 header pins.

Unfortunately, the pins on the header block are not labeled in any way on the Raspberry Pi board. If you orient the board so that the header block is on the right edge of the board, just above the USB ports, pins 1 and 2 are at the top of the header block. The odd numbered pins are on the left side of the header block; even numbered pins are on the right side.

You've probably already noticed that the pins on the header block don't appear to be laid out in any particular logical order. The GPIO ports are scattered about the header haphazardly, interspersed with 3.3 V, 5 V, and Ground pins at seemingly random locations.

To avoid confusion when programming Raspberry Pi projects, people common number the GPIO ports using their header pin numbers rather than the GPIO port numbers. For example, GPIO port 19 can be referred to as pin 10 in a Python program. When you write your programs in this way, you can completely ignore the GPIO port number, instead referring to the GPIO port using its pin number. The only trick when you do this is to remember that not all the pins on the 40-pin header are used for GPIO ports; only those pin numbers designated as GPIO ports in the figure should be used as GPIO ports.

The GPIO ports on a Raspberry Pi are rated for about 16 mA of current flow each, with a total of 40 mA across all GPIO ports combined. When designing circuits that interface with the GPIO ports, keep this limit in mind. Make sure you provide adequate current-limiting resistors to avoid damaging your Pi.

About This Article

This article is from the book:

About the book author:

Doug Lowe is the bestselling author of more than 40 For Dummies books. He's covered everything from Microsoft Office to creating web pages to technologies such as Java and ASP.NET, and has written several editions of both PowerPoint For Dummies and Networking For Dummies.

This article can be found in the category: