Skip to content

GPIO Interface

GPIOInterface

Interface to the Raspberry Pi GPIO module. Pin numbering used by functions is identical to the numbers on the 40-pin header. A diagram can be found at: https://pinout.xyz/.

cleanup() staticmethod

Clean up resources and reset pins to default states. NOTE: It is important to call this function prior to exiting your script to avoid accidental damage to the GPIO module.

read_pin(pin) staticmethod

Read the value of a single pin.

Parameters:

Name Type Description Default
pin int

Pin number to read.

required

Returns:

Type Description
bool

True if pin is high, False otherwise.

setup_pin(pin, mode) staticmethod

Setup a pin for either input or output. This must be done prior to any read or write operations.

Parameters:

Name Type Description Default
pin int | list[int]

Pin number (or list of pin numbers) to be setup. The pin numbering scheme matches the header pins on the Raspberry Pi.

required
mode GPIOPinMode

Mode to assign to given pin(s).

required

write_pin(pin, value) staticmethod

Write to a GPIO pin or multiple pins.

Parameters:

Name Type Description Default
pin int | list[int]

Pin number (or a list of pin numbers) to write to.

required
value bool

Value to write to pin (True for HIGH, False for LOW).

required

GPIOPinMode

Bases: Enum

Enum for pin modes.