Not quite sure the best place to put this but I’ve been able to communicate with the BME280 breakout board using the Pico and MicroPython though my code still needs more work it might help people communicate with more breakout boards or finish the bme280 calibration calculations part which is missing from mine:
from machine import Pin, I2C
from micropython import const
from time import sleep_ADDR = const(0x76)
_CALIB2 = const(0xe1)
_CALIB1 = const(0x88)
_DATA = const(0xf7)
_CONFIG = const(0xf5)
_CTRL_MEAS = const(0xf4)
_CTRL_HUM = const(0xf2)
_CHIP_ID = const(0xd0)
_RESET = const(0xe0)class TooManyAttempts(Exception):
“”“Too many attempts”“”class BME280:
def init(self, i2c):
self._i2c = i2c
self._ready = bytearray(1)
self._chip_id = bytearray(1)
self._data = bytearray(8)
self._calib1 = bytearray(26)
self._calib2 = bytearray(7)def ready(self): attempts = 100 while True: self._i2c.readfrom_into(_ADDR, self._ready) if self._ready == b'\x00': break attempts -= 1 if not attempts: raise TooManyAttempts() def chip_id(self): self.ready() self._i2c.readfrom_mem_into(_ADDR, _CHIP_ID, self._chip_id) return self._chip_id def reset(self): self.ready() self._i2c.writeto_mem(_ADDR, _RESET, b'\xb6') def ctrl_hum(self, osrs_h=16): self.ready() self._i2c.writeto_mem(_ADDR, _CTRL_HUM, chr(0b101)) def ctrl_meas(self, osrs_t=16, osrs_p=16, mode='normal'): self.ready() self._i2c.writeto_mem(_ADDR, _CTRL_MEAS, chr(0b10110111)) def config(self, t_sb=500, filter=2): self.ready() self._i2c.writeto_mem(_ADDR, _CONFIG, chr(0b10001000)) def data(self): self.ready() self._i2c.readfrom_mem_into(_ADDR, _DATA, self._data) return self._data def calibration(self): self.ready() self._i2c.readfrom_mem_into(_ADDR, _CALIB1, self._calib1) self.ready() self._i2c.readfrom_mem_into(_ADDR, _CALIB2, self._calib2) def init(self): self.reset() sleep(0.1) self.ctrl_hum() self.ctrl_meas() self.config() self.calibration()
bme280 = BME280(I2C(0, scl=Pin(21), sda=Pin(20)))
print(bme280.chip_id())