Simple test

Ensure your device works with this simple test.

examples/tca9548a_simpletest.py
 1# SPDX-FileCopyrightText: 2021 Carter Nelson for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4# This example shows using TCA9548A to perform a simple scan for connected devices
 5import board
 6import adafruit_tca9548a
 7
 8# Create I2C bus as normal
 9i2c = board.I2C()  # uses board.SCL and board.SDA
10# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
11
12# Create the TCA9548A object and give it the I2C bus
13tca = adafruit_tca9548a.TCA9548A(i2c)
14
15for channel in range(8):
16    if tca[channel].try_lock():
17        print("Channel {}:".format(channel), end="")
18        addresses = tca[channel].scan()
19        print([hex(address) for address in addresses if address != 0x70])
20        tca[channel].unlock()

Multisensor test

Shows how to use the I2C Multiplexer with two sensors

examples/tca9548a_multisensor.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4# This example shows using two TSL2491 light sensors attached to TCA9548A channels 0 and 1.
 5# Use with other I2C sensors would be similar.
 6import time
 7import board
 8import adafruit_tsl2591
 9import adafruit_tca9548a
10
11# Create I2C bus as normal
12i2c = board.I2C()  # uses board.SCL and board.SDA
13# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
14
15# Create the TCA9548A object and give it the I2C bus
16tca = adafruit_tca9548a.TCA9548A(i2c)
17
18# For each sensor, create it using the TCA9548A channel instead of the I2C object
19tsl1 = adafruit_tsl2591.TSL2591(tca[0])
20tsl2 = adafruit_tsl2591.TSL2591(tca[1])
21
22# After initial setup, can just use sensors as normal.
23while True:
24    print(tsl1.lux, tsl2.lux)
25    time.sleep(0.1)