TCA9548A I2C Multiplexer (Product #2717). For multiple MUX on one bus: Need Example
I need to sense the environment every 10 cm for 30 cm. I have four MUX’s each with several sensors. The multiple MUXs are on one I2C bus from Arduino. I can’t get data from the sensors.
This must be a common scenario. Is there an example somewhere? I’m using sensors AHT10, BH1750, BMP280, etc. but example can be any sensor.
The MUX address jumpers are set for different addresses: 0x70 through 0x73. The tutorial in Learn is for multiple sensors on 1 MUX, but not multiple MUXs w/multiple sensors each on one I2C.
Thanks.
TCA9548A I2C Multiplexer (Product #2717). For multiple MUX on one bus: Need Example
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- john kauffman
- Posts: 20
- Joined: Mon Sep 09, 2013 7:43 pm
- adafruit_support_carter
- Posts: 29168
- Joined: Tue Nov 29, 2016 2:45 pm
Re: TCA9548A I2C Multiplexer (Product #2717). For multiple MUX on one bus: Need Example
This guide doesn't cover multiple muxer, but is good for a general reference:
https://learn.adafruit.com/working-with ... s/overview
The mux changes in Arduino must be done manually. The typical helper function to do that is:
That only works for a single muxer with a fixed known address (TCAADDR). You could modify that allow passing in the muxer address as well:
and call it as needed:
However note that the unique address requirement for the entire I2C bus must still be maintained - even between muxers. Note that you can effectively "disable" a given muxer by sending all 0's for the channel selection (different that setting channel 0). So would need to alter the code more to provide a way to set that.
https://learn.adafruit.com/working-with ... s/overview
The mux changes in Arduino must be done manually. The typical helper function to do that is:
Code: Select all
// Helper function for changing TCA output channel
void tcaselect(uint8_t channel) {
if (channel > 7) return;
Wire.beginTransmission(TCAADDR);
Wire.write(1 << channel);
Wire.endTransmission();
}
Code: Select all
// Helper function for changing TCA output channel
void tcaselect(uint8_t tca_addr, uint8_t channel) {
if (channel > 7) return;
Wire.beginTransmission(tca_addr);
Wire.write(1 << channel);
Wire.endTransmission();
}
Code: Select all
tcaselect(0x70, 0); # set muxer at address 0x70 to channel 0
- john kauffman
- Posts: 20
- Joined: Mon Sep 09, 2013 7:43 pm
Re: TCA9548A I2C Multiplexer (Product #2717). For multiple MUX on one bus: Need Example
Carter:
Your tutorial at Learn is great, thanks for that. Worked well for the single-MUX scenario.
I have to travel tomorrow but on return will implement your suggestion of expanding the helper function.
- John
Your tutorial at Learn is great, thanks for that. Worked well for the single-MUX scenario.
I have to travel tomorrow but on return will implement your suggestion of expanding the helper function.
- John
Please be positive and constructive with your questions and comments.