-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from adafruit/pca9546a_update
Adding a PCA9546A class and examples
- Loading branch information
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries | ||
# SPDX-License-Identifier: MIT | ||
|
||
# This example shows using two TSL2491 light sensors attached to PCA9546A channels 0 and 1. | ||
# Use with other I2C sensors would be similar. | ||
import time | ||
import board | ||
import adafruit_tsl2591 | ||
import adafruit_tca9548a | ||
|
||
# Create I2C bus as normal | ||
i2c = board.I2C() # uses board.SCL and board.SDA | ||
# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller | ||
|
||
# Create the PCA9546A object and give it the I2C bus | ||
mux = adafruit_tca9548a.PCA9546A(i2c) | ||
|
||
# For each sensor, create it using the PCA9546A channel instead of the I2C object | ||
tsl1 = adafruit_tsl2591.TSL2591(mux[0]) | ||
tsl2 = adafruit_tsl2591.TSL2591(mux[1]) | ||
|
||
# After initial setup, can just use sensors as normal. | ||
while True: | ||
print(tsl1.lux, tsl2.lux) | ||
time.sleep(0.1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# SPDX-FileCopyrightText: 2021 Carter Nelson for Adafruit Industries | ||
# SPDX-License-Identifier: MIT | ||
|
||
# This example shows using TCA9548A to perform a simple scan for connected devices | ||
import board | ||
import adafruit_tca9548a | ||
|
||
# Create I2C bus as normal | ||
i2c = board.I2C() # uses board.SCL and board.SDA | ||
# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller | ||
|
||
# Create the PCA9546A object and give it the I2C bus | ||
mux = adafruit_tca9548a.PCA9546A(i2c) | ||
|
||
for channel in range(4): | ||
if mux[channel].try_lock(): | ||
print("Channel {}:".format(channel), end="") | ||
addresses = mux[channel].scan() | ||
print([hex(address) for address in addresses if address != 0x70]) | ||
mux[channel].unlock() |