code.py
1 # SPDX-FileCopyrightText: 2022 Carter Nelson for Adafruit Industries 2 # 3 # SPDX-License-Identifier: MIT 4 5 import time 6 import board 7 import adafruit_tca9548a 8 from adafruit_bme280 import basic as adafruit_bme280 9 10 # Create I2C bus as normal 11 i2c = board.I2C() 12 13 # Create the TCA9548A object and give it the I2C bus 14 tca = adafruit_tca9548a.TCA9548A(i2c) 15 16 #-------------------------------------------------------------------- 17 # NOTE!!! This is the "special" part of the code 18 # 19 # Create each BME280 using the TCA9548A channel instead of the I2C object 20 bme1 = adafruit_bme280.Adafruit_BME280_I2C(tca[0]) # TCA Channel 0 21 bme2 = adafruit_bme280.Adafruit_BME280_I2C(tca[1]) # TCA Channel 1 22 bme3 = adafruit_bme280.Adafruit_BME280_I2C(tca[2]) # TCA Channel 2 23 #-------------------------------------------------------------------- 24 25 print("Three BME280 Example") 26 27 while True: 28 # Access each sensor via its instance 29 pressure1 = bme1.pressure 30 pressure2 = bme2.pressure 31 pressure3 = bme3.pressure 32 33 print("-"*20) 34 print("BME280 #1 Pressure =", pressure1) 35 print("BME280 #2 Pressure =", pressure2) 36 print("BME280 #3 Pressure =", pressure3) 37 38 time.sleep(1)