Qwiic MUX Hookup Guide

Pages
Favorited Favorite 0

Introduction

PCA9548A and TCA9548A? The SparkX version of the Qwiic Mux breakout used the PCA9548A. The SparkFun red version uses the TCA9548A. Overall, both should be functionally the same with a few minor differences.

The Qwiic Mux - TCA9548A enables communication with multiple I2C devices that have the same address. The IC is simple to interface with and also has 8 configurable addresses of its own, this allows you to put 64 I2C buses on a single bus!

SparkFun Qwiic Mux Breakout - 8 Channel (TCA9548A)

SparkFun Qwiic Mux Breakout - 8 Channel (TCA9548A)

BOB-14685
$11.95

In this tutorial we'll go over how to talk to sensors on different channels of your MUX. The application of this is pretty straightforward so things won't get too fancy.

Required Materials

You'll need a few additional items to get started with the Qwiic Mux. The RedBoard Qwiic is for the Arduino examples and the Qwiic pHAT is for the Raspberry Pi example (see note below). You may already have a few of these items, so feel free to modify your cart based on your needs. Additionally, there are also options that are available as well (click button below to toggle options).

SparkFun RedBoard Qwiic

SparkFun RedBoard Qwiic

DEV-15123
$19.95
5
SparkFun Qwiic Cable Kit

SparkFun Qwiic Cable Kit

KIT-15081
$7.95
1
SparkFun Qwiic pHAT for Raspberry Pi

SparkFun Qwiic pHAT for Raspberry Pi

DEV-15351
$5.95
Qwiic compatible microcontrollers:

SparkFun Thing Plus - ESP32 WROOM

WRL-14689
7
SparkFun RedBoard Qwiic

SparkFun RedBoard Qwiic

DEV-15123
$19.95
5
SparkFun RedBoard Turbo - SAMD21 Development Board

SparkFun RedBoard Turbo - SAMD21 Development Board

DEV-14812
$24.95
3
SparkFun Thing Plus - SAMD51

SparkFun Thing Plus - SAMD51

DEV-14713
$19.95
1
In addition we also offer, Qwiic compatible stackable shields for microcontrollers and pHATs for single board computers (like the Raspberry Pi boards) that don't include a Qwiic connector.
SparkFun Qwiic Shield for Arduino

SparkFun Qwiic Shield for Arduino

DEV-14352
$6.95
SparkFun Qwiic Adapter

SparkFun Qwiic Adapter

DEV-14495
$1.50
SparkFun Qwiic Shield for Photon

SparkFun Qwiic Shield for Photon

DEV-14477
$5.95
SparkFun Qwiic SHIM for Raspberry Pi

SparkFun Qwiic SHIM for Raspberry Pi

DEV-15794
$0.95
SparkFun Qwiic HAT for Raspberry Pi

SparkFun Qwiic HAT for Raspberry Pi

DEV-14459
$5.95
1
SparkFun Qwiic pHAT for Raspberry Pi

SparkFun Qwiic pHAT for Raspberry Pi

DEV-15351
$5.95
SparkFun Servo pHAT for Raspberry Pi

SparkFun Servo pHAT for Raspberry Pi

DEV-15316
$10.95
1
You will also need a Qwiic cable to connect to your Qwiic Mux, choose a length that suits your needs.
Qwiic Cable - 100mm

Qwiic Cable - 100mm

PRT-14427
$1.50
Qwiic Cable - 200mm

Qwiic Cable - 200mm

PRT-14428
$1.50
Qwiic Cable - 50mm

Qwiic Cable - 50mm

PRT-14426
$0.95
Qwiic Cable - 500mm

Qwiic Cable - 500mm

PRT-14429
$1.95

Raspberry Pi Example: If you don't already have them, you will need a Raspberry Pi and standard peripherals. An example setup is listed below. (The Qwiic Mux and Python library have not been tested on the newly released Raspberry Pi 4 because we don't carry it in out catalog yet.)

Tools

Depending on your setup, you may need a soldering iron, solder, and general soldering accessories.

Solder Lead Free - 100-gram Spool

Solder Lead Free - 100-gram Spool

TOL-09325
$7.95
7
Weller WLC100 Soldering Station

Weller WLC100 Soldering Station

TOL-14228
$44.95
1

Suggested Reading

If you're unfamiliar with jumper pads, I2C, Qwiic, or Python be sure to checkout some of these foundational tutorials.

Serial Communication

Asynchronous serial communication concepts: packets, signal levels, baud rates, UARTs and more!

Logic Levels

Learn the difference between 3.3V and 5V devices and logic levels.

I2C

An introduction to I2C, one of the main embedded communications protocols in use today.

Serial Terminal Basics

This tutorial will show you how to communicate with your serial devices using a variety of terminal emulator applications.

Raspberry Pi SPI and I2C Tutorial

Learn how to use serial I2C and SPI buses on your Raspberry Pi using the wiringPi I/O library for C/C++ and spidev/smbus for Python.

Raspberry Pi 3 Starter Kit Hookup Guide

Guide for getting going with the Raspberry Pi 3 Model B and Raspberry Pi 3 Model B+ starter kit.

Python Programming Tutorial: Getting Started with the Raspberry Pi

This guide will show you how to write programs on your Raspberry Pi using Python to control hardware.

Qwiic pHAT for Raspberry Pi Hookup Guide

Get started interfacing your Qwiic enabled boards with your Raspberry Pi. The Qwiic pHAT connects the I2C bus (GND, 3.3V, SDA, and SCL) on your Raspberry Pi to an array of Qwiic connectors.

How to Work with Jumper Pads and PCB Traces

Handling PCB jumper pads and traces is an essential skill. Learn how to cut a PCB trace, add a solder jumper between pads to reroute connections, and repair a trace with the green wire method if a trace is damaged.

Qwiic Shield for Arduino & Photon Hookup Guide

Get started with our Qwiic ecosystem with the Qwiic shield for Arduino or Photon.

RedBoard Qwiic Hookup Guide

This tutorial covers the basic functionality of the RedBoard Qwiic. This tutorial also covers how to get started blinking an LED and using the Qwiic system.

Qwiic Connect System

The Qwiic Mux is intended for the Qwiic connect system. We recommend familiarizing yourself with the Logic Levels and I2C tutorials before using it. Click on the banner above to learn more about our Qwiic products.

Hardware Overview

What is the difference between the PCA9548A and TCA9548A? Very little. PCA is made by NXP, TCA is made by TI. PCA can operate from 2.3 to 5.5V, TCA can operate from 1.65 to 5.5V. Everything else is identical.

Let's look over a few characteristics of the TCA9548A so we know a bit more about how it behaves.

CharacteristicRange
Operating Voltage1.65V - 5.5V
Operating Temperature-40 - 85° C
I2C Address0x70 (default) up to 0x77 (see below table)

The Qwiic input for the Mux is located at the top-center of the board, labeled Main, highlighted in the image below. The outputs are then located on the left and right sides of the board and are numbered accordingly.

Main Qwiic Port

The onboard reset pin, highlighted below, is an active low input. Pulling reset low for at least 6 ns will restart the multiplexer.

Reset Pin

The Qwiic Mux also allows you to change the last 3 bits of the address byte, allowing for 8 jumper selectable addresses if you happen to need to put more than one Mux on the same I2C port. The address can be changed by adding solder to any of the three ADR jumpers, shown in the image below.

Address Jumpers

The below table shows which jumpers must be soldered together to change to the corresponding address.

I2C AddressADR2ADR1ADR0
0x70OpenOpenOpen
0x71OpenOpenClosed
0x72OpenClosedOpen
0x73OpenClosedClosed
0x74ClosedOpenOpen
0x75ClosedOpenClosed
0x76ClosedClosedOpen
0x77ClosedClosedClosed

If you want to remove the pullup resistors from the I2C bus, simply remove the solder from the jumper highlighted in the below image.

Pullup Jumper

Hardware Assembly

Support Tip: Make sure that you are connecting the Main Qwiic connector to the Arduino board/shield or Raspberry HAT.

Arduino Example

