Esp32-s2 thing plus not working with sparkfun mux board

Hi All,

I have been trying all day to get this working. I can See the 0x70 address of the mux with an I2C scanner code running on the esp32. I added print statements to the mux code and it prints 1 and 2 but not 3 so the conclusion is it hangs on “Wire.requestFrom”. It does this for enable and disable mux port calls. I can talk directly to my ToF sensors if I exclude the MUX so it is some combination of the ESP32 and the MUX. I have tried 100k and 400k i2c freq. I have read of a lot of problems but none seem like mine. I have tried a different mux and same behavior (both were new in packaging earlier today). Any feedback would be helpful. Maybe someone can just try and run my sketch to see if they can enable ports on the MUX?

#include "Adafruit_VL53L1X.h"

#define IRQ_PIN 2
#define XSHUT_PIN 3
#define MUX_ADDR 0x70 //7-bit unshifted default I2C Address

Adafruit_VL53L1X vl53 = Adafruit_VL53L1X(XSHUT_PIN, IRQ_PIN);

//Enables a specific port number
void enableMuxPort(byte portNumber)
{
  if (portNumber > 7) portNumber = 7;
  Serial.println("1");
  Wire.beginTransmission(MUX_ADDR);
  Serial.println("2");
  //Read the current mux settings
  delay(10);
  Wire.requestFrom(MUX_ADDR, 1);
  Serial.println("3");
  if (!Wire.available()) return; //Error
  byte settings = Wire.read();
  Serial.println("4");
  //Set the wanted bit to enable the port
  settings |= (1 << portNumber);
  Serial.println("5");
  Wire.write(settings);
  Serial.println("6");
  Wire.endTransmission();
  Serial.println("7");
}

//Disables a specific port number
void disableMuxPort(byte portNumber)
{
  if (portNumber > 7) portNumber = 7;
  Serial.println("1");

  Wire.beginTransmission(MUX_ADDR);
  Serial.println("2");
//Read the current mux settings
  Wire.requestFrom(MUX_ADDR, 1);
  Serial.println("3");
  if (!Wire.available()) return; //Error
  Serial.println("4");
  byte settings = Wire.read();
  Serial.println("5");

  //Clear the wanted bit to disable the port
  settings &= ~(1 << portNumber);
  Serial.println("6");

  Wire.write(settings);
  Serial.println("7");
  Wire.endTransmission();  
  Serial.println("8");

}

void setup() {
  Serial.begin(115200);
  while (!Serial) delay(10);

  Serial.println(F("Adafruit VL53L1X sensor demo"));

  Wire.begin();
  Wire.setClock(400000); // tried at 100 and 400
  /*disableMuxPort(0);
  disableMuxPort(1);
  disableMuxPort(2);
  disableMuxPort(3);
  disableMuxPort(4);
  disableMuxPort(5);
  disableMuxPort(6);
  disableMuxPort(7);*/
   
  enableMuxPort(0);
  /*enableMuxPort(1);
  enableMuxPort(2);
  enableMuxPort(3);
  enableMuxPort(4);
  enableMuxPort(5);
  enableMuxPort(6);
  enableMuxPort(7);*/
  
  if (! vl53.begin(0x29, &Wire)) {
    Serial.print(F("Error on init of VL sensor: "));
    Serial.println(vl53.vl_status);
    while (1)       delay(10);
  }
  Serial.println(F("VL53L1X sensor OK!"));

  Serial.print(F("Sensor ID: 0x"));
  Serial.println(vl53.sensorID(), HEX);

  if (! vl53.startRanging()) {
    Serial.print(F("Couldn't start ranging: "));
    Serial.println(vl53.vl_status);
    while (1)       delay(10);
  }
  Serial.println(F("Ranging started"));

  // Valid timing budgets: 15, 20, 33, 50, 100, 200 and 500ms!
  vl53.setTimingBudget(50);
  Serial.print(F("Timing budget (ms): "));
  Serial.println(vl53.getTimingBudget());

  /*
  vl.VL53L1X_SetDistanceThreshold(100, 300, 3, 1);
  vl.VL53L1X_SetInterruptPolarity(0);
  */
}

void loop() {
  int16_t distance;

  if (vl53.dataReady()) {
    // new measurement for the taking!
    distance = vl53.distance();
    if (distance == -1) {
      // something went wrong!
      Serial.print(F("Couldn't get distance: "));
      Serial.println(vl53.vl_status);
      return;
    }
    Serial.print(F("Distance: "));
    Serial.print(distance);
    Serial.println(" mm");

    // data is read out, time for another reading!
    vl53.clearInterrupt();
  }
}

Try disabling all but one set of i2c pullup resistors…probably makes more sense to disable the ToF sensor jumpers and leave the mux one intact https://learn.sparkfun.com/tutorials/qw … e-overview is the guide for the ToF, go to the jumper section…then also the same for this one https://learn.sparkfun.com/tutorials/qw … uWEALw_wcB

Hi, good idea but even if I remove the ToF sensor and the thing plus is just talking to the MUX it still hangs. The only pull ups present are on the MUX in this scenario.

Surely someone has a esp32-s2 thing plus and a sparkfun MUX and they can try and duplicate the situation, right? I would really appreciate it.

Maybe this helps. Looking at https://github.com/sparkfun/SparkFun_I2 … ibrary.cpp. There is a routine called getport() in which is states NOT to do beginTransmission(_deviceAddress)

//Returns the first port number bit that is set
//Returns 255 if no port is enabled
//Return 254 if there is an I2C error
uint8_t QWIICMUX::getPort()
{
  //Read the current mux settings
  //_i2cPort->beginTransmission(_deviceAddress); <- Don't do this!
  _i2cPort->requestFrom(_deviceAddress, uint8_t(1));
  if (!_i2cPort->available())
    return (254); //Error
  uint8_t portBits = _i2cPort->read();

  //Search for the first set bit, then return its location
  for (uint8_t x = 0; x < 8; x++)
  {
    if (portBits & (1 << x))
      return (x);
  }
  return (255); //Return no port set
}

This did it! The documentation should really be updated here to point to the library you sited: https://learn.sparkfun.com/tutorials/qw … uWEALw_wcB