capteur-i2c.sh
The Linux reflex for any I2C sensor: scan the bus with i2cdetect, confirm the chip is there, then read a few registers with i2cget. Direct terminal output without writing a line of application code.
Hardware
An ODROID-M1 (Rockchip RK3568B2, 4 Cortex-A55, 4-8 GB) running Armbian or Ubuntu Hardkernel, with M.2 NVMe, SATA and gigabit Ethernet. 1 I2C sensor (BMP280, MPU6050, SSD1306...) — power it at 3.3 V.
Wiring
SDA/SCL to the connector I2C pins (locate them in the board docs), VCC 3.3 V, GND. Enable the bus in the firmware/device tree.
How it works
i2cdetect -y probes every address and prints the answers; i2cget reads a register. The script checks the address before reading.
Running it
On Armbian: apt install gpiod python3-gpiod; the RK3568’s two GPIO chips (gpiochip0/gpiochip3) show in gpiodetect, map the pin with gpioinfo.
Variants
Chain into a Python conversion (py-smbus), or script periodic reads in a cron job to log pressure/temperature.
capteur-i2c.sh
#!/bin/bash
# Detection et lecture d'un capteur I2C (ex. BMP280 en 0x76) avec i2c-tools.
# Installation : sudo apt install i2c-tools
# Activer le bus I2C (raspi-config / device tree overlay / dtb selon la carte).
set -u
BUS="${1:-1}" # numero de bus (sortie de i2cdetect -l)
echo "== Bus I2C disponibles =="
i2cdetect -l || { echo "noyau sans I2C ? activer le bus"; exit 1; }
echo
echo "== Balayage du bus ${BUS} =="
i2cdetect -y "${BUS}" || exit 1
ADRESSE="${2:-0x76}"
if i2cdetect -y "${BUS}" | grep -q "${ADRESSE#0x}"; then
echo
echo "== Lecture de ${ADRESSE} (16 octets) =="
i2cget -f -y "${BUS}" "${ADRESSE}" 0x00 # ID de puce (0x58/0x5D BMP280)
i2cget -y "${BUS}" "${ADRESSE}" 0xfa # LSB pression (registre brut)
i2cget -y "${BUS}" "${ADRESSE}" 0xfb
i2cget -y "${BUS}" "${ADRESSE}" 0xfc
echo "(brut a convertir avec les registres de calibration de la doc)"
else
echo "Aucune puce a ${ADRESSE} : verifier cable/alimentation/adresse"
exit 2
fi