🛠 BME280 sur I2C0 (GPIO2/3) : activer i2c_arm et lire l'ID 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
- A Compute Module 1 on an IO Board
- A BME280 module (I2C, default address 0x76)
- Wiring: VCC 3V3, GND, GPIO2=SDA, GPIO3=SCL (pull-ups present on the module)
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
- Looking for
/dev/i2c-1: on CM1/BCM2835, the user bus is 0; scripts copied from RPi 3/4 fail here. - Forgetting
dtparam=i2c_arm=onor rebooting:i2cdetect -llists no buses. - Expecting an analog input on a GPIO: the CM1 has no ADC, a classic error when migrating from Arduino; add an MCP3008/ADS1115.
- Leaving SDO floating on a bare module: the address may switch between 0x76 and 0x77, scan both.
- Powering an unregulated BME280 module with 5 V: exceeds 3.3 V logic levels, damaging the fragile sensor.
Other tutorials for this board
- Flasher l'eMMC du CM1 avec rpiboot et le jumper J4
- Premier boot : Bullseye legacy, rails 3,3 V et ordre des alimentations
- Première LED sur GPIO17 : banques, courants et broches réservées
- Servo moteur sur PWM0 (GPIO18) : 50 Hz et 2,5 à 12,5 %
- Caméra officielle sur le connecteur FPC CSI du CM1
- Boot sans EEPROM : fallback USB et bootcode.bin sur eMMC
Code examples for this board
clignotante.pyPythonbouton-gpio.pyPythoncapteur-i2c.shBashsurveillance-temperature.shBashcapteur-dht11.pyPythonservo-pwm-sysfs.shBash