|
1 | | -Qwiic_TCA9548A_Py |
2 | | -============== |
| 1 | + |
3 | 2 |
|
4 | | -<p align="center"> |
5 | | - <img src="https://cdn.sparkfun.com/assets/custom_pages/2/7/2/qwiic-logo-registered.jpg" width=200> |
6 | | - <img src="https://www.python.org/static/community_logos/python-logo-master-v3-TM.png" width=240> |
7 | | -</p> |
8 | | -<p align="center"> |
9 | | - <a href="https://pypi.org/project/sparkfun-qwiic-tca9548a/" alt="Package"> |
10 | | - <img src="https://img.shields.io/pypi/pyversions/sparkfun_qwiic_tca9548a.svg" /></a> |
11 | | - <a href="https://github.com/sparkfun/Qwiic_TCA9548A_Py/issues" alt="Issues"> |
12 | | - <img src="https://img.shields.io/github/issues/sparkfun/Qwiic_TCA9548A_Py.svg" /></a> |
13 | | - <a href="https://qwiic-TCA9548A-py.readthedocs.io/en/latest/?" alt="Documentation"> |
14 | | - <img src="https://readthedocs.org/projects/qwiic-tca9548a-py/badge/?version=latest&style=flat" /></a> |
15 | | - <a href="https://github.com/sparkfun/Qwiic_TCA9548A_Py/blob/master/LICENSE" alt="License"> |
16 | | - <img src="https://img.shields.io/badge/license-MIT-blue.svg" /></a> |
17 | | - <a href="https://twitter.com/intent/follow?screen_name=sparkfun"> |
18 | | - <img src="https://img.shields.io/twitter/follow/sparkfun.svg?style=social&logo=twitter" |
19 | | - alt="follow on Twitter"></a> |
20 | | - |
21 | | -</p> |
| 3 | +# SparkFun Qwiic TCA9548A - Python Package |
22 | 4 |
|
23 | | -<img src="https://cdn.sparkfun.com/assets/parts/1/5/6/8/9/16784-SparkFun_Qwiic_Mux_Breakout_V2_-_8_Channel__TCA9548A_-01.jpg" align="right" width=300 alt="SparkFun Qwiic Mux for the Raspberry Pi"> |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +[](https://docs.sparkfun.com/qwiic_tca9548a_py/classqwiic__tca9548a_1_1_qwiic_t_c_a9548_a.html) |
24 | 10 |
|
25 | | -Python module for the [SparkFun Qwiic Mux Breakout - 8 Channel (TCA9548A)](https://www.sparkfun.com/products/16784). |
| 11 | +The SparkFun Qwiic I2C Mux TCA9548A Module provides a simple and cost effective solution for adding I2C Mux capabilities to your project. Implementing a SparkFun Qwiic I2C interface, these sensors can be rapidly added to any project with boards that are part of the SparkFun Qwiic ecosystem. |
26 | 12 |
|
27 | | -This package should be used in conjunction with the overall [SparkFun qwiic Python Package](https://github.com/sparkfun/Qwiic_Py). New to qwiic? Take a look at the entire [SparkFun qwiic ecosystem](https://www.sparkfun.com/qwiic). |
| 13 | +This repository implements a Python package for the SparkFun Qwiic TCA9548A. This package works with Python, MicroPython and CircuitPython. |
28 | 14 |
|
29 | | -## Contents |
30 | | -* [Supported Platforms](#supported-platforms) |
31 | | -* [Dependencies](#dependencies) |
| 15 | +### Contents |
| 16 | + |
| 17 | +* [About](#about-the-package) |
| 18 | +* [Getting Started](#getting-started) |
32 | 19 | * [Installation](#installation) |
33 | | -* [Documentation](#documentation) |
34 | | -* [Example Use](#example-use) |
| 20 | +* [Supported Platforms](#supported-platforms) |
| 21 | +* [Documentation](https://docs.sparkfun.com/qwiic_tca9548a_py/classqwiic__tca9548a_1_1_qwiic_t_c_a9548_a.html) |
| 22 | +* [Examples](#examples) |
| 23 | + |
| 24 | +## About the Package |
| 25 | + |
| 26 | +This python package enables the user to access the features of the TCA9548A via a single Qwiic cable. This includes enabling channels, disabling channels, listing channels, controlling multiple I2C devices with the same address and more. The capabilities of the TCA9548A are each demonstrated in the included examples. |
| 27 | + |
| 28 | +New to qwiic? Take a look at the entire [SparkFun qwiic ecosystem](https://www.sparkfun.com/qwiic). |
35 | 29 |
|
36 | | -Supported Platforms |
37 | | --------------------- |
38 | | -The qwiic TCA9548A Python package current supports the following platforms: |
39 | | -* [Raspberry Pi](https://www.sparkfun.com/search/results?term=raspberry+pi) |
40 | | -<!-- Platforms to be tested |
41 | | -* [NVidia Jetson Nano](https://www.sparkfun.com/products/15297) |
42 | | -* [Google Coral Development Board](https://www.sparkfun.com/products/15318) |
43 | | ---> |
| 30 | +### Supported SparkFun Products |
44 | 31 |
|
45 | | -Dependencies |
46 | | ---------------- |
47 | | -This package depends on the qwiic I2C driver: [Qwiic_I2C_Py](https://github.com/sparkfun/Qwiic_I2C_Py) |
| 32 | +This Python package supports the following SparkFun qwiic products on Python, MicroPython and Circuit python. |
48 | 33 |
|
49 | | -Documentation |
50 | | -------------- |
51 | | -The SparkFun qwiic TCA9548A module documentation is hosted at [ReadTheDocs](https://qwiic-tca9548a-py.readthedocs.io/en/latest/?) |
| 34 | +* [SparkFun I2C Mux Sensor - TCA9548A](https://www.sparkfun.com/products/14685) |
52 | 35 |
|
53 | | -Installation |
54 | | -------------- |
| 36 | +### Supported Platforms |
55 | 37 |
|
56 | | -### PyPi Installation |
57 | | -This repository is hosted on PyPi as the [sparkfun-qwiic-tca9548a](https://pypi.org/project/sparkfun-qwiic-tca9548a/) package. On systems that support PyPi installation via pip, this library is installed using the following commands |
| 38 | +| Python | Platform | Boards | |
| 39 | +|--|--|--| |
| 40 | +| Python | Linux | [Raspberry Pi](https://www.sparkfun.com/raspberry-pi-5-8gb.html) , [NVIDIA Jetson Orin Nano](https://www.sparkfun.com/nvidia-jetson-orin-nano-developer-kit.html) via the [SparkFun Qwiic SHIM](https://www.sparkfun.com/sparkfun-qwiic-shim-for-raspberry-pi.html) | |
| 41 | +| MicroPython | Raspberry Pi - RP2, ESP32 | [SparkFun RP2040 Thing+](https://www.sparkfun.com/sparkfun-thing-plus-rp2040.html), [SparkFun RP2350 Thing+](https://www.sparkfun.com/sparkfun-thing-plus-rp2350.html), [SparkFun ESP32 Thing+](https://www.sparkfun.com/sparkfun-thing-plus-esp32-wroom-usb-c.html) |
| 42 | +|CircuitPython | Raspberry Pi - RP2, ESP32 | [SparkFun RP2040 Thing+](https://www.sparkfun.com/sparkfun-thing-plus-rp2040.html), [SparkFun RP2350 Thing+](https://www.sparkfun.com/sparkfun-thing-plus-rp2350.html), [SparkFun ESP32 Thing+](https://www.sparkfun.com/sparkfun-thing-plus-esp32-wroom-usb-c.html) |
58 | 43 |
|
59 | | -For all users (note: the user must have sudo privileges): |
| 44 | +> [!NOTE] |
| 45 | +> The listed supported platforms and boards are the primary platform targets tested. It is fully expected that this package will work across a wide variety of Python enabled systems. |
| 46 | +
|
| 47 | +## Installation |
| 48 | + |
| 49 | +The first step to using this package is installing it on your system. The install method depends on the python platform. The following sections outline installation on Python, MicroPython and CircuitPython. |
| 50 | + |
| 51 | +### Python |
| 52 | + |
| 53 | +#### PyPi Installation |
| 54 | + |
| 55 | +The package is primarily installed using the `pip3` command, downloading the package from the Python Index - "PyPi". |
| 56 | + |
| 57 | +Note - the below instructions outline installation on a Linux-based (Raspberry Pi) system. |
| 58 | + |
| 59 | +First, setup a virtual environment from a specific directory using venv: |
60 | 60 | ```sh |
61 | | -sudo pip install sparkfun-qwiic-tca9548a |
| 61 | +python3 -m venv path/to/venv |
62 | 62 | ``` |
63 | | -For the current user: |
| 63 | +You can pass any path as path/to/venv, just make sure you use the same one for all future steps. For more information on venv [click here](https://docs.python.org/3/library/venv.html). |
64 | 64 |
|
| 65 | +Next, install the qwiic package with: |
| 66 | +```sh |
| 67 | +path/to/venv/bin/pip3 install sparkfun-qwiic-tca9548a |
| 68 | +``` |
| 69 | +Now you should be able to run any example or custom python scripts that have `import qwiic_tca9548a` by running e.g.: |
65 | 70 | ```sh |
66 | | -pip install sparkfun-qwiic-tca9548a |
| 71 | +path/to/venv/bin/python3 example_script.py |
67 | 72 | ``` |
68 | 73 |
|
69 | | -### Local Installation |
70 | | -To install, make sure the setuptools package is installed on the system. |
| 74 | +### MicroPython Installation |
| 75 | +If not already installed, follow the [instructions here](https://docs.micropython.org/en/latest/reference/mpremote.html) to install mpremote on your computer. |
71 | 76 |
|
72 | | -Direct installation at the command line: |
| 77 | +Connect a device with MicroPython installed to your computer and then install the package directly to your device with mpremote mip. |
73 | 78 | ```sh |
74 | | -python setup.py install |
| 79 | +mpremote mip install github:sparkfun/qwiic_tca9548a_py |
75 | 80 | ``` |
76 | 81 |
|
77 | | -To build a package for use with pip: |
| 82 | +If you would also like to install the examples for this repository, issue the following mip command as well: |
78 | 83 | ```sh |
79 | | -python setup.py sdist |
80 | | - ``` |
81 | | -A package file is built and placed in a subdirectory called dist. This package file can be installed using pip. |
| 84 | +mpremote mip install github:sparkfun/qwiic_tca9548a_py@examples |
| 85 | +``` |
| 86 | + |
| 87 | +### CircuitPython Installation |
| 88 | +If not already installed, follow the [instructions here](https://docs.circuitpython.org/projects/circup/en/latest/#installation) to install CircUp on your computer. |
| 89 | + |
| 90 | +Ensure that you have the latest version of the SparkFun Qwiic CircuitPython bundle. |
| 91 | +```sh |
| 92 | +circup bundle-add sparkfun/Qwiic_Py |
| 93 | +``` |
| 94 | + |
| 95 | +Finally, connect a device with CircuitPython installed to your computer and then install the package directly to your device with circup. |
| 96 | +```sh |
| 97 | +circup install --py qwiic_tca9548a |
| 98 | +``` |
| 99 | + |
| 100 | +If you would like to install any of the examples from this repository, issue the corresponding circup command from below. (NOTE: The below syntax assumes you are using CircUp on Windows. Linux and Mac will have different path seperators. See the [CircUp "example" command documentation](https://learn.adafruit.com/keep-your-circuitpython-libraries-on-devices-up-to-date-with-circup/example-command) for more information) |
| 101 | + |
82 | 102 | ```sh |
83 | | -cd dist |
84 | | -pip install sparkfun_qwiic_tca9548a-<version>.tar.gz |
85 | | - |
| 103 | +circup example qwiic_tca9548a\qwiic_tca9548a_ex1 |
| 104 | +circup example qwiic_tca9548a\qwiic_tca9548a_ex2 |
| 105 | +circup example qwiic_tca9548a\simple_disable_channels |
| 106 | +circup example qwiic_tca9548a\simple_enable_channels |
86 | 107 | ``` |
| 108 | + |
87 | 109 | Example Use |
88 | 110 | --------------- |
89 | | -See the examples directory for more detailed use examples. |
| 111 | +Below is a quickstart program to print readings from the TCA9548A. |
| 112 | + |
| 113 | +See the examples directory for more detailed use examples and [examples/README.md](https://github.com/sparkfun/qwiic_tca9548a_py/blob/main/examples/README.md) for a summary of the available examples. |
90 | 114 |
|
91 | 115 | ```python |
| 116 | + |
| 117 | + |
92 | 118 | import qwiic_tca9548a |
| 119 | +import qwiic_i2c |
93 | 120 | import time |
94 | 121 | import sys |
95 | 122 |
|
96 | 123 | def runExample(): |
97 | 124 |
|
98 | | - print("\nSparkFun TCA9548A Example 1\n") |
99 | | - test = qwiic_tca9548a.QwiicTCA9548A() |
100 | | - |
101 | | - if test.is_connected() == False: |
102 | | - print("The Qwiic TCA9548A device isn't connected to the system. Please check your connection", \ |
103 | | - file=sys.stderr) |
104 | | - return |
105 | | - |
| 125 | + print("\nSparkFun TCA9548A 8-Channel Mux Example 1\n") |
| 126 | + |
| 127 | + myTca = qwiic_tca9548a.QwiicTCA9548A() |
| 128 | + |
| 129 | + if myTca.connected == False: |
| 130 | + print("The Qwiic TCA9548A 8-Channel Mux device isn't connected to the system. Please check your connection", \ |
| 131 | + file=sys.stderr) |
| 132 | + return |
| 133 | + |
| 134 | + i2c = qwiic_i2c.getI2CDriver() |
| 135 | + |
| 136 | + while True: |
| 137 | + print("Enabling channels 0 and 1") |
| 138 | + myTca.disable_all() |
| 139 | + myTca.enable_channels([0,1]) |
| 140 | + myTca.list_channels() |
| 141 | + |
| 142 | + print("Checking for i2c devices on ports 0 and 1") |
| 143 | + devices = i2c.scan() |
| 144 | + print("Devices found: ", devices) |
| 145 | + time.sleep(2) |
| 146 | + |
| 147 | + print("Enabling channels 2 and 3") |
| 148 | + myTca.disable_all() |
| 149 | + myTca.enable_channels([2,3]) |
| 150 | + myTca.list_channels() |
| 151 | + |
| 152 | + print("Checking for i2c devices on ports 2 and 3") |
| 153 | + devices = i2c.scan() |
| 154 | + print("Devices found: ", devices) |
| 155 | + time.sleep(2) |
| 156 | + |
| 157 | +if __name__ == '__main__': |
106 | 158 | try: |
107 | | - test.list_channels() |
108 | | - time.sleep(2) |
109 | | - |
110 | | - test.enable_channels([4,5]) |
111 | | - test.list_channels() |
112 | | - time.sleep(2) |
113 | | - |
114 | | - test.disable_channels(5) |
115 | | - test.list_channels() |
116 | | - time.sleep(2) |
| 159 | + runExample() |
| 160 | + except (KeyboardInterrupt, SystemExit) as exErr: |
| 161 | + print("\nEnding Example 1") |
| 162 | + sys.exit(0) |
117 | 163 |
|
118 | | - except Exception as e: |
119 | | - print(e) |
120 | 164 | ``` |
121 | 165 | <p align="center"> |
122 | 166 | <img src="https://cdn.sparkfun.com/assets/custom_pages/3/3/4/dark-logo-red-flame.png" alt="SparkFun - Start Something"> |
|
0 commit comments