Problem initializing multiple vl53l0x sensors

I’m having trouble consistently initializing two vl53l0x sensors on the same I2C bus of an Arduino Uno. I’ve been initializing them with separate addresses like so

Wire.begin();
 
  pinMode(SHT_LOX1, OUTPUT);
  pinMode(SHT_LOX2, OUTPUT);

  Serial.println(F("Activating Left Eye and deactivating Right Eye"));
  digitalWrite(SHT_LOX2, HIGH);
  digitalWrite(SHT_LOX1, LOW);

  delay(10);

  Serial.println(F("Initing Left Eye"));
  lox1.setAddress(LOX1_ADDRESS);
  if(!lox1.init()) {
    Serial.println(F("Failed to boot Left Eye"));
    while(1);
  }
  
  Serial.println(F("SUCCESS Left Eye"));

  Serial.println(F("Activating Right Eye"));
  digitalWrite(SHT_LOX1, HIGH);
  Serial.println(F("Deactivating Left Eye"));
  digitalWrite(SHT_LOX2, LOW);
  Serial.println(F("Initing Right Eye"));

  delay(10);

  lox2.setAddress(LOX2_ADDRESS);
  if(!lox2.init()) {
    Serial.println(F("Failed to boot Right Eye"));
    while(1);
  }
  Serial.println(F("SUCCESS Right Eye"));

My issue is that, depending on the boot, either of the sensors may fail to initialize, Loop() may execute once and crash, or it may work fine. The latter is the rarest case but it does happen and the sensors seem to read fine when it happens. The two sensors are connected to the same I2C bus, I’ve just split the wires. The XSHUT pins are wired to pins D13 and D8, and the Vin comes from the 5V on the board. I am not using any pullup resistors but I’m wondering if I should, perhaps, on the XSHUT pins.

Any helpful troubleshooting tips would be very welcome. The sketch I’m running uses 47% of the onboard memory so based on that and the fact that this sometimes works with no change, I’m thinking it’s more related to a power or wiring issue. I’ve used a continuity tester to verify all points on the sensor are connected to where they should be and the Vin to the sensors reads just below 5V.

Hello.

I am sorry you are having issues consistently communicating with your time of flight sensors. First, I want to point out that XSHUT is not 5V-tolerant. So, you should not be sending a digital high from your Arduino Uno, which is a 5V microcontroller. By default, our VL53L0X boards pull XSHUT up to logic high (VDD, which is 2.8V), so your connection only needs to drive it low to shut the board down or leave it floating (set the Arduino pin to an input) to allow it to be pulled high and enable the board.

If your boards are still working after taking care of that, I recommend modifying your code to not disable the first sensor after setting its address and initializing it. (Doing so will effectively reset the board.) Also, you might want to intentionally reset both sensors at the beginning of your program, which will help avoid issues from inconsistent previous states.

-Jon

1 Like

Thank you, helpful Pololu Man, it seems my sensors are booting up correctly reliably now!

Here’s my updated code for future travellers:


  Wire.begin();
 
 
  Serial.println(F("Powering Eyes off to restart and keep state consistent"));
  pinMode(SHT_LOX1, OUTPUT);
  pinMode(SHT_LOX2, OUTPUT);

  digitalWrite(SHT_LOX2, LOW);
  digitalWrite(SHT_LOX1, LOW);

  delay(10);

  Serial.println(F("Activating Left Eye"));
  pinMode(SHT_LOX1, INPUT);

  Serial.println(F("Initing Left Eye"));
  lox1.setAddress(LOX1_ADDRESS);
  if(!lox1.init()) {
    Serial.println(F("Failed to boot Left Eye"));
    while(1);
  }
  
  Serial.println(F("SUCCESS Left Eye"));

  Serial.println(F("Activating Right Eye"));
  pinMode(SHT_LOX2, INPUT);
  Serial.println(F("Initing Right Eye"));

  delay(10);

  lox2.setAddress(LOX2_ADDRESS);
  if(!lox2.init()) {
    Serial.println(F("Failed to boot Right Eye"));
    while(1);
  }
  Serial.println(F("SUCCESS Right Eye"));
1 Like

this problem appear mostly with external power source, you just can add small delay in your code before starting the communication, to get the power supply stable after that start communication. how to modify the code you can watch that video.