Electronic – ESP8266 I2C Multiplexer

esp8266i2cmultiplexer

EDIT: I ran an i2c bus scanning program and it detected a device at 0x70 (the mux). I connected the device I am trying to interface with directly to the i2c bus and ran this code and it worked exactly as expected. But still when I run this code with the device attached to one of the mux channels, it does not work. I'm stumped!


I am trying to control an I²C device via a multiplexer on an ESP8266. Below is the circuit I'm using and the code. This exact code works if I change the device to be connected directly to SDA and SCL (bypassing the multiplexer). Unfortunately, if connected via the multiplexer, the code outputs "No TCS34725 found." I have tried this on two distinct boards with the same results on both.

Multiplexer datasheet

PCB footprint

Reset (N$5) is pulled up to 3.3v via a 10k resistor.

specsheet symbol

#include <Wire.h>

#include <Adafruit_TCS34725.h>

#define TCAADDR 0x70

uint16_t clear, red, green, blue;

Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_2_4MS, TCS34725_GAIN_1X);

void setup() {

  Wire.begin();
  Serial.begin(115200);
  delay(10);
  Serial.println("\r\n");

   tcaselect(6);
  if (tcs.begin()) {
    Serial.println("Found sensor");
  } else {
    Serial.println("No TCS34725 found ... check your connections");
    while (1); // halt!
  }
}

void tcaselect(uint8_t i) {
  if (i > 7) return;

  Wire.beginTransmission(TCAADDR);
  Wire.write(1 << i);
  Wire.endTransmission();  
}

Any ideas on why this isn't working?

Best Answer

The first thing to check is that !RESET pin of mux properly pulled up by resistor and not held low by master MCU. And I mean really check not just assume that it is OK because it is supposed to be so. The mux might still ACK in reset when you scanning the bus but it will not select output channel on command.

If that is not the case, here is a simple procedure to diagnose the problem. You'd need another I2C device "B", for example VL53L0X that you've mentioned. You've already did some of the steps below, so you can skip those. Also make sure devices with selectable IDs always wired identically in the tests.

  1. Try sending some random channel selections to Mux and then reading control register. If you are not getting back the values that you send --> something wrong with Mux.
  2. Connect A (TCS34725) and B directly to main I2C bus and run scanner. You should see 3 devices.
  3. Verify A and B working properly by sending some commands and reading responses. If A doesn't work --> something wrong with the library.
  4. Connect A and B to Mux channel and scan the bus after selecting this channel. You should see 3 devices. Also if you can bypass the Mux and scan the channel itself you should see 2 devices.
  5. If you do not see all 3 try sending FF to Mux (select all channels). If you can see them now --> the channel wiring is messed up on PCB
  6. Try communicating with A and B after selecting correct channel. If B works and A doesn't --> there is some kind of incompatibility between TCS34725 and Mux.
  7. Try adding delay between channel selection command and following communication with devices. You shouldn't need it but doesn't hurt to check.
  8. If neither A nor B work in above tests when connected to Mux --> something wrong with the Mux.

You can diagnose further by comparing voltages and pull-ups on main bus and output Mux channels. Also go through the datasheets and re-check supported speeds and re-calculate required pull-up resistor values for Mux channels (they depend on speed and bus capacitance).