🛠 Brancher un capteur BME280 sur l'I2C1 du carrier (GPIOX_17/18)

Banana Pi BPI-CM4 (Amlogic A311D, Raspberry Pi CM4 form factor) · intermediaire · Schéma : IMG-bananapi-cm4-intermediaire-2-i2c-bme280-banapi-cm4.svg — module BME280 câblé sur le header 26 broches du BPI-CM4IO : SDA sur la broche 3 (GPIOX_17), SCL sur la broche 5 (GPIOX_18), VCC en 3V3 et GND, résistances de pull-up intégrées au module.

Objectives

Mount a BME280 temperature/humidity/pressure sensor on the carrier's I2C1 bus, wired to GPIOX_17 (SDA, pin 3) and GPIOX_18 (SCL, pin 5) according to the BPI-CM4IO pinout table. You will enable the controller (overlays tutorial), resolve the actual bus number (the mainline &i2c2 controller has no alias), scan the bus, verify the chip ID (0x60), and then read the raw temperature in Python via i2c-dev — the method is identical on BSP 4.9 and on Armbian.

Hardware

Complete code

sudo apt install -y i2c-tools
# Résoudre le numéro du bus du header (contrôleur &i2c2, non aliasé)
for d in /sys/class/i2c-dev/i2c-*; do
  echo "$(basename $d) -> $(cat $d/of_node/name 2>/dev/null)"
done
i2cdetect -y 2        # adapter N ; la case 76 doit apparaître
#!/usr/bin/env python3
"""bme280_cm4.py — lecture BME280 sur le BPI-CM4 (BUS = numéro trouvé plus haut)."""
import fcntl, time

BUS, ADDR = 2, 0x76            # à ajuster selon i2cdetect -l
I2C_SLAVE = 0x0703

def read_regs(reg, n=1):
    with open(f"/dev/i2c-{BUS}", "rb+", buffering=0) as f:
        fcntl.ioctl(f, I2C_SLAVE, ADDR)
        f.write(bytes([reg]))
        return f.read(n)

chip_id = read_regs(0xD0)[0]
print(f"chip ID 0x{chip_id:02X} (attendu 0x60 pour un BME280)")

# Reset doux puis mesure forcée T+x1, P+x1
with open(f"/dev/i2c-{BUS}", "wb+", buffering=0) as f:
    fcntl.ioctl(f, I2C_SLAVE, ADDR)
    f.write(bytes([0xE0, 0xB6])); time.sleep(0.05)
    f.write(bytes([0xF4, 0x27]))
time.sleep(0.1)
raw = read_regs(0xFA, 3)       # MSB..XLSB température (20 bits)
temp = ((raw[0] << 16) | (raw[1] << 8) | raw[2]) >> 4
print(f"température brute (registre 20 bits) : {temp}")

Expected verification

i2cdetect displays 76 on the header bus; the script prints chip ID 0x60; when blowing on the sensor, the raw value of the 20-bit register decreases regularly. For a complete physical value, read the calibration coefficients (blocks 0x88-0xA1 and 0xE1-0xE7) and apply the compensation from the Bosch datasheet, or use an existing BME280 library.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials