🛠 Lire un bouton poussoir dans la console

ODROID-C4 (Hardkernel) · debutant · Schéma : IMG-odroid-c4-debutant-2-odroidc4-bouton-console.svg — Broches 13 (GPIOX_4) et 14 (GND) du connecteur 40 broches reliées par un bouton poussoir, résistance de pull-up interne indiquée.

Objectives

Wire a push button to the 40-pin connector of the ODROID-C4 and display each press in the console using gpiomon (libgpiod). You will understand the mapping from physical pin to GPIO line (PIN_13 = GPIOX_4, line 4 of the gpio chip), the benefit of the internal pull-up resistor, and the golden rule: all connector logic operates at 3.3 V.

Hardware

Complete Code

#!/usr/bin/env bash
# Câblage : bouton entre PIN_13 (GPIOX_4, chip "gpio", ligne 4)
#           et PIN_14 (GND). Jamais de signal 5 V : logique 3,3 V max.
# pull-up interne activée -> état au repos = 1, appui = 0.

# Événements montants (relâchement) et descendants (appui) :
sudo gpiomon --num-events=20 --rising-edge --falling-edge --bias=pull-up gpio 4

# Variante script : réagir à un seul appui puis afficher un message
while sudo gpiomon --num-events=1 --falling-edge --bias=pull-up gpio 4 ; do
  echo "Appui détecté à $(date +%T)"
done

Expected Verification

Each press prints an event line with a timestamp (event: event=falling edge), and each release prints a rising edge line. As long as you do not press the button, the command remains silently blocked: this is normal, as gpiomon waits on a poll. With gpioget gpio 4 without pressing the button, you should read 1 (internal pull-up).

Common Errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials