🛠 Capteur BME280 (I2C) sur Le Potato : overlay et lecture

Libre Computer Amlogic boards — libre-amlogic (flagship: Le Potato AML-S905X-CC) · intermediaire · Schéma : IMG-libre-amlogic-intermediaire-2-libre-amlogic-intermediaire-i2c-bme280.svg — BME280 câblé en I2C (SDA/SCL 3,3 V) sur le connecteur 40 broches du Le Potato après activation de l'overlay I2C.

Objectives

Enable the I2C interface on the Le Potato's 40-pin header (disabled by default) and read a BME280 sensor (temperature, humidity, pressure) in Python.

Hardware

Complete Code

# 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")

Expected Verification

i2cdetect -y 0 displays 0x76; the script prints chip id: 0x60 and a consistent temperature (the raw calibrated field is sufficient for a test; for accuracy, use the bme280/adafruit-circuitpython-bme280 library with the bus explicitly passed).

Common Errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials