🛠 Bouton poussoir et retour sur la console

Raspberry Pi Model A (2013) — Board Sheet · debutant · Schéma : IMG-model-a-debutant-2-modela-bouton-console.svg — Raspberry Pi Model A avec un bouton poussoir câblé entre GPIO4 (broche 7) et la masse, résistance interne de pull-up indiquée, sortie console série annotée

Objectives

Hardware

Complete code

# Lecture événementielle avec gpiomon (libgpiod)
sudo gpiomon --rising-edge --num-events=0 gpiochip0 4

# Version Python avec la bibliothèque héritée RPi.GPIO
python3 - <<'PY'
import RPi.GPIO as GPIO, time
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.IN, pull_up_down=GPIO.PUD_UP)
try:
    while True:
        print("bouton:", "APPUYE" if not GPIO.input(4) else "libre", flush=True)
        time.sleep(0.05)
finally:
    GPIO.cleanup
PY

Expected verification

Each press displays a rise event (gpiomon) or “button: PRESSED” then “released” upon interruption. The circuit is active-low: at rest, the input is pulled to 3.3 V by the internal pull-up.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials