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 #-------------------------------------------------------------------- 14 # NOTE!!! This is the "special" part of the code 15 # 16 # For each TCA9548A, create a separate instance and give each 17 # the *same* I2C bus but with specific address for each 18 tca1 = adafruit_tca9548a.TCA9548A(i2c, 0x70) # TCA with address 0x70 19 tca2 = adafruit_tca9548a.TCA9548A(i2c, 0x71) # TCA with address 0x71 20 # Create each BME280 using the TCA9548A channel instead of the I2C object 21 # Be sure to use the TCA instance each BME280 is attached to 22 bme1 = adafruit_bme280.Adafruit_BME280_I2C(tca1[0]) # TCA 1 Channel 0 23 bme2 = adafruit_bme280.Adafruit_BME280_I2C(tca1[1]) # TCA 1 Channel 1 24 bme3 = adafruit_bme280.Adafruit_BME280_I2C(tca2[0]) # TCA 2 Channel 0 25 #-------------------------------------------------------------------- 26 27 print("Multiple BME280 / Multiple TCA9548A Example") 28 29 while True: 30 # Access each sensor via its instance 31 pressure1 = bme1.pressure 32 pressure2 = bme2.pressure 33 pressure3 = bme3.pressure 34 35 print("-"*20) 36 print("BME280 #1 Pressure =", pressure1) 37 print("BME280 #2 Pressure =", pressure2) 38 print("BME280 #3 Pressure =", pressure3) 39 40 time.sleep(1)