🛠 Lire un bouton poussoir et afficher dans la console

Orange Pi 5 Plus (Rockchip RK3588) · debutant · Schéma : IMG-orangepi-5-plus-debutant-2-opi5p-bouton-console.svg — bouton poussoir entre la broche 7 et la masse avec résistance de pull-up 10 kΩ vers 3,3 V, terminal console affichant les appuis

Objectives

Read the state of a push button on the 40-pin connector and display a message in the console on each press, using gpiomon (libgpiod) which waits for edges on a GPIO line. We reuse pin 7 (GPIO1_D6 = gpiochip1, line 30) already wired in the LED tutorial: remove the LED before starting.

Hardware

Complete code

# Attente d'un seul appui (front descendant : repos au niveau haut grâce au pull-up)
sudo gpiomon --num-events=1 --falling-edge gpio1 30

# Boucle complète : un message par appui, anti-rebond 50 ms
while sudo gpiomon --num-events=1 --falling-edge \
      --debounce-edge-period 50000000 gpio1 30 >/dev/null; do
    echo "Bouton pressé à $(date +%T)"
done

Expected verification

gpiomon blocks and then displays a line like event: 1 falling edge on the first press. With the loop, each press prints "Button pressed" with the time; without debouncing, a single press can trigger 2 to 5 events (mechanical contact bounce).

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials