0% found this document useful (0 votes)
115 views6 pages

General Purpose Input/Output (GPIO)

General Purpose Input/Output (GPIO) allows peripherals and expansion boards to connect to the CPU by exposing input and output pins on the Raspberry Pi. The GPIO pins can be programmed through software to behave as inputs or outputs. The production Raspberry Pi board has a 26-pin header that provides access to 8 GPIO pins along with power and ground connections. Special care needs to be taken when interfacing with the GPIO pins due to the 3.3V logic level.

Uploaded by

sweetsuresh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
115 views6 pages

General Purpose Input/Output (GPIO)

General Purpose Input/Output (GPIO) allows peripherals and expansion boards to connect to the CPU by exposing input and output pins on the Raspberry Pi. The GPIO pins can be programmed through software to behave as inputs or outputs. The production Raspberry Pi board has a 26-pin header that provides access to 8 GPIO pins along with power and ground connections. Special care needs to be taken when interfacing with the GPIO pins due to the 3.3V logic level.

Uploaded by

sweetsuresh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 6

General Purpose Input/Output (GPIO)

Introduction
In addition to the familiar USB, Ethernet and HDMI ports, the R-Pi offers lower-level interfaces
intended to connect more directly with chips and subsystem modules. These GPIO (general purpose
I/O) signals on the 2x13 header pins include SPI, I2C, serial UART, 3V3 and 5V power. These
interfaces are not "plug and play" and require care to avoid miswiring. The pins use a 3V3 logic level
and are not tolerant of 5V levels, such as you might find on a 5V powered Arduino. CSI (camera serial
interface) can be used to connect the 5 MP camera available. Not yet software-enabled is the flex cable
connectors with DSI (display serial interface) and a serial link inside the HDMI connector called CEC.
(consumer electronics control)

General Purpose Input/Output (GPIO)


General Purpose Input/Output (a.k.a. GPIO) is a generic pin on a chip whose behavior
(including whether it is an input or output pin) can be controlled (programmed) through software.
The Raspberry Pi allows peripherals and expansion boards (such as the Rpi Gertboard) to
access the CPU by exposing the inputs and outputs.
For further general information about GPIOs, see: the wikipedia article.
For further specific information about the Raspberry Pi's BCM2835 GPIOs, see: this wiki
article.
To connect devices to the serial port (UART), see the RPi_Serial_Connection page.
Sample circuits for interfacing the GPIOs with other electronics are shown on the
RPi_GPIO_Interface_Circuits page.
The production Raspberry Pi board has a 26-pin 2.54 mm (100 mil) expansion header, marked
as P1, arranged in a 2x13 strip. They provide 8 GPIO pins plus access to I²C, SPI, UART), as well as
+3.3 V, +5 V and GND supply lines. Pin one is the pin in the first column and on the bottom row.
GPIO voltage levels are 3.3 V and are not 5 V tolerant. There is no over-voltage protection on
the board - the intention is that people interested in serious interfacing will use an external board with
buffers, level conversion and analog I/O rather than soldering directly onto the main board.
All the GPIO pins can be reconfigured to provide alternate functions, SPI, PWM, I²C and so. At
reset only pins GPIO 14 & 15 are assigned to the alternate function UART, these two can be switched
back to GPIO to provide a total of 17 GPIO pins. Each of their functions and full details of how to
access are detailed in the chipset datasheet .
Each GPIO can interrupt, high/low/rise/fall/change. There is currently no support for GPIO
interrupts in the official kernel, however a patch exists, requiring compilation of modified source tree.
The 'Raspbian "wheezy"' version that is currently recommended for starters already includes GPIO
interrupts.
GPIO input hysteresis (Schmitt trigger) can be on or off, output slew rate can be fast or limited,
and source and sink current is configurable from 2 mA up to 16 mA. Note that chipset GPIO pins 0-27
are in the same block and these properties are set per block, not per pin. See GPIO Datasheet
Addendum - GPIO Pads Control. Particular attention should be applied to the note regarding SSO
(Simultaneous Switching Outputs): to avoid interference, driving currents should be kept as low as
possible.
The available alternative functions and their corresponding pins are detailed below. These
numbers are in reference to the chipset documentation and may not match the numbers exposed in
Linux. Only fully usable functions are detailed, for some alternative functions not all the necessary pins
are available for the funtionality to be actually used.
There is also some information on the Tutorial on Easy GPIO Hardware & Software.
Kernel boot messages go to the UART at 115200 bit/s - there are more details on the serial port
page.

