Qwiic TCA9548A MUX how to use the multiple channels...

I recently purchased the sparkfun qwiic I2C MUX with 8 channels.

The python github is seen here:

https://github.com/sparkfun/Qwiic_TCA9548A_Py

I hooked up 8 MLX90393 magnetic sensors to channels 0-7 of the MUX.

However I have failed to find a way to read the data off all of the channels for each of the sensors. I can enable all of them, but only 1 sensor will produce data at any given time.

I also get errors about the ‘address’ where it can’t seem to find it.

I’m not sure how to use the multiple channels found within the MUX. Any help is greatly appreciated.

Please let me know if you have any questions.

The code I used is:

import qwiic_tca9548a
import sys
import time
import busio
import board
import adafruit_mlx90393

test = qwiic_tca9548a.QwiicTCA9548A()
test.enable_all()
test.list_channels()
test.available_addresses()
# Above prints available_addresses as: [112, 113, 114, 115, 116, 117]

I2C_BUS = busio.I2C(board.SCL, board.SDA)
SENSOR0 = adafruit_mlx90393.MLX90393(I2C_BUS, address=112,  gain=adafruit_mlx90393.GAIN_1X)
SENSOR1 = adafruit_mlx90393.MLX90393(I2C_BUS, address=113,  gain=adafruit_mlx90393.GAIN_1X)
SENSOR2 = adafruit_mlx90393.MLX90393(I2C_BUS, address=114,  gain=adafruit_mlx90393.GAIN_1X)
SENSOR3 = adafruit_mlx90393.MLX90393(I2C_BUS, address=115,  gain=adafruit_mlx90393.GAIN_1X)
SENSOR4 = adafruit_mlx90393.MLX90393(I2C_BUS, address=116,  gain=adafruit_mlx90393.GAIN_1X)
SENSOR5 = adafruit_mlx90393.MLX90393(I2C_BUS, address=117,  gain=adafruit_mlx90393.GAIN_1X)
SENSOR6 = adafruit_mlx90393.MLX90393(I2C_BUS, address=118,  gain=adafruit_mlx90393.GAIN_1X)
SENSOR7 = adafruit_mlx90393.MLX90393(I2C_BUS, address=119,  gain=adafruit_mlx90393.GAIN_1X)


# Testing sensor 0
print('-------------- Sensor 0 --------------')
print(SENSOR0.i2c_device.device_address)
MX0, MY0, MZ0 = SENSOR0.magnetic
print("X: {} uT".format(MX0))
print("Y: {} uT".format(MY0))
print("Z: {} uT".format(MZ0))

# Testing sensor 1
print('-------------- Sensor 1 --------------')
print(SENSOR1.i2c_device.device_address)
MX1, MY1, MZ1 = SENSOR1.magnetic
print("X: {} uT".format(MX1))
print("Y: {} uT".format(MY1))
print("Z: {} uT".format(MZ1))
    
# Testing sensor 2
print('-------------- Sensor 2 --------------')
print(SENSOR2.i2c_device.device_address)
MX2, MY2, MZ2 = SENSOR2.magnetic
print("X: {} uT".format(MX2))
print("Y: {} uT".format(MY2))
print("Z: {} uT".format(MZ2))

# Testing sensor 3
print('-------------- Sensor 3 --------------')
print(SENSOR3.i2c_device.device_address)
MX3, MY3, MZ3 = SENSOR3.magnetic
print("X: {} uT".format(MX3))
print("Y: {} uT".format(MY3))
print("Z: {} uT".format(MZ3))

# Testing sensor 4
print('-------------- Sensor 4 --------------')
print(SENSOR4.i2c_device.device_address)
MX4, MY4, MZ4 = SENSOR4.magnetic
print("X: {} uT".format(MX4))
print("Y: {} uT".format(MY4))
print("Z: {} uT".format(MZ4))
    
# Testing sensor 5
print('-------------- Sensor 5 --------------')
print(SENSOR5.i2c_device.device_address)
MX5, MY5, MZ5 = SENSOR5.magnetic
print("X: {} uT".format(MX5))
print("Y: {} uT".format(MY5))
print("Z: {} uT".format(MZ5))

# Testing sensor 6
print('-------------- Sensor 6 --------------')
print(SENSOR6.i2c_device.device_address)
MX6, MY6, MZ6 = SENSOR6.magnetic
print("X: {} uT".format(MX6))
print("Y: {} uT".format(MY6))
print("Z: {} uT".format(MZ6))
    
# Testing sensor 7
print('-------------- Sensor 7 --------------')
print(SENSOR7.i2c_device.device_address)
MX7, MY7, MZ7 = SENSOR7.magnetic
print("X: {} uT".format(MX7))
print("Y: {} uT".format(MY7))
print("Z: {} uT".format(MZ7))

You will need to enable a channel, talk to the sensor on that channel then disable that channel before moving onto another channel.