🛠 Capteur BME280 (I2C) sur Le Potato : overlay et lecture
Objetivos
Activar el I2C del conector de 40 pines del Le Potato (desactivado por defecto) y luego leer un sensor BME280 (temperatura, humedad, presión) en Python.
Material
- Le Potato AML-S905X-CC con Armbian mainline
- Módulo BME280 (dirección 0x76 por defecto, 0x77 si ADDR=1)
- Cableado 3,3 V / GND / SDA / SCL en los pines I2C del encabezado (ningún pin de 5 V)
sudo apt install i2c-tools python3-smbus
Código completo
# 1) Activer l'I2C : sudo armbian-config -> System > Options > HW interfaces
# (ou overlay dédié, cf. « How to Enable I2C on AML-S905X-CC » sur hub.libre.computer)
sudo reboot
sudo i2cdetect -y 0 # le bus peut être i2c-0 ou i2c-1 : ls /dev/i2c-*
#!/usr/bin/env python3
# bme280.py — lecture brute des registres (bus 0, adresse 0x76)
import smbus, time
bus = smbus.SMBus(0); ADDR = 0x76
bus.write_byte_data(ADDR, 0xD0, 0x00) # soft reset
reg = bus.read_byte_data(ADDR, 0xD0)
print("chip id:", hex(reg)) # attendu 0x60
bus.write_byte_data(ADDR, 0xF4, 0x27) # t+p oversampling x1
bus.write_byte_data(ADDR, 0xF5, 0x00) # mode forcé
def lire(reg): # 24 bits signé, format BME280
v = (bus.read_byte_data(ADDR, reg) << 12) | \
(bus.read_byte_data(ADDR, reg+1) << 4) | \
(bus.read_byte_data(ADDR, reg+2) >> 4)
return v - 16777216 if v > 8388607 else v
time.sleep(0.1)
print("temp brute:", lire(0xFA) / 100.0, "degres")
Verificación esperada
i2cdetect -y 0 muestra 0x76; el script imprime chip id: 0x60 y una temperatura coherente (el campo bruto calibrado es suficiente para una prueba; para mayor precisión, utilice la biblioteca bme280/adafruit-circuitpython-bme280 pasando explícitamente el bus).
Errores frecuentes
- Overlay I2C no activado: «Could not open device» — el I2C NO está activo por defecto en esta placa.
- Número de bus incorrecto: pruebe
i2cdetect -y 1; CircuitPython requiere el bus explícito. - Bus de 5 V o módulo de 5 V alimentado a 5 V: los pines solo aceptan 3,3 V.
chip id: 0x00: cableado SDA/SCL invertido o dirección 0x77.
Otros tutoriales para esta placa
- Faire clignoter une LED en C avec libgpiod sur Le Potato
- Lire un bouton poussoir avec libgpiod (pull-up interne)
- GPIO en Python avec python3-libgpiod sur Le Potato
- Fondu LED progressif avec PWM sous sysfs (meson)
- Console série (ttyAML0) et SSH sur Le Potato
- Boot SD/eMMC et récupération (pyamlboot) sur Amlogic S905X
Ejemplos de código para esta placa
clignotante.pyPythonbouton-gpio.pyPythoncapteur-i2c.shBashsurveillance-temperature.shBashcapteur-dht11.pyPythonservo-pwm-sysfs.shBash