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
TW3_SDA
40PIN_GPIO2
3
4
5 V
TW3_SCL
40PIN_GPIO3
5
6
GND
GPIO36
40PIN_GPIO4
7
8
40PIN_GPIO14
UART3_TXD
GND
9
10
40PIN_GPIO15
UART3_RXD
GPIO15
40PIN_GPIO17
11
12
40PIN_GPIO18
I2S3_BCLK
GPIO7
40PIN_GPIO27
13
14
GND
UART3_CTSn
40PIN_GPIO22
15
16
40PIN_GPIO23
UART3_RTSn
3.3 V
17
18
40PIN_GPIO24
SM_GPIO0
SPI1_SDO
40PIN_GPIO10
19
20
GND
SPI1_SDI
40PIN_GPIO9
21
22
40PIN_GPIO25
SM_GPIO1
SPI1_SCLK
40PIN_GPIO11
23
24
40PIN_GPIO8
SPI1_SS0n
GND
25
26
40PIN_GPIO7
SPI1_SS1n
GPIO44
40PIN_GPIO0
27
28
40PIN_GPIO1
GPIO45
GPIO14
40PIN_GPIO5
29
30
GND
GPIO4
40PIN_GPIO6
31
32
40PIN_GPIO12
PWM0
PWM1
40PIN_GPIO13
33
34
GND
I2S3_LRCKIO
40PIN_GPIO19
35
36
40PIN_GPIO16
SM_GPIO11
GPIO13
40PIN_GPIO26
37
38
40PIN_GPIO20
I2S3_DI
GND
39
40
40PIN_GPIO21
I2S3_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.