/ examples / tca9548a_simpletest.py
tca9548a_simpletest.py
 1  # This example shows using two TSL2491 light sensors attached to TCA9548A channels 0 and 1.
 2  # Use with other I2C sensors would be similar.
 3  import time
 4  import board
 5  import busio
 6  import adafruit_tsl2591
 7  import adafruit_tca9548a
 8  
 9  # Create I2C bus as normal
10  i2c = busio.I2C(board.SCL, board.SDA)
11  
12  # Create the TCA9548A object and give it the I2C bus
13  tca = adafruit_tca9548a.TCA9548A(i2c)
14  
15  # For each sensor, create it using the TCA9548A channel instead of the I2C object
16  tsl1 = adafruit_tsl2591.TSL2591(tca[0])
17  tsl2 = adafruit_tsl2591.TSL2591(tca[1])
18  
19  # After initial setup, can just use sensors as normal.
20  while True:
21      print(tsl1.lux, tsl2.lux)
22      time.sleep(0.1)