🛠 Bouton et LED avec Adafruit_BBIO, la bibliothèque historique

BeagleBone Black (TI Sitara AM3358) · debutant · Schéma : IMG-beaglebone-black-debutant-3-bouton-led-adafruit-bbio.svg — breadboard avec BeagleBone Black : bouton entre P9_11 et GND, LED + 330 Ω sur P8_11, broches P8 et P9 repérées sur la carte.

Objectives

Control an output and read an input on the cape headers using Adafruit_BBIO, the historical Python library of the BeagleBone ecosystem: thousands of BBB tutorials use it and you will encounter it. You will also learn the mapping from header pin to GPIO line (P8_11 = gpio1_13, which is line 45 of the single gpiochip0 on the AM335x) and the equivalent reading using modern libgpiod.

Hardware

Complete Code

#!/usr/bin/env python3
# pip3 install Adafruit_BBIO (images communautaires Debian)
import Adafruit_BBIO.GPIO as GPIO

LED, BTN = "P8_11", "P9_11"
GPIO.setup(LED, GPIO.OUT)
GPIO.setup(BTN, GPIO.IN, pull_up_down=GPIO.PUD_UP)  # bouton vers GND

try:
    while True:
        # actif-à-l'état-bas : appuyé == LOW
        GPIO.output(LED, GPIO.input(BTN) == GPIO.LOW)
finally:
    GPIO.cleanup   # libère les broches, sinon elles restent réclamées
# Équivalent moderne sans Python (libgpiod, images récentes) :
# P8_11 = gpio1_13 = ligne 45 du gpiochip0 ; les noms P8_xx viennent du DT
gpioset -t 200m gpiochip0 P8_11=1     # impulse 200 ms
gpioget gpiochip0 P9_11               # état du bouton
gpiodetect ; gpioinfo gpiochip0 | grep -E "P8_11|P9_11"

Expected Verification

LED off at rest, on when the button is pressed. gpioinfo shows both pins claimed by the script during execution, and released after GPIO.cleanup. With gpioset, you see the LED light up for 200 ms.

Common Errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials