🛠 Lire un capteur I2C (BME280) sur le bus

Orange Pi PC (Allwinner H3) · intermediaire · Schéma : IMG-orangepi-pc-intermediaire-2-opipc-i2c-capteur.svg — Capteur BME280 relié aux lignes SDA/SCL du connecteur 40 broches de l'Orange Pi PC en 3.3 V, adresses I2C balayées par i2cdetect, température et pression remontées dans un terminal.

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

Complete Code

  1. 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
  1. 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

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials