NAME
gpio – access to Raspberry Pi GPIO pins

SYNOPSIS
bind –a #G /dev

/dev/gpio

DESCRIPTION
Gpio serves a single file that provides access to the GPIO pins on the Raspberry Pi. Reads from the file receive a 16–character hexadecimal string representing a vlong giving the values of up to 64 GPIO lines. (The processor on both the first and second generation Pis provides 54 actual GPIO lines.) The proper method for sampling GPIO 27 is as follows:
read(gfd, buf, 16);
buf[16] = 0;
gvals = strtoull(buf, nil, 16);
pin27 = gvals & (1 << 27);

Writes to gpio control the characteristics and output values of GPIO lines. The exact operation is specified by one of the following commands:
function pin f
Set the function of GPIO pin to f. The valid values for f are: in, out, alt0, alt1, alt2, alt3, alt4, atl5, and pulse. The functions in and out set the specified GPIO line to be a general purpose input and output, respectively. The various altn functions are as specified in the Broadcom documentation and differ on a per–pin basis. The pulse function is somewhat specialized. It causes the pin to be set to an output for 2μS and then to be set to a input. With the value of the line set to 0 and a pullup resistor on the line, this operation provides a short low pulse suitable for bit–banging a 1–wire interface.
pullup pin
Enables the internal pullup resistor for the specified GPIO pin.
pulldown pin
Enables the internal pulldown resistor for the specified GPIO pin.
float pin
Disables both internal pullup and pulldown resistors for the specified GPIO pin.
set pin value
For GPIO pins set to the output function, this command sets the output value for the pin. The value should be either 0 or 1.

NOTES
All pin number references are according to the SoC documentation. These GPIO signal numbers do not match the pin numbers on the header on the Pi board. Reads sample the external signal values. As a result, the values read for output pins might not match the value written to them if externally they are driven harder than the SoC drives them.

SOURCE
/sys/src/9/bcm/devgpio.c
/sys/src/9/bcm/gpio.c
Copyright © 2025 Plan 9 Foundation. All rights reserved.