🛠 BME280 sur I2C0 (GPIO2/3) : activer i2c_arm et lire l'ID 0x60

Raspberry Pi Compute Module 1 (CM1) · intermediaire · Schéma : IMG-cm1-intermediaire-2-bme280-i2c0-cm1.svg — Un capteur BME280 adresse 0x76 relié aux broches GPIO2 (SDA) et GPIO3 (SCL) du Compute Module 1, avec la ligne dtparam=i2c_arm=on dans config.txt et le registre 0xD0 renvoyant 0x60

Objectives

Connect a BME280 temperature/humidity/pressure sensor to the CM1's I2C bus. The "user" I2C bus is I2C0, wired to GPIO2 (SDA) and GPIO3 (SCL); it must be enabled with dtparam=i2c_arm=on in config.txt. The BME280 appears at address 0x76 (or 0x77 depending on the SDO pin), and its identification register 0xD0 must return 0x60. Beware of habits from the RPi 3/4: the CM1 has no built-in ADC converter, so an analog sensor requires an external ADC (e.g., MCP3008 over SPI).

Hardware

Complete Code

# Activer I2C (config.txt du CM1, redémarrage requis)
echo 'dtparam=i2c_arm=on' | sudo tee -a /boot/config.txt
sudo reboot

# Scanner le bus
sudo apt install -y i2c-tools
sudo i2cdetect -y 0        # le BME280 apparaît en 76

# Lire l'ID : registre 0xD0 -> 0x60
sudo i2cget -y 0 0x76 0xD0

# Température brute (registres 0xFA..0xFC, format 20 bits signé)
T=$(sudo i2cget -y 0 0x76 0xFA; sudo i2cget -y 0 0x76 0xFB; sudo i2cget -y 0 0x76 0xFC)
# pip install smbus2
import smbus2
b = smbus2.SMBus(0)
print(hex(b.read_byte_data(0x76, 0xD0)))   # 0x60

Expected Verification

i2cdetect -y 0 displays 76; i2cget on 0xD0 returns 0x60, the BME280 signature (the BMP280 returns 0x58, the BME680 returns 0x61). When initializing the sensor (forced mode), the measurement registers change with finger temperature. The bus is indeed named /dev/i2c-0 on the CM1 — not /dev/i2c-1 as on recent RPi models.

Common Errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials