🛠 LED et bouton USER : triggers kernel et gpio-keys
Objectives
Get familiar with BeaglePlay I/O without writing a driver: control the five gpio-leds LEDs defined in the device tree via the /sys/class/leds interface, change their triggers (heartbeat, cpu, mmc, gpio), and read the USER button declared as gpio-keys on GPIO line GPIO0_18, using evtest.
Hardware
- A BeaglePlay board (recent Debian image)
- No external components: LEDs and button are onboard
- SSH or serial access
Complete code
# Lister les LED déclarées par le device tree
ls /sys/class/leds/
# Voir les triggers disponibles puis activer heartbeat
cat /sys/class/leds/green:heartbeat/trigger
echo heartbeat | sudo tee /sys/class/leds/green:heartbeat/trigger
# Pilotage manuel
echo none | sudo tee /sys/class/leds/green:heartbeat/trigger
echo 1 | sudo tee /sys/class/leds/green:heartbeat/brightness
echo 200 | sudo tee /sys/class/leds/green:heartbeat/delay_on
# Bouton USER (gpio-keys, GPIO0_18) : écouter les événements
sudo evtest # choisir l'entrée gpio-keys, appuyer : BTN_0 down/up
Expected verification
ls /sys/class/leds/ displays the LEDs from the device tree; after echo heartbeat, the LED blinks at the kernel's rate. sudo evtest lists an entry named after the button; pressing it prints EV_KEY / BTN_0 / value 1 followed by value 0. If you write gpio to the trigger file, the LED only responds to brightness.
Common errors
- Looking for a
/sys/class/gpio/gpio...file: with gpio-keys and gpio-leds, the lines are claimed by the kernel, andgpioget/gpiosetreturn EBUSY. - Using the wrong LED name: the exact labels are provided by
ls /sys/class/leds, not by the schematic. - Writing to
brightnesswithout settingtriggertonone: the trigger constantly overwrites the value. - Connecting an external button to GPIO0_18 expecting raw input: you must remove the gpio-keys node from the DTBO, otherwise the line remains occupied.
- Forgetting
sudowith evtest: without permissions on /dev/input, the tool lists no entries.
Other tutorials for this board
- Flasher l'image Debian sur la microSD puis l'eMMC 16 Go
- OLED Qwiic sur le bus I2C 5 (mcu_i2c0)
- Capteurs Grove sur le bus I2C 1 et inventaire du bus
- Double Ethernet : GbE RTL8211F et 10BASE-T1L sur RJ11
- Caméra CSI OV5640 via fdtoverlays dans extlinux.conf
- Reflasher le CC1352P7 en BSL depuis le processeur hôte
Code examples for this board
clignotante.pyPythonbouton-gpio.pyPythoncapteur-i2c.shBashsurveillance-temperature.shBashcapteur-dht11.pyPythonservo-pwm-sysfs.shBash