Here's the same thing for CircuitPython:

# SPDX-FileCopyrightText: 2022 Carter Nelson for Adafruit Industries
#
# SPDX-License-Identifier: MIT

import time
import board
import adafruit_tca9548a
from adafruit_bme280 import basic as adafruit_bme280

# Create I2C bus as normal
i2c = board.I2C()  # uses board.SCL and board.SDA
# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller

# Create the TCA9548A object and give it the I2C bus
tca = adafruit_tca9548a.TCA9548A(i2c)

#--------------------------------------------------------------------
# NOTE!!! This is the "special" part of the code
#
# Create each BME280 using the TCA9548A channel instead of the I2C object
bme1 = adafruit_bme280.Adafruit_BME280_I2C(tca[0])   # TCA Channel 0
bme2 = adafruit_bme280.Adafruit_BME280_I2C(tca[1])   # TCA Channel 1
bme3 = adafruit_bme280.Adafruit_BME280_I2C(tca[2])   # TCA Channel 2
bme4 = adafruit_bme280.Adafruit_BME280_I2C(tca[3])   # TCA Channel 3
#--------------------------------------------------------------------

print("Four BME280 Example")

while True:
    # Access each sensor via its instance
    pressure1 = bme1.pressure
    pressure2 = bme2.pressure
    pressure3 = bme3.pressure
    pressure4 = bme4.pressure

    print("-"*20)
    print("BME280 #1 Pressure =", pressure1)
    print("BME280 #2 Pressure =", pressure2)
    print("BME280 #3 Pressure =", pressure3)
    print("BME280 #4 Pressure =", pressure4)

    time.sleep(1)

With that code running on the CircuitPython board, the output will look like this:

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
Four BME280 Example
--------------------
BME280 #1 Pressure = 1014.0
BME280 #2 Pressure = 1013.72
BME280 #3 Pressure = 1013.73
BME280 #4 Pressure = 1013.75
--------------------
BME280 #1 Pressure = 1013.99
BME280 #2 Pressure = 1013.72
BME280 #3 Pressure = 1013.76
BME280 #4 Pressure = 1013.73
--------------------
BME280 #1 Pressure = 1013.98
BME280 #2 Pressure = 1013.71
BME280 #3 Pressure = 1013.74
BME280 #4 Pressure = 1013.75

Again, there is little more done compared to the 3xBME280s example other than adding a new instance for the 4th sensor, specifying the TCA9548A channel:

bme4 = adafruit_bme280.Adafruit_BME280_I2C(tca[3])   # TCA Channel 3

And then using it like the others:

pressure4 = bme4.pressure

This guide was first published on May 04, 2022. It was last updated on May 04, 2022.

This page (CircuitPython) was last updated on May 31, 2023.

Text editor powered by tinymce.