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  bme4 = adafruit_bme280.Adafruit_BME280_I2C(tca[3])   # TCA Channel 3
24  #--------------------------------------------------------------------
25  
26  print("Four BME280 Example")
27  
28  while True:
29      # Access each sensor via its instance
30      pressure1 = bme1.pressure
31      pressure2 = bme2.pressure
32      pressure3 = bme3.pressure
33      pressure4 = bme4.pressure
34  
35      print("-"*20)
36      print("BME280 #1 Pressure =", pressure1)
37      print("BME280 #2 Pressure =", pressure2)
38      print("BME280 #3 Pressure =", pressure3)
39      print("BME280 #4 Pressure =", pressure4)
40  
41      time.sleep(1)