GPIO — General Purpose I/O interface

This module provides access and control of pins set up as General Purpose I/O (GPIO).


You need to be part of the gpio group of the OS running on the Beaglebone to be able to run GPIO code as a non-root user. The default user created upon the Debian image installation should already be part of the group. Otherwise, you can use sudo usermod -a -G gpio userName to add userName to the group.


When coding with this module, you will be using pin names for better readability. As such, you can specify them in the header 8 or 9 form (e.g. “P8_16”) or in pin name form (e.g. “GPIO1_14”). For easy reference, you can use the Beaglebone pin names table


On-board LEDs (USR0-USR3) are handled by LED class driver rather than the GPIO pin driver.

They have a different path in the /sys/ filesystem.

Setup the pin for output and write GPIO.HIGH or GPIO.LOW


# Use the config-pin command line tool to set a pin's function to GPIO
# Then you can control it with the GPIO module from Python
config-pin P9_14 gpio

import Adafruit_BBIO.GPIO as GPIO

# Set up pins as inputs or outputs
GPIO.setup("P8_13", GPIO.IN)
GPIO.setup("P8_14", GPIO.OUT)
GPIO.setup("GPIO0_26", GPIO.OUT)  # Alternative: use actual pin names

# Write a logic high or logic low
GPIO.output("P8_14", GPIO.HIGH)  # You can also write '1' instead
GPIO.output("P8_14", GPIO.LOW)   # You can also write '0' instead

# Blinking onboard led example
import Adafruit_BBIO.GPIO as GPIO
import time

for i in range(4):
    GPIO.setup("USR%d" % i, GPIO.OUT)

while True:
    for i in range(4):
        GPIO.output("USR%d" % i, GPIO.HIGH)
    for i in range(4):
        GPIO.output("USR%d" % i, GPIO.LOW)
Adafruit_BBIO.GPIO.setup(channel, direction[, pull_up_down=GPIO.PUD_OFF, initial=None, delay=0])

Set up the given GPIO channel, its direction and (optional) pull/up down control

  • channel (str) – GPIO channel to set up (e.g. “P8_16”).
  • direction (int) – GPIO channel direction (GPIO.IN or GPIO.OUT).
  • pull_up_down (int) – pull-up/pull-down resistor configuration (GPIO.PUD_OFF, GPIO.PUD_UP or GPIO.PUD_DOWN).
  • initial (int) – initial value for an output channel (GPIO.LOW/GPIO.HIGH).
  • delay (int) – time in milliseconds to wait after exporting the GPIO pin.

Clean up by resetting all GPIO channels that have been used by the application to IN with no pullup/pulldown and no event detection.

Note:It’s recommended that you call this function upon exiting your application.
Adafruit_BBIO.GPIO.output(channel, value)

Set the given output channel to the given digital value.

  • channel (str) – GPIO channel to output the value to (e.g. “P8_16”).
  • value (int or bool) – value to set the output to– 0/1 or False/True or GPIO.LOW/GPIO.HIGH.

Get the given input channel’s digital value.

Parameters:channel (str) – GPIO channel to read the value from (e.g. “P8_16”).
Returns:Channel value–– 0 or 1.
Return type:int
Adafruit_BBIO.GPIO.add_event_detect(channel, edge[, callback=None, bouncetime=0])

Enable edge detection events for the given GPIO channel.

  • channel (str) – GPIO channel to detect events from (e.g. “P8_16”).
  • edge (int) – edge to detect–– GPIO.RISING, GPIO.FALLING or GPIO.BOTH
  • callback (func) – a function to call once the event has been detected.
  • bouncetime (int) – switch bounce timeout in ms for the callback.

Remove edge detection for the given GPIO channel.

Parameters:channel (str) – GPIO channel to remove event detection from (e.g. “P8_16”).

Checks if an edge event has occured on a given GPIO.

Note:You need to enable edge detection using add_event_detect() first.
Parameters:channel (str) – GPIO channel to check for event detection for (e.g. “P8_16”).
Returns:True if an edge has occured on a given GPIO, False otherwise
Return type:bool
Adafruit_BBIO.GPIO.add_event_callback(channel, callback[, bouncetime=0])

Add a callback for an event already defined using add_event_detect()

  • channel (str) – GPIO channel to add a callback to (e.g. “P8_16”).
  • callback (func) – a function to call once the event has been detected.
  • bouncetime (int) – switch bounce timeout in ms for the callback.
Adafruit_BBIO.GPIO.wait_for_edge(channel, edge[, timeout=-1])

Wait for an edge on the given channel.

  • channel (str) – GPIO channel to wait on (e.g. “P8_16”).
  • edge (int) – edge to detect–– GPIO.RISING, GPIO.FALLING or GPIO.BOTH
  • timeout (int) – time to wait for an edge, in milliseconds. -1 will wait forever.

Return the current GPIO function (IN, IN, ALT0) of the given pin.

Warning:Currently only returning the direction of the pin (input or output) is supported.
Parameters:channel (str) – GPIO pin to query the status of.
Returns:0 if IN, 1 if OUT
Return type:int

Enable or disable GPIO warning messages.

Warning:Currently enabling or disabling warnings has no effect.
Parameters:gpio_warnings (int) – 0–– disable warnings; 1–– enable warnings

Pin mode– alternate function 0.


Edge detection– detect both edges.


Edge detection– detect falling edge.


Pin status– logic low.


Pin mode– input.


Pin status– logic low.


Pin mode– output.


Pull-up/pull-down resistor type– no pull-up/pull-down.


Pull-up/pull-down resistor type– pull-down.


Pull-up/pull-down resistor type– pull-up.


Edge detection– detect rising edge.


GPIO module version. Currently unused.