Just plug one end of the Qwiic cable into the Main connector on the Qwiic multiplexer breakout and the other end into Qwiic connector on your Qwiic enabled microcontroller. If it seems like it's too easy to use, but that's why we made it that way! Otherwise, if you chose to use a Qwiic shield/adapter, now would be the time to head on over to that tutorial to assemble the shield.

With the shield assembled, SparkFun's new Qwiic environment means that connecting the mux could not be easier. Just plug one end of the Qwiic cable into the Qwiic multiplexer breakout (Main connector) and the other into the Qwiic Shield; then, you'll be ready to upload a sketch and figure out just how all those address sharing sensors are behaving.

Mux Connected to Shield
SparkFun RedBoard with the Qwiic shield connected the Qwiic Mux with a Qwiic cable.
Additionally, a few peripheral Qwiic Boards are attached to verify Qwiic Mux functionality.

Raspberry Pi Examples

Note: This board and the Python library have not been tested on the newly released Raspberry Pi 4 because we don't carry it in out catalog yet.

With the Qwiic connector system, assembling the hardware is simple. In addition to the Qwiic Mux, you will need: a Qwiic cables, a SparkFun Qwiic pHAT for Raspberry Pi, and a Raspberry Pi setup with the Raspbian OS, monitor, and standard peripherals. (*If you are unfamiliar with the Qwiic pHAT, you can find the Hookup Guide here.)

Note: The peripheral Qwiic boards attached to the Qwiic Mux are not necessary for this hookup guide, but they are useful for customers looking to verify the functionality of the Qwiic Mux. Use channels 0, 4, and 7 for the examples below.

Hardware assembly with Raspberry Pi 3B with Qwiic pHAT
Raspberry Pi 3B connected the Qwiic Mux with a Qwiic pHAT and Qwiic cable (and a few peripheral Qwiic Boards).

Alternatively, you can also use another Qwiic adapter like the Pi Servo pHat instead.

Hardware assembly with Raspberry Pi 3B with Pi Servo pHat
Raspberry Pi 3 connected the Qwiic Mux with the Pi Servo pHat and Qwiic cable (and a few peripheral Qwiic Boards).

Note: This tutorial assumes you are familiar with using a Raspberry Pi and you have the latest (full... with recommended software) version of Raspbian OS your Raspberry Pi. You can download the latest version of the Raspbian OS from the Raspberry Pi Foundation website. As of Feb. 13th 2019, we recommend the Raspbian Stretch with desktop and recommended software option.

If this is your first time using a Raspberry Pi, please head over to the Raspberry Pi Foundation website to use their quickstart guides. We have listed a few of them here:

  1. Setting up your Raspberry Pi
  2. Using your Raspberry Pi
  3. Documentation:
  4. Setup Documentation
    Installation Documentation
    Raspbian Documentation
    SD card Documentation

Arduino Example

Note: This tutorial assumes you are familiar with Arduino products and you are using the latest stable version of the Arduino IDE on your desktop. If this is your first time using the Arduino IDE, please review our tutorial on installing the Arduino IDE.

SparkFun has written some example code to enable and disable ports on the Qwiic Mux. Go ahead and download this example code here.

Additionally, you will need to install the MMA8452Q Arduino library if you are using two MMA8452Q accelerometers. First, you’ll need the Sparkfun MMA8452Q Arduino library. You can obtain these libraries through the Arduino Library Manager. Search for Sparkfun MMA8452Q Accelerometer by Jim@SparkFun Electronics to install the latest version. If you prefer downloading the libraries from the GitHub repository and manually installing it, you can grab them here:

Arduino Example Example1-BasicReadings.ino

Opening Example1-BasicReadings will open two tabs in the Arduino IDE, the first example, and also Mux_Control. Let's take a look under the hood of Mux_Control to get an idea of what's going on. There are two functions here, boolean enableMuxPort(byte portNumber) and boolean disableMuxPort(byte portNumber) which is pretty much all we need to specify which channels we'd like to talk to on the Mux. If we have a sensor on channel 0, we simply call enableMuxPort(0) to open that channel on the multiplexer. Then we'll take whatever reads and perform whatever actions we'd like to the sensor on that channel. Once finished, we have to call disableMuxPort(0) to close communication on that channel so we don't accidentally perform actions on the sensor on that channel. The below example code shows how to read from two MMA8452Q accelerometers.

language:c
#include <Wire.h>
#include <SFE_MMA8452Q.h> //From: https://github.com/sparkfun/SparkFun_MMA8452Q_Arduino_Library

MMA8452Q accel;

#define NUMBER_OF_SENSORS 2

void setup()
{
  Serial.begin(9600);
  Serial.println("Qwiic Mux Shield Read Example");

  Wire.begin();

  //Initialize all the sensors
  for (byte x = 0 ; x < NUMBER_OF_SENSORS ; x++)
  {
    enableMuxPort(x); //Tell mux to connect to port X
    accel.init(); //Init the sensor connected to this port
    disableMuxPort(x);
  }

  Serial.println("Mux Shield online");
}

void loop()
{
  for (byte x = 0 ; x < NUMBER_OF_SENSORS ; x++)
  {
    enableMuxPort(x); //Tell mux to connect to this port, and this port only

    if (accel.available())
    {
      accel.read();

      Serial.print("Accel ");
      Serial.print(x);
      Serial.print(": ");
      Serial.print(accel.cx, 2);
      Serial.print(" ");
      Serial.print(accel.cy, 2);
      Serial.print(" ");
      Serial.print(accel.cz, 2);
      Serial.print(" ");

      Serial.println(); // Print new line every time.
    }

    disableMuxPort(x); //Tell mux to disconnect from this port
  }

  delay(1); //Wait for next reading
}

With the example provided, you should be able to read two I2C sensors with the same address on the same bus! Try opening up the Arduino Serial Monitor set to 9600 baud in order to read the sensor values.

Python Package Overview

Note: This board and the Python package have not been tested on the newly released Raspberry Pi 4 because we don't carry it in out catalog yet.

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)

Input: value

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.)

Output: Boolean

True: Connected to I2C device on the default (or specified) address.
False: No device found or connected.

Input: i2c_driver

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.

Output: Boolean

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.

Intput: Integer or List

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.

Intput: Integer or List

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

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()

Troubleshooting Tips

Here are a few tips for troubleshooting this device.

No Available Devices

Double check your connections. On a Raspberry Pi, you may get this is indicated with an OSError: [Errno 121] Remote I/O error readout.

On a Raspberry Pi, also make sure that the I2C hardware is enabled. This is usually indicated with an Error: Failed to connect to I2C bus 1. readout.

Checking Your I2C Connection

A simple method to check if your Raspberry Pi can communicate over I2C with the Qwiic Mux, is to ping the I2C bus. On the latest releases of Raspbian Stretch, the i2ctools package should come pre-installed. If it isn't run the following command in the terminal:

sudo apt-get install i2ctools

Once the i2ctools package is installed, you can ping the I2C bus with the following command in the terminal:

i2cdetect -y 1

You should see a table printed out in the terminal. If the Qwiic Mux is connected/working properly you should see the address space for 0x70 marked with 70.

Resources and Going Further

Now that you've successfully got your Qwiic Mux listening to all of those concurrent addresses, it's time to incorporate it into your own project!

For more information, check out the resources below:

Need even more inspiration for your next project? Check out some of these related tutorials:

AS726X NIR/VIS Spectral Sensor Hookup Guide

It's now easier than ever to measure and characterize how different materials absorb and reflect different wavelengths of light. The AS726X spectral sensors allow you to detect wavelengths in the visible range (VIS) and near infrared range (NIR)!

SparkFun SAMD21 Pro RF Hookup Guide

Using the super blazing, nay blinding, fast SAMD21 whipping clock cycles at 48MHz and the RFM96 module to connect to the Things Network (and other Radio woodles).

Build a Qwiic Jukebox that is Toddler Approved!

Follow this tutorial to build your own custom jukebox. Note, this is designed simple and tough for use primarily with toddlers. It's also a great introduction to SparkFun's Qwiic products!

Capacitive Touch Slider (CAP1203) Hookup Guide

An easy and Qwiic way to add capacitive touch to any of your projects using the CAP1203! In this guide, we go over how to connect and set up your Capacitive Touch Slider so you can start playing with it right away.