# bme280.py – MicroPython driver for BME280 sensor import time from ustruct import unpack, unpack_from from machine import I2C class BME280: def __init__(self, i2c, addr=0x76): self.i2c = i2c self.addr = addr self.dig = {} self._read_coefficients() self._write_register(0xF4, 0x27) # Normal mode, oversampling 1x self._write_register(0xF5, 0xA0) # Standby 1000ms, filter off def _read_coefficients(self): # Read calibration registers data = self._read_register(0x88, 24) self.dig["T1"] = unpack("> 4) adc_T = (data[3] << 12) | (data[4] << 4) | (data[5] >> 4) T, t_fine = self.compensate_temperature(adc_T) P = self.compensate_pressure(adc_P, t_fine) return T, P # temperature in °C, pressure in hPa