R-Pi PCB Revision 2 UPDATE: According to Eben at the R-Pi Rev.2 board being rolled out
starting in September 2012 adds 4 more GPIO on a new connector called P5, and changes some of the
existing P1 GPIO pinouts. On Rev2, GPIO_GEN2 [BCM2835/GPIO27] is routed to P1 pin 13, and
changes what was SCL0/SDA0 to SCL1/SDA1: SCL1 [BCM2835/GPIO3] is routed to P1 pin 5, SDA1
[BCM2835/GPIO2] is routed to P1 pin 3. Also the power and ground connections previously marked
"Do Not Connect" on P1 will remain as connected, specifically: P1-04:+5V0, P1-09:GND, P1-
14:GND, P1-17:+3V3, P1-20:GND, P1-25:GND. According to this comment (and confirmed in this
post ) the P1 pinout is not expected to change in future beyond the current Rev.2 layout.
Referring to pins on the Expansion header
The header is referred to as "The GPIO Connector (P1)". To avoid nomenclature confusion
between Broadcom signal names on the SoC and pin names on the expansion header, the following
naming is highly recommended.
• The expansion header is referred to as "Expansion Header" or "GPIO Connector (P1)"
• Pins on the GPIO connector (P1) are referred to as P1-01, etc.
• Names GPIO0, GPIO1, GPIOx-ALTy, etc. refer to the signal names on the SoC as enumerated
in the Broadcom datasheet, where "x" matches BCM2835 number (without leading zero) and
"y" is the alternate number column 0 to 5 on page 102-103 of the Broadcom document. For
example, depending on what you are describing, use either "GPIO7" to refer to a row of the
table, and "GPIO7-ALT0" would refer to a specific cell of the table.
• When refering to signal names, you should modify the Broadcom name slightly to minimize
confusion. The Broadcom SPI bus pin names are fine, such as "SPI0_*" and "SPI1_*", but they
didn't do the same on the I²C and UART pins. Instead of using "SDA0" and "SCL0", you should
use "I2C0_SDA" and "I2C0_SCL"; and instead of "TX" or "TXD" and "RX" or "RXD", you
should use "UART0_TXD" and "UART0_RXD".

Power pins
The maximum permitted current draw from the 3.3 V pins is 50 mA.
Maximum permitted current draw from the 5 V pin is the USB input current (usually 1 A)
minus any current draw from the rest of the board.
• Model A: 1000 mA - 500 mA -> max current draw: 500 mA
• Model B: 1000 mA - 700 mA -> max current draw: 300 mA
Be very careful with the 5 V pins P1-02 and P1-04, because if you short 5 V to any other P1 pin
you may permanently damage your RasPi. Before probing P1, it's a good idea to strip short pieces of
insulation off a wire and push them over the 5 V pins so you don't accidentally short them with a probe.

GPIO hardware hacking


The complete list of chipset GPIO pins which are available on the GPIO connector is:
0, 1, 4, 7, 8, 9, 10, 11, 14, 15, 17, 18, 21, 22, 23, 24, 25

(on the Revision2.0 RaspberryPis, this list changes to: 2, 3, 4, 7, 8, 9, 10, 11, 14, 15, 17, 18, 22,
23, 24, 25, 27, with 28, 29, 30, 31 additionally available on the P5 header)
As noted above, P1-03 and P1-05 (SDA0 and SCL0 / SDA1 and SCL1) have 1.8 kilohm pull-up
resistors to 3.3 V.
If 17 GPIOs aren't sufficient for your project, there are a few other signals potentially available,
with varying levels of software and hardware (soldering iron) hackery skills:
GPIO02, 03, 05 and 27 are available on S5 (the CSI interface) when a camera peripheral is not
connected to that socket, and are configured by default to provide the functions SDA1, SCL1,
CAM_CLK and CAM_GPIO respectively. SDA1 and SCL1 have 1K6 pull-up resistors to 3.3 V.
GPIO06 is LAN_RUN and is available on pad 12 of the footprint for IC3 on the Model A. On
Model B, it is in use for the Ethernet function.
There are a few other chipset GPIO pins accessible on the PCB but are in use:
• GPIO16 drives status LED D5 (usually SD card access indicator)
• GPIO28-31 are used by the board ID and are connected to resistors R3 to R10 (only on Rev1.0
boards).
• GPIO40 and 45 are used by analogue audio and support PWM. They connect to the analogue
audio circuitry via R21 and R27 respectively.
• GPIO46 is HDMI hotplug detect (goes to pin 6 of IC1).
• GPIO47 to 53 are used by the SD card interface. In particular, GPIO47 is SD card detect (this
would seem to be a good candidate for re-use). GPIO47 is connected to the SD card interface
card detect switch; GPIO48 to 53 are connected to the SD card interface via resistors R45 to
R50.

