🛠 Lire un capteur I2C (Weather Board Zero)

ODROID-C4 (Hardkernel) · intermediaire · Schéma : IMG-odroid-c4-intermediaire-2-odroidc4-i2c-capteur.svg — Weather Board Zero Hardkernel emboîtée sur le connecteur 40 broches, bus SDA/SCL (3,3 V) reliant le capteur BME-class au SoC S905X3.

Objectives

Enable the I2C bus on the ODROID-C4 under Armbian mainline and read a BME680-type environmental sensor (Hardkernel Weather Board Zero, ~$2): address detection with i2cdetect, register reading in Python via smbus, and declarative activation of overlays in armbianEnv.txt.

Hardware

Full code

# 1) Activer I2C (Armbian) puis redémarrer
sudo sed -i 's/^#*overlay_add=.*/overlay_add=i2c0/' /boot/armbianEnv.txt
sudo reboot
# 2) Détecter le capteur
i2cdetect -l        # lister les bus
i2cdetect -y 0      # le capteur répond à 0x76 ou 0x77
#!/usr/bin/env python3
# lecture_bme.py - CHIP_ID + température brute (démo non calibrée)
import smbus, time
BUS, ADDR = 0, 0x77   # adapter selon i2cdetect
bus = smbus.SMBus(BUS)
chip_id = bus.read_byte_data(ADDR, 0xD0)
assert chip_id == 0x61, f"chip id inattendu {chip_id:#x}"

def read_reg24(reg):
    msb, lsb, xlsb = bus.read_i2c_block_data(ADDR, reg, 3)
    return (msb << 12) | (lsb << 4) | (xlsb >> 4)

while True:
    t = read_reg24(0x24) / 16384.0 - 50.0
    print(f"température brute ≈ {t:6.2f} °C (CHIP_ID={chip_id:#04x})")
    time.sleep(2)

Expected verification

i2cdetect -y 0 displays a grid with a non-empty cell at 0x76 or 0x77. The Python script prints a temperature line and the CHIP_ID 0x61 every 2 seconds; Ctrl+C stops it cleanly. The raw value is approximate (demonstration without BME680 calibration table) but should change when you warm the sensor with your finger.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials