Qwiic MUX Hookup Guide

Pages
Contributors: santaimpersonator, Englandsaurus
Favorited Favorite 0

Python Examples

The following examples are available in the GitHub repository. To run the examples, simple download or copy the code into a file. Then, open/save the example file (if needed) and execute the code in your favorite Python IDE.

For example, with the default Python IDLE click Run > Run Module or use the F5 key. To terminate the example use the Ctrl + C key combination.

Support Tip: To check for changes in the channels of the Qwiic Mux, users can attach various Qwiic boards to the channels (as shown in the Hardware Assembly section). With the i2ctools package installed on Raspbian, users can verify whether the channels on the Qwiic Mux are enabled with the following command (in the Terminal):

i2cdetect -y 1

A table will be printed out in the terminal, listing the addresses of the available devices. By running this command before, between, and after the following examples, users can verify the changes in the enabled channels of the Qwiic Mux.

Example 1

Users should run the first example after power up or reset of the board. In this example, channels 0 and 4 are enabled, there is a pause, and then channel 7 is enabled.

Import Dependencies

The first part of the code, imports the required dependencies to operate.

language:python
import qwiic
import time

Initialize Constructor

This line instantiates an object for the device.

language:python
test = qwiic.QwiicTCA9548A()

Test Run

This section of the code, illustrates how to enable the I2C channels on the Qwiic Mux. First, it list all the channels on the Qwiic Mux and their configuration (enabled or disabled). (*On power up or reset all the channels will be disabled.) The second part of the code, enables channels 0 and 4 using the list method. Then then the code pauses for a second before enabling channel 7. Once that task its complete, the code returns the final configuration of the channels. Users should expect to see channels 0, 4, and 7 enabled.

language:python
# List Channel Configuration
test.list_channels()

# Enable Channels 0 and 4
test.enable_channels([0,4])

# Pause 1 sec
time.sleep (1)

# Enable Channel 7
test.enable_channels(7)

# List Channel Configuration
test.list_channels()

Example 2

Users should run the first example before running this example. This example disables channels 0 and 4.

Import Dependencies

The first part of the code, imports the required dependencies to operate.

language:python
import qwiic
import time

Initialize Constructor

This line instantiates an object for the device.

language:python
test = qwiic.QwiicTCA9548A()

Test Run

This section of the code, illustrates how to disable the I2C channels on the Qwiic Mux. First, it list all the channels on the Qwiic Mux and their configuration (enabled or disabled). (*From the previous example, channels 0, 4, and 7 should be enabled.) The second part of the code, disables channels 0 and 4 using the list method. Then then the code returns the final configuration of the channels. Users should expect to see only channel 7 enabled.

language:python
# List Channel Configuration
test.list_channels()

# Enable Channels 0 and 4
test.disable_channels([0,4])

# List Channel Configuration
test.list_channels()