pimoroni / bme280-python

Python library for the BME280 temperature, pressure and humidity sensor
https://shop.pimoroni.com/products/bme280-breakout
MIT License
65 stars 25 forks source link

Binho Nova adapter instructions #24

Open rxbynerd opened 1 year ago

rxbynerd commented 1 year ago

Not submitting this as a PR to the documentation as I'm not confident in it at all, but wanted to capture this atrocity I've just cooked up, to read a BME280 via the Binho Nova host adapter's Python library:

class BinhoSmbusShim:
    def __init__(self, host_adapter):
        self.binho = host_adapter
    def read_i2c_block_data(self, i2c_address, register, length):
        return self.binho.i2c.transfer(i2c_address, [register], length)

    def write_i2c_block_data(self, i2c_address, register, values):
        self.binho.i2c.transfer(i2c_address, [register] + values, 0)

Usage instructions:

    binho = binhoHostAdapter()
    binho.operationMode = "I2C"

    bme280 = BME280(i2c_dev=BinhoSmbusShim(binho))
    bme280.setup()
    # you can now follow examples/

Fairly confident this glosses over a lot of details (like register width?), but this was enough to get temperature/humidity/pressure out of the sensor so I can carry on with software.

I'm also aware you're no longer stocking Binho Nova, so no worries if you don't want to add in support/documentation for use — this note is just to capture this info in the public domain for next time I need it 🙈