🛠 Lire un bouton poussoir et afficher l'état dans la console

Orange Pi 3B (Rockchip RK3566) · debutant · Schéma : IMG-orangepi-3b-debutant-2-opi3b-bouton-console.svg — bouton poussoir avec résistance de pull câblé entre une broche GPIO et la masse sur l'Orange Pi 3B

Objectives

Wire a push button to the 40-pin connector of the Orange Pi 3B, read its state from the command line using gpioget, and display each state change in the console.

Hardware

Complete code

# 1. Lecture ponctuelle de la broche (gpioget la configure en entrée)
sudo gpioget -c gpio1 35          # 0 ou 1 selon l'état du bouton

# 2. Journal des appuis dans la console
#!/bin/bash
# fichier : bouton.sh  ->  bash bouton.sh
CHIP=1
PIN=35   # gpio1_b3 en exemple : vérifier une broche libre sur le plan officiel
dernier=""
while true; do
  etat=$(sudo gpioget -c gpio$CHIP $PIN)
  if [ "$etat" != "$dernier" ]; then
    echo "$(date +%T) - bouton = $etat"
    dernier=$etat
  fi
  sleep 0.05
done

Expected verification

At rest, gpioget returns 1 (pull-up to 3.3 V); when the button is pressed, it returns 0. The script displays a timestamped line for each state change, both on press and release.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials