Skip to main content

GPIO

This guide shows how to find GPIO pins on the board's 40-pin header and check whether their GPIO lines are available. You'll use the Linux shell to set an output high or low and read the state of an input.

Before You Start​

Open a shell on the board. This guide uses the libgpiod 2.x command-line tools. Run gpioset --version to check the installed version.

danger

Check the header orientation, pinout, and GPIO voltage limits before using the header.

See Hardware Resources for the board datasheet and schematic.

Board Header Mapping​

The diagram shows each pin's physical number and default function. Use the Linux GPIO line name from the Label column in commands such as gpioinfo and gpioset.

3.3 V
1
2
5 V
I2C0 SDA
40PIN_GPIO2
3
4
5 V
I2C0 SCL
40PIN_GPIO3
5
6
GND
GPIO4
40PIN_GPIO4
7
8
40PIN_GPIO14
UART2 TX
GND
9
10
40PIN_GPIO15
UART2 RX
GPIO0
40PIN_GPIO17
11
12
40PIN_GPIO18
PCM BCLK
GPIO11
40PIN_GPIO27
13
14
GND
GPIO74
40PIN_GPIO22
15
16
40PIN_GPIO23
GPIO72
3.3 V
17
18
40PIN_GPIO24
GPIO69
SPI2 MOSI
40PIN_GPIO10
19
20
GND
SPI2 MISO
40PIN_GPIO9
21
22
40PIN_GPIO25
GPIO73
SPI2 SCLK
40PIN_GPIO11
23
24
40PIN_GPIO8
SPI2 CS
GND
25
26
40PIN_GPIO7
GPIO6
I2C2 SDA
40PIN_GPIO0
27
28
40PIN_GPIO1
I2C2 SCL
GPIO1
40PIN_GPIO5
29
30
GND
GPIO21
40PIN_GPIO6
31
32
40PIN_GPIO12
PWM2
PWM1
40PIN_GPIO13
33
34
GND
PCM FS
40PIN_GPIO19
35
36
40PIN_GPIO16
GPIO9
GPIO10
40PIN_GPIO26
37
38
40PIN_GPIO20
PCM DI
GND
39
40
40PIN_GPIO21
PCM DO
PowerGroundGPIOI²CAudioPWMSPIUART

Set an Output​

This example uses physical pin 7. Check that its GPIO line is free:

Board shell
gpioinfo --strict '40PIN_GPIO4'

If the line has a consumer, use a different GPIO. Otherwise, drive the pin high:

Board shell
gpioset --strict '40PIN_GPIO4=1'

The command stays running and holds the output high. Press Ctrl+C to release the line. To drive it low, run the same command with =0. The pin level may change when gpioset exits.

Read an Input​

This example reads physical pin 13. You can test it with a short jumper wire. Connecting pin 13 to GND (pin 14) gives a low level, and connecting it to 3.3 V (pin 17) gives a high level. Before connecting the jumper, check that the GPIO line is free and the pin is configured as an input.

Board shell
gpioinfo --strict '40PIN_GPIO27'

Connect the jumper, then read the input.

Board shell
gpioget --strict '40PIN_GPIO27'

The command reports the logical state, active (1) or inactive (0), and exits. A floating input can return either value.