Skip to content

GPIO tools

14 commands

Reading and driving Raspberry Pi GPIO pins from the shell using pinctrl and the libgpiod utilities (gpiodetect, gpioget, gpioset).

  • GPIO
  • Raspberry Pi
  • hardware

Install GPIO tools

sudo apt install gpiod

Discovering4

pinout

Prints a diagram of the 40-pin header for the board you are on (from python3-gpiozero).

Link
gpiodetect

Lists GPIO chips. On a Pi 5 the header is on gpiochip4 (or a chip labelled pinctrl-rp1); on earlier models gpiochip0.

Link
gpioinfo

Every line on every chip with its name, direction and whether it is in use.

Link
gpiofind <name>

Finds the chip and offset for a named line (libgpiod 1.x).

Link

Reading and writing (libgpiod)4

gpioget <chip> <line>

Reads the current value of a line (1.x syntax; in 2.x use gpioget -c gpiochip0 17).

Link
gpioset <chip> <line>=<value>

Drives a line high. In libgpiod 2.x gpioset keeps running to hold the value until you stop it.

Link
gpiomon <chip> <line>

Waits for and prints edge events, such as a button press.

Link
gpioget -B pull-up <chip> <line>

Enables the internal pull-up resistor while reading.

Link

pinctrl (Raspberry Pi OS)5

pinctrl get

State of every pin: function, direction, pull and level.

Link
pinctrl get <pin>

State of one pin.

Link
pinctrl set <pin> op dh

Sets a pin as an output driving high; dl drives low.

Link
pinctrl set <pin> ip pu

Sets a pin as an input with pull-up.

Link
pinctrl funcs <pin>

Lists the alternate functions a pin supports (UART, SPI, I²C…).

Link

Python1

python3 -c "from gpiozero import LED; from time import sleep; l=LED(17); l.on(); sleep(1); l.off()"

Blinks an LED on GPIO17 once using gpiozero.

Link