🛠 Lire un capteur I2C (BMP280) depuis le bus du connecteur
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
- Orange Pi 5 Plus (Armbian or Orange Pi OS image)
- BMP280 sensor (I2C module, default address 0x76)
- 4 jumpers: SDA, SCL, 3.3 V, GND — never use 5 V on a 3.3 V non-tolerant sensor
sudo apt install -y i2c-tools python3-smbus2(package python3-smbus depending on the distribution)
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
- Bus not enabled in the device-tree:
i2cdetect -ldoes not show a bus connected to the connector; on an Orange Pi image, enable the controller viasudo orangepi-config(System → Hardware) then reboot. - Wrong bus number between physical pinout and /dev/i2c-N: scan each bus listed by i2cdetect -l.
- Sensor powered at 5 V on 3.3 V lines or SDA/SCL swapped: no address responds.
- >
Other tutorials for this board
- Allumer une LED via le GPIO 40 broches (libgpiod)
- Lire un bouton poussoir et afficher dans la console
- Premier script Python : fiche signalétique de la carte et LED
- Variation d'intensité d'une LED avec PWM (sysfs pwm)
- Exploiter le double Ethernet 2,5 GbE et sécuriser le SSH
- Booter sur NVMe (M.2 PCIe 3.0 x4) et récupérer une carte brique via MaskROM
Code examples for this board
clignotante.pyPythonbouton-gpio.pyPythoncapteur-i2c.shBashsurveillance-temperature.shBashcapteur-dht11.pyPythonservo-pwm-sysfs.shBash