🛠 Lire un capteur I²C (BME280) sur le bus i2c-1 du connecteur Pi-2

Pine64 PINE A64 / PINE A64+ (Allwinner A64) · intermediaire · Schéma : IMG-pine64-intermediaire-2-capteur-i2c-bme280.svg — PINE A64 sur breadboard avec un module BME280 branche sur SDA/SCL du connecteur 40 broches (broches PH2/PH3 annotees), alimente en 3,3V, terminal affichant i2cdetect -r 1 avec 0x76 detecte et valeurs brutes lues en Python

Objectives

On mainline PINE A64 images, the i2c-1 bus is enabled by default in the device tree (&i1c1 with the i2c1_pins pin group on PH2/PH3 of the Pi-2 connector, pull-ups included): an I²C sensor works without an overlay. You will wire a BME280 (temperature/pressure/humidity), detect it with i2cdetect, and read it in Python via smbus2 — while understanding the numbering: PH2 = (H−A)×32 + 2 = 226, PH3 = 227, if you need to replay the pinctrl configuration manually.

Hardware

Complete code

# Lister les bus puis scanner le bus 1 (&i2c1 activé dans le DTS) :
i2cdetect -l
i2cdetect -r 1        # doit afficher 76 (ou 77)
#!/usr/bin/env python3
"""Lecture brute d'un BME280 sur i2c-1 (broches PH2/PH3 du connecteur Pi-2)."""
import smbus2, time

BUS  = 1          # &i2c1 est activé dans sun50i-a64-pine64.dts
ADDR = 0x76       # 0x77 si la broche CSB est tirée à 1
bus = smbus2.SMBus(BUS)
assert bus.read_byte_data(ADDR, 0xD0) in (0x52, 0x53), "pas de BME280 (id?)"
bus.write_byte_data(ADDR, 0xF4, 0x27)   # temp x1, press x1, mode normal
bus.write_byte_data(ADDR, 0xF5, 0x00)   # veille 1 Hz
time.sleep(0.1)
print("octets bruts pression:", bus.read_i2c_block_data(ADDR, 0xF7, 6))
# Pour des unités lisibles, utiliser un driver (adafruit-blinka, bme280-i2c) ;
# les formules de compensation complètes sont dans la datasheet BME280.

Expected verification

i2cdetect -r 1 displays 76: the i2c-1 bus exists, the DTS pull-ups are doing their job, and the sensor responds. The Python script prints the 6 raw pressure bytes (registers 0xF7–0xFC) which change when you press the sensor with your finger. The identity test (0xD0 = 0x52) validates the link before any measurement — the assertion fails loudly if the wiring is incorrect.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials