🛠 Apprivoiser les LED et la touche ADC du carrier CM4IO

Banana Pi BPI-CM4 (Amlogic A311D, Raspberry Pi CM4 form factor) · debutant · Schéma : IMG-bananapi-cm4-debutant-2-leds-et-cle-adc-cm4io.svg — gros plan du carrier BPI-CM4IO : LED bleue (GPIOAO_7), LED verte (GPIOAO_2), bouton « Function » relié au SARADC, header 26 broches en bas d'image.

Objectives

The mainline device tree (meson-g12b-bananapi-cm4-cm4io.dts, Linux ≥ 6.4) already registers the two carrier LEDs (blue = GPIOAO_7, green = GPIOAO_2) and the carrier's "AD-Key" button, a resistive key on channel 2 of the SARADC. No GPIO library is needed: you will control the LEDs via the /sys LED class API and read the button with evtest.

Hardware

Complete code

sudo apt update && sudo apt install -y gpiod evtest

# Les deux LED sont des périphériques LED class
ls /sys/class/leds/
cat /sys/class/leds/blue:status/trigger   # la liste des triggers, default=heartbeat

# LED bleue = activité CPU, LED verte = allumée manuellement
echo cpu  | sudo tee /sys/class/leds/blue:status/trigger
echo none | sudo tee /sys/class/leds/green:status/trigger
echo 255  | sudo tee /sys/class/leds/green:status/brightness

# Faire monter la charge pour voir le trigger « cpu » réagir
sudo apt install -y stress-ng && stress-ng --matrix 0 --timeout 30s &

# Le bouton AD-Key (SARADC ch2, seuil 1,71 V) arrive comme périphérique evdev
sudo evtest    # choisir le périphérique adc-keys, appuyer : événement KEY_FN

Expected verification

The blue LED blinks according to CPU load (significantly faster during stress-ng); the green LED remains on after echo 255; evtest displays EV_KEY / KEY_FN events each time the Function key on the carrier is pressed.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials