🛠 Interroger un capteur I2C (BME280) sur le bus du 40 broches

Raspberry Pi Model B+ (2014) — Board Sheet · intermediaire · Schéma : IMG-model-b-plus-intermediaire-2-modelbp-i2c-capteur.svg — capteur BME280 relié au bus I2C0 : SDA sur broche 3 (GPIO2), SCL sur broche 5 (GPIO3), VCC 3,3 V (broche 1) et GND (broche 6), avec les résistances de pull-up du module.

Objectives

Enable the I2C bus on the Model B+ (I2C0 is available by default on the 40-pin connector), scan the bus with i2cdetect, then read the identification number of a BME280 sensor in Python — proving that the hardware/software chain works before using the measurements.

Hardware

Complete code

# Activer I2C : raspi-config > Interfaces de connexion > I2C, ou :
echo "dtparam=i2c_arm=on" | sudo tee -a /boot/config.txt
sudo reboot
sudo apt install -y i2c-tools python3-smbus
i2cdetect -y 1        # le BME280 doit répondre à 0x76 (ou 0x77)
#!/usr/bin/env python3
"""Lecture de l'ID du BME280 sur i2c-1 — Model B+."""
import smbus

ADDR = 0x76                      # 0x77 si l'adresse SDO est montée
bus = smbus.SMBus(1)
chip_id = bus.read_byte_data(ADDR, 0xD0)
print(f"BME280 chip id: 0x{chip_id:02X}")   # attendu 0x60 (BMP280 : 0x58)

Expected verification

i2cdetect -y 1 displays a grid where the cell 76 is marked. The Python script prints “BME280 chip id: 0x60”. With a BMP280, 0x58 confirms a neighboring sensor; 0x55 or 0xFF indicates a power supply issue.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials