LinuxCommandLibrary

gpio

TLDR

Read GPIO pin state

$ gpio read [pin]
copy
Set GPIO pin output
$ gpio write [pin] [0|1]
copy
Set pin mode
$ gpio mode [pin] [in|out|pwm]
copy
Read all pins
$ gpio readall
copy
Export pin for user access
$ gpio export [pin] [in|out]
copy
Unexport pin
$ gpio unexport [pin]
copy

SYNOPSIS

gpio [options] command [args]

DESCRIPTION

gpio is the WiringPi command-line utility for controlling GPIO pins on Raspberry Pi and similar boards. It allows reading, writing, and configuring GPIO pins from shell scripts and the command line.
The tool supports multiple pin numbering schemes: WiringPi numbering, BCM GPIO numbering (-g), and physical pin numbers (-1).

PARAMETERS

read pin

Read pin value.
write pin value
Write value (0 or 1) to pin.
mode pin mode
Set pin mode: in, out, pwm, clock.
readall
Display all GPIO pins status.
export pin mode
Export pin for user-space access.
unexport pin
Unexport pin.
pwm pin value
Set PWM value (0-1023).
-g
Use BCM GPIO numbering.
-1
Use physical pin numbering.

CAVEATS

WiringPi is deprecated but still functional. Different numbering schemes can cause confusion. Requires appropriate permissions. Pin capabilities vary by board. Some pins have special functions.

HISTORY

gpio is part of WiringPi, created by Gordon Henderson for Raspberry Pi GPIO access. While WiringPi was deprecated in 2019, it remains widely used. Alternatives include libgpiod and Python's RPi.GPIO.

SEE ALSO

Copied to clipboard