pimoroni / bme680-python

Python library for the BME680 gas, temperature, humidity and pressure sensor.
https://shop.pimoroni.com/products/bme680
MIT License
260 stars 93 forks source link

SPI instead of I2C? #27

Open oxboxer opened 4 years ago

oxboxer commented 4 years ago

I need 3 sensors, but there are unfortunately only 2 I2C addresses. So i have to use SPI instead of I2C. Is there a way to use the same library in SPI?

Gadgetoid commented 4 years ago

As much as I hate to say it - since we only provide breakouts that use the i2c interface and this library is strongly i2c focussed - I'm afraid I can't support use over SPI.

You can- however- throw up an additional i2c bus using i2c-gpio (documentation in the overlays readme: https://raw.githubusercontent.com/raspberrypi/firmware/master/boot/overlays/README) on a Raspberry Pi using any two regular GPIO pins and appropriate pull resistors.

Then you can initialise the BME680 library with your new i2c bus like so:

from smbus import SMBus
from bme680 import BME680

bme680 = BME680(i2c_device=SMBus(N))

SPI support is something I would consider reviewing and merging a PR for, however, since I know many people using breakouts not manufactured by us use this library and may want this feature.

oxboxer commented 4 years ago

Thanks for the answer. I think i'm gonna buy an i2c multiplexer und use this.

tristanCB commented 3 years ago

This scenario happened to me too. I ended up using the TCA9548A I2C Multiplexer to get this accomplished. Worked like a charm. If you are quick pintch in a hurry you can use a GPIO to power the sensor (it requires really low current so a gpio pin set to high is enough) and just cycle them from high to low sequentially to get all measurements.