🛠 Lire un capteur I2C (BMP280) depuis le bus du connecteur

Orange Pi 5 Plus (Rockchip RK3588) · intermediaire · Schéma : IMG-orangepi-5-plus-intermediaire-2-opi5p-i2c-capteur.svg — capteur BMP280 relié en I2C (SDA, SCL, 3,3 V, GND) au connecteur 40 broches de l'Orange Pi 5 Plus, valeurs température/pression affichées en terminal

Objectives

Enable and explore an I2C bus on the Orange Pi 5 Plus, scan the bus with i2cdetect, then read a BMP280 sensor (temperature + pressure, address 0x76 or 0x77) in Python using smbus2. The 40-pin connector multiplexes I2C among UART/SPI/CAN/PWM; internally, the RK806-1 PMIC is on SPI and the RK8602/RK8603 regulators are already on I2C — the controller connected to the connector must be verified on your image.

Hardware

Complete code

# 1. Lister les contrôleurs I2C puis balayer le bus du connecteur
i2cdetect -l
i2cdetect -y 1        # adapter N ; le BMP280 apparaît à 76 (ou 77)

# Lecture brute en shell :
sudo i2cget -y 1 0x76 0xd0    # doit répondre 0x58 (ID du BMP280)
#!/usr/bin/env python3
"""Lecture BMP280 sur i2c-1 (adapter le numéro de bus)."""
import smbus2, struct, time

BUS, ADDR = 1, 0x76
bus = smbus2.SMBus(BUS)
assert bus.read_byte_data(ADDR, 0xD0) == 0x58, "BMP280 introuvable"

# Calibration (registres 0x88..0xA1)
cal = bus.read_i2c_block_data(ADDR, 0x88, 24)
dig_T1, dig_T2, dig_T3 = struct.unpack("<Hhh", bytes(cal[0:6]))

bus.write_byte_data(ADDR, 0xF4, 0x27)   # mode forcé, oversampling x16/x1
bus.write_byte_data(ADDR, 0xF5, 0xA0)   # standby 1000 ms, filtre x16
time.sleep(0.1)
raw = bus.read_i2c_block_data(ADDR, 0xF7, 6)
adc_p, adc_t = struct.unpack(">HH", bytes(raw[0:4]))

# Compensation température simplifiée du datasheet
var1 = (adc_t / 16384.0 - dig_T1 / 1024.0) * dig_T2
var2 = ((adc_t / 131072.0 - dig_T1 / 8192.0) ** 2) * dig_T3
t_fine = var1 + var2
temp = (t_fine * 5.12) / 100.0
print(f"Température : {temp:.1f} °C (ADC pression brut : {adc_p})")

Expected verification

i2cdetect -y N displays “76” in the grid; i2cget ... 0xd0 returns 0x58; the Python script prints a temperature consistent with the room (15 to 30 °C). For pressure, prefer the Adafruit_BMP280 library (pip) which implements full compensation.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials