🛠 Lire un capteur I2C (BME280) sur le bus
Objectives
Implement I2C on the Orange Pi PC: enable the bus, scan addresses with i2cdetect, then read a BME280 temperature/pressure/humidity sensor in Python. You will also discover that the board already has an internal I2C device: the CPU voltage regulator SY8106A, on the R_I2C bus (secondary bus) at address 0x65 — proof that the I2C stack works even without anything connected.
Hardware
- Orange Pi PC running Armbian, 5 V / 2 A power supply (DC jack)
- BME280 sensor (module with 3.3 V regulator recommended)
- Dupont cables: VCC→3.3 V, GND→GND, SDA→SDA pin, SCL→SCL pin
- sudo apt install i2c-tools python3-smbus
Complete Code
- Enable I2C (armbian-config > Hardware > Overlays > i2c) and scan:
sudo sed -i 's/^overlays=.*/& i2c0/' /boot/armbianEnv.txt && sudo reboot
i2cdetect -l # lister les bus
i2cdetect -y 0 # balayer le bus 0 : le BME280 répond 0x76 ou 0x77
- Python reading (ID register + simplified raw data):
#!/usr/bin/env python3
"""bme280_lut.py — lecture bas niveau d'un BME280 sur Orange Pi PC."""
import smbus, time
BUS, ADDR = smbus.SMBus(0), 0x76 # 0x77 si ADDR du module câblé à VCC
def main -> None:
chip_id = BUS.read_byte_data(ADDR, 0xD0)
print(f"Chip ID : 0x{chip_id:02X} (attendu 0x52)")
# Configuration forcée en mode capteur (datasheet BME280, registre 0xF4)
BUS.write_byte_data(ADDR, 0xF4, 0x27) # x1/x1 oversampling, mode normal
time.sleep(0.1)
for _ in range(5):
# Température brute (registres 0xFA-0xFC) — conversion simplifiée
msb, mid, lsb = BUS.read_i2c_block_data(ADDR, 0xFA, 3)
adc_t = (msb << 12) | (mid << 4) | (lsb >> 4)
t_c = (adc_t / 16384.0 - 50.0) # approximation linéaire, hors compensation
print(f"ADC temp : {adc_t:6d} -> ~{t_c:5.1f} °C (non compensé)")
time.sleep(1)
if __name__ == "__main__":
main
For exact compensated values, install the adafruit-circuitpython-bme280 library (pip3).
Expected Verification
i2cdetect displays a grid with 76 (or 77) occupied. The script prints Chip ID : 0x52, followed by 5 lines of temperature. On the internal R_I2C bus, a dedicated scan would show the SY8106A regulator at 0x65.
Common Errors
- Bus not enabled by overlay: i2cdetect -l shows no bus — reboot after modifying armbianEnv.txt.
- Powering the module with 5 V on a 3.3 V sensor without a regulator: risk of destruction (3.3 V logic on the H3).
- Wrong address (0x76 vs 0x77): the module has an ADDR jumper; run i2cdetect first.
- SCL/SDA swapped: the scan returns an empty grid without an explicit error.
Other tutorials for this board
Code examples for this board
clignotante.pyPythonbouton-gpio.pyPythoncapteur-i2c.shBashsurveillance-temperature.shBashcapteur-dht11.pyPythonservo-pwm-sysfs.shBash