P2 header
The P2 header is the VideoCore JTAG and used only during the production of the board. It
cannot be used as the ARM JTAG . This connector is unpopulated in Rev 2.0 boards.
Useful P2 pins:
• Pin 1 - 3.3V (same as P1-01, 50 mA max current draw across both of them)
• Pin 7 - GND
• Pin 8 - GND

P3 header
The P3 header, unpopulated, is the LAN9512 JTAG
Useful P3 pins:
• Pin 7 - GND

P5 header
The P5 header was added with the release of the Revision 2.0 PCB design.
P5 Header Pinout (seen from the back of the board), top row:
Pin Pin Name Alt 0
Hardware Notes Other Alternative Functions
Number Rev2 Function
Supply through input
P5-01 5V0
poly fuse
P5-03 GPIO28 I2C0_SDA ALT2 = PCM_CLK
ALT2 = PCM_DIN ALT3 =
P5-05 GPIO30
UART0_CTS ALT5 = UART1_CTS
P5-07 GND
P5 Header Pinout (seen from the back of the board), bottom row:
Pin Pin Name Alt 0
Hardware Notes Other Alternative Functions
Number Rev2 Function
50 mA max
P5-02 3.3 V
(combined with P1)
P5-04 GPIO29 I2C0_SCL ALT2 = PCM_FS
ALT2 = PCM_DOUT ALT3 =
P5-06 GPIO31
UART0_RTS ALT5 = UART1_RTS
P5-08 GND
Note that the connector is intended to be mounted on the bottom of the PCB, so that for those
who put the connector on the top side, the pin numbers are swapped. Pin 1 and pin 2 are swapped, pin 3
and 4, etc.
Some people have come to the conclusion that the best way (for them) to attach this header is
on top, at a slant away from the P1 header.
The new header can provide a second I2C channel (SDA + SCL) and handshake lines for the
existing UART (TxD and RxD), or it can be used for an I2S (audio codec chip) interface using the
PCM signals CLK, FS (Frame Sync), Din and Dout.
Note that the connector is placed JUST off-grid with respect to the P1 connector.

P6 header
The P6 header was added with the release of the Revision 2.0 PCB design.
P6 Pinout:
Pin Number Pin Name Rev2 Hardware Notes
P6-01 RUN Short to ground to reset the BCM2835
P6-02 GND
A reset button can be attached to the P6 header, with which the Pi can be reset. Momentarily
shorting the two pins of P6 together will cause a soft reset of the CPU (which can also 'wake' the Pi
from halt/shutdown state).

Internal Pull-Ups & Pull-Downs


The GPIO ports include the ability to enable and disable internal pull-up or pull-down resistors
(see below for code examples/support of this).
Pull-up is Min. 50K Ohm, Max 65 KOhm.
Pull-down is Min. 50K Ohm, Max 60 KOhm.

Driver support
The Foundation will not include a GPIO driver in the initial release, standard Linux GPIO
drivers should work with minimal modification.
The community implemented SPI and I²C drivers , which will be integrated with the new Linux
pinctrl concept in a later version of the kernel. (On Oct. 14 2012, it was already included in the latest
raspbian image.) A first compiled version as Linux modules is available to install on the 19/04/2012
Debian image, including 1-wire support. The I²C and SPI driver uses the hardware modules of the
microcontroller and interrupts for low CPU usage, the 1-wire support uses bitbanging on the GPIO
ports, which results in higher CPU usage.
GordonH wrote a (mostly) Arduino compatible/style WiringPi library in C for controlling the
GPIO pins.
A useful tutorial on setting up I²C driver support can be found at Robot Electronics - look for
the downloadable document rpi_i2c_setup.doc

You might also like