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.
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.
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.
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.