🛠 Apprivoiser les LED et la touche ADC du carrier CM4IO
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
- BPI-CM4 on its carrier (BPI-CM4IO ideally, since the LEDs and the key are soldered onto it)
- Up-to-date Armbian bananapicm4io (or any system with mainline kernel ≥ 6.4)
- No soldering, no external components
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
- Looking for pins using Raspberry Pi GPIO numbering: here the pins are Amlogic banks (GPIOA, GPIOX, GPIOAO) and the mainline DTS does not define gpio-line-names for the header.
- Installing the vendor's WiringPi (Dangku fork): it only works on the 4.9 BSP kernel, not on mainline.
- Using the wrong LED name depending on the image (use the wildcard /sys/class/leds/*/trigger if necessary).
- Running evtest without permissions: run with sudo or add the user to the input group.
- Confusing the ADC button (SARADC channel 2, keyboard event) with a standard GPIO: gpiomon will never see it.
Other tutorials for this board
- Monter le module BPI-CM4 sur son carrier et réussir le premier boot
- Mesurer le stockage du BPI-CM4 : eMMC, microSD et le palier NVMe
- Activer I2C, SPI et UART sur le BPI-CM4 : env.txt ou armbianEnv.txt
- Brancher un capteur BME280 sur l'I2C1 du carrier (GPIOX_17/18)
- Déplacer le rootfs sur un SSD NVMe via le port mini-PCIe
- Exploiter le NPU 5 TOPS de l'A311D pour l'inférence embarquée
Code examples for this board
clignotante.pyPythonbouton-gpio.pyPythoncapteur-i2c.shBashsurveillance-temperature.shBashcapteur-dht11.pyPythonservo-pwm-sysfs.shBash