Skip to content

Bugfix Channel Scan #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion adafruit_tca9548a.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ def writeto_then_readfrom(self, address, buffer_out, buffer_in, **kwargs):

def scan(self):
"""Perform an I2C Device Scan"""
return self.tca.i2c.scan()
self.try_lock()
try:
return self.tca.i2c.scan()
finally:
self.unlock()


class TCA9548A:
Expand Down
9 changes: 9 additions & 0 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,12 @@ Ensure your device works with this simple test.
.. literalinclude:: ../examples/tca9548a_simpletest.py
:caption: examples/tca9548a_simpletest.py
:linenos:

Channel Scan
-------------

Ensure your device scans each channel of TCA9547A with Channel Scan.

.. literalinclude:: ../examples/tca9548a_channelscan.py
:caption: examples/tca9548a_channelscan.py
:linenos:
20 changes: 20 additions & 0 deletions examples/tca9548a_channelscan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# SPDX-FileCopyrightText: 2021 codenio (Aananth K)
# SPDX-License-Identifier: MIT

# This example shows scanning of each TCA9548A channels.
import board
import busio
import adafruit_tca9548a

# Create I2C bus as normal
i2c = busio.I2C(board.SCL, board.SDA)

# Create the TCA9548A object and give it the I2C bus
tca = adafruit_tca9548a.TCA9548A(i2c)

# Scan the Main I2C Channel present in your board
print("Scan of Main I2C Channel:{}".format([hex(i) for i in i2c.scan()]))

# Scan Each TCA9548A channel
for i in range(8):
print("Scan of TCA[{}] Channel: {}".format(i, [hex(j) for j in tca[i].scan()]))