TCA9548A with BME680

Hi Team,

I am unable to retrieve BME680 data using 8 Port Multiplexer. Could you please advise.

import time
import board
import busio
import adafruit_bme680
import adafruit_tca9548a

Create I2C bus as normal

i2c = board.I2C() # uses board.SCL and board.SDA

Create the TCA9548A object and give it the I2C bus

tca = adafruit_tca9548a.TCA9548A(i2c)

Select channel 1

tca.channels[1].enabled = True

Create separate I2C instance for channel 1

i2c_bme680 = busio.I2C(board.SCL, board.SDA)

For the BME680 sensor, create it using the separate I2C instance

bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c_bme680)

After initial setup, you can use the BME680 sensor as normal.

while True:
temperature = bme680.temperature
humidity = bme680.humidity
pressure = bme680.pressure
gas = bme680.gas

print("Temperature:", temperature)
print("Humidity:", humidity)
print("Pressure:", pressure)
print("Gas Resistance:", gas)

time.sleep(1)

Thanks,
Ravi

Hi, do you have any problems with the code or any other wiki? Can you point out which wiki is the problem?
Maybe you can try to check whether the wiring is correct, whether the interface is loose, if not the above problem, you need to consider the problem of the code part

Dear Seeed team,

I have similar trouble with 3 BME688 sensors plugged in the multiplexer. I manage to see the multiplexer and sensors when using a scanner but when adapting the BME688 code to work with the multiplexer, it never initialize. I am not an expert coder and would very much like to understand what is wrong with it.

Here is the code :

#include <Wire.h>

#include <TCA9548A.h>

#include “seeed_bme680.h”

#define TCA_ADDR 0x70 // I2C address of the TCA9548A multiplexer

TCA9548A tca;

#define BME_SCK 13

#define BME_MISO 12

#define BME_MOSI 11

#define BME_CS 10

#define BME680_IIC_ADDR1 uint8_t(0x76)

#define BME680_IIC_ADDR2 uint8_t(0x77)

#define BME680_IIC_ADDR3 uint8_t(0x78)

Seeed_BME680 bme680_1;

Seeed_BME680 bme680_2;

Seeed_BME680 bme680_3;

void setup() {

Serial.begin(9600);

while (!Serial);

Wire.begin();

tca.begin(Wire);

Serial.println("Serial start!!!");

delay(100);

initializeBME680(bme680_1, BME680_IIC_ADDR1, "Sensor 1");

initializeBME680(bme680_2, BME680_IIC_ADDR2, "Sensor 2");

initializeBME680(bme680_3, BME680_IIC_ADDR3, "Sensor 3");

}

void loop() {

// Reading from the first BME680 sensor

tca.openChannel(0);

readAndPrintSensorData(bme680_1, "Sensor 1");

// Reading from the second BME680 sensor

tca.openChannel(1);

readAndPrintSensorData(bme680_2, "Sensor 2");

// Reading from the third BME680 sensor

tca.openChannel(2);

readAndPrintSensorData(bme680_3, "Sensor 3");

delay(2000);

}

void initializeBME680(Seeed_BME680 &bme, uint8_t i2cAddress, const char *sensorName) {

bme = Seeed_BME680(i2cAddress);

if (!bme.init()) {

    Serial.print("Failed to initialize ");

    Serial.print(sensorName);

    Serial.println(" BME680 sensor! Can't find device!");

    while (1);

}

}

void readAndPrintSensorData(Seeed_BME680 &bme, const char *sensorName) {

if (bme.read_sensor_data()) {

    Serial.print("Failed to perform reading on ");

    Serial.println(sensorName);

    return;

}

Serial.print(sensorName);

Serial.print(" - Temperature: ");

Serial.print(bme.sensor_result_value.temperature);

Serial.print(" C, Pressure: ");

Serial.print(bme.sensor_result_value.pressure / 1000.0);

Serial.print(" KPa, Humidity: ");

Serial.print(bme.sensor_result_value.humidity);

Serial.print(" %, Gas Resistance: ");

Serial.print(bme.sensor_result_value.gas / 1000.0);

Serial.println(" Kohms");

Serial.println();

}