Qwiic MUX Hookup Guide
Python Package Overview
Note: This example assumes you are using the latest version of Python (2 or 3). If this is your first time using Python or I2C hardware on a Raspberry Pi, please checkout our tutorial on Python Programming with the Raspberry Pi and the Raspberry Pi SPI and I2C Tutorial.
*On the Raspberry Pi, Python 2 and 3 are included with the Raspbian OS (with desktop and recommended software) image.
Support Tip: Don't forget to double check that the hardware I2C connection is enabled on your Raspberry Pi or other single board computer.
We've written a Python package to easily get setup and utilize the Qwiic Mux. However, before we jump into operating the multiplexer, let's take a closer look at the available functions in the Python package. You can install the sparkfun-qwiic-tca9548a
Python package hosted by PyPi.
Installation
To install the Python package for this product, it is recommended that users install the SparkFun Qwiic Python package, which installs all the available Python packages for our Qwiic products and includes the required I2C driver package. On systems that support PyPi installation via pip3
(use pip
for Python 2) is simple, using the following commands:
For all users (note: the user must have sudo privileges):
language:bash
sudo pip3 install sparkfun-qwiic
For the current user:
language:bash
pip3 install sparkfun-qwiic
Note: Users can, alternatively, manually build or individually install the python package (see instructions below). The required I2C driver package will still need to be installed as well.
If you prefer to manually download and build the libraries from the GitHub repository, you can grab them here (*Please be aware of any package dependencies. You can also check out the repository documentation page, hosted on ReadtheDocs.):
PyPi Installation
This repository is hosted on PyPi as the sparkfun-qwiic-tca9548a package
. On systems that support PyPi installation via pip3
(use pip
for Python 2) is simple, using the following commands:
For all users (note: the user must have sudo privileges):
sudo pip3 install sparkfun-qwiic-tca9548a
For the current user:
pip3 install sparkfun-qwiic-tca9548a
Local Installation
To install, make sure the setuptools
package is installed on the system.
Direct installation at the command line (use python
for Python 2):
python3 setup.py install
To build a package for use with pip3
:
python3 setup.py sdist
A package file is built and placed in a subdirectory called dist. This package file can be installed using pip3
.
cd dist
pip3 install sparkfun_qwiic_tca9548a-<version>.tar.gz
Python Package Operation
Below is a description of the basic functionality of the Python package. This includes the package organization, built-in methods, and their inputs and/or outputs. For more details on how the Python package works, check out the source code and the datasheet.
Dependencies
This Python package has a very few dependencies in the code, listed below:
language:python
import time # Time access and conversion package
import qwiic_i2c # I2C bus driver package
Default Variables
The default variables, in the code, for this Python package are listed below:
language:python
#The name of this device
_DEFAULT_NAME = "Qwiic Mux"
_AVAILABLE_I2C_ADDRESS = [*range(0x70,0x77 + 1)]
Class
QwiicTCA9548A()
or QwiicTCA9548A(i2caddr)
This Python package operates as a class object, allowing new instances of that type to be made. An __init__()
constructor is used that creates a connection to an I2C device over the I2C bus using the default or specified I2C address.
The Constructor
A constructor is a special kind of method used to initialize (assign values to) the data members needed by the object when it is created.
__init__(self, address = None, debug = None, i2c_driver = None)
The value of the device address. If not defined, the Python package will use the default I2C address (0x29) stored under _AVAILABLE_I2C_ADDRESS
variable. (The other available addresses are configured with the jumpers on the board.)
True: Connected to I2C device on the default (or specified) address.
False: No device found or connected.
Loads the specified I2C driver; by default the Qwiic I2C driver is used: qwiic_i2c.getI2CDriver()
. Users should use the default I2C driver and leave this field blank.
Functions
A function that is an attribute of the class, which defines a method for instances of that class. In simple terms, they are objects for the operations (or methods) of the class.
.is_connected()
Determine if the device is conntected to the system.
True: Connected to I2C device on the default (or specified) address.
False: No device found or connected.
.disable_all()
This method disables the connection of all channels on the Qwiic Mux.
.disable_channels(disable)
This method disables the connection of specific channels on the Qwiic Mux.
Channel(s) to disable on the Qwiic Mux.
Range: 0 to 7 (*The method will automatically convert an individual integer into a list.)
.enable_all()
This method enables the connection of specific channels on the Qwiic Mux.
.enable_channels(enable)
This method enables the connection of specific channels on the Qwiic Mux.
Channel(s) to enable on the Qwiic Mux.
Range: 0 to 7 (*The method will automatically convert an individual integer into a list.)
.list_channels()
This method lists all the available channels and their current configuration (enabled or disabled) on the Qwiic Mux.
Upgrading the Package
In the future, changes to the Python package might be made. Updating the installed packages has to be done individually for each package (i.e. sub-modules and dependencies won't update automatically and must be updated manually). For the sparkfun-qwiic-tca9548a
Python package, use the following command (use pip
for Python 2):
For all users (note: the user must have sudo privileges):
language:bash
sudo pip3 install --upgrade sparkfun-qwiic-tca9548a
For the current user:
language:bash
pip3 install --upgrade sparkfun-qwiic-tca9548a