DFRobot VL53L0X I2C issue

I am using an Arduino Due with 2 DFRobot VL53L0X sensors. My only goal with this is to verify that I can use them both without having to use a multiplexer as they have the same address by default. According to the data sheet the I2C addresses are programmable and I have followed the example here and the manufacturer example here to do so. The issue that I’m having is that I am unable to get a reading from both sensors at once using SDA, SCL, SDA1, SCL1 pins on the Due. I have 10K pull-ups connected to the SDA1 and SCL1 pins.

#include <Wire.h>
#include "DFRobot_VL53L0X.h"

#define S1_ADDRESS 0x30
#define S2_ADDRESS 0x31

#define S1_SHT 7
#define S2_SHT 6

DFRobotVL53L0X S1;
DFRobotVL53L0X S2;

void setup() {
  Serial.begin(115200);

  pinMode(S1_SHT, OUTPUT);
  pinMode(S2_SHT, OUTPUT);

  digitalWrite(S1_SHT, LOW);
  digitalWrite(S2_SHT, LOW);
  delay(10);

  Wire.begin();
  Wire1.begin();

  
  digitalWrite(S1_SHT, HIGH);
  delay(10);
  S1.begin(S1_ADDRESS);
  delay(10);
  S1.setMode(Continuous, High);
  S1.start();
  
  
  digitalWrite(S2_SHT, HIGH);
  delay(10);
  S2.begin(S2_ADDRESS);
  delay(10);
  S2.setMode(Continuous, High);
  S2.start();
  
}

void loop() {
  
  Serial.print((S1.getDistance()));
  Serial.print(" ");
  Serial.println((S2.getDistance()));
  delay(1000);
}

If I remove any lines involving the second sensor (connected to SDA1 SCL1) then it works and I get the readings I expect. However if I include the second sensor, or only look at the second sensor. I get the following output

Revision ID: 10
Device ID: EE


Revision ID: FF
Device ID: FF

16383.75 16383.75
16383.75 16383.75
16383.75 16383.75

Correct values should be ~200. I also tried to connect these sensors to the same SDA and SCL and changing their addresses, but to do so involves disabling each sensor individually which seems to overwrite the change of address.

Ive found a lot of posts about issues with the Wire library and the Due, but all were several years old, and one post mentioned that the compiler uses a Due specific Wire library. is there something else I’m missing?

That is a 3.3V sensor. If you want to test it with an Arduino Uno, then you have to use a I2C level shifter.

The Due board has wrong pullup resistors of 1k5 or 1k at SDA and SCL. You can remove those.
The SCA1 and SCL1 has no pullup resistors at all, so with 10k pullup resistors it should work with short wires.

Have you run a I2C Scanner for some time ? Both addresses should be found and it should be 100% reliable.

Do you use this library: GitHub - DFRobot/DFRobot_VL53L0X.
That library is not written for two sensors. There is a object “DetailedData” created in “DFRobot_VL53L0X.cpp” and it is used in almost every function. That is a single object.
A major goal of C++ is to have objects that contain everything (functions and data), so they can be used multiple times. That became completely useless with the object “DetailedData”.

Does the Adafruit library allow to use “Wire1” without modifying the source of the library ? I think so, Can you try that ?

Have you run a I2C Scanner for some time ? Both addresses should be found and it should be 100% reliable.

I initially avoided running an I2C Scanner because I read a lot of posts about how they were not reliable for the Due. Granted these were older posts so I just ran it anyway and through the SDA and SCL ports I can successfully identify the sensor. I also added to the I2C scanner code here to verify that the address would successfully change and it does work. However when I switch to the SDA1 and SCL1 pins, I can identify the sensor at the default address, but ONLY at the default address because for some reason the address won't change. I am able to connect both sensors to the SDA and SCL pins and identify that they are both present and successfully change the address.

That library is not written for two sensors. There is a object "DetailedData" created in "DFRobot_VL53L0X.cpp" and it is used in almost every function. That is a single object. A major goal of C++ is to have objects that contain everything (functions and data), so they can be used multiple times. That became completely useless with the object "DetailedData".

This is true even though I create both sensors as separate objects? (Side note C++ is not my strongest so I'm learning as I go) Is it because "DetailedData" is a structure in the header file that is not specifically bound to the object? That would make sense since I can connect both to the same pins, change their addresses, but only get one measurement using the DFRobot library.

Does the Adafruit library allow to use "Wire1" without modifying the source of the library ? I think so, Can you try that ?

It looks as if the Adafruit library has an optional input in "begin" to create a pointer to the specific I2C with the default being Wire. I may be wrong, but this appears as if I could specify Wire1. I was able to get it working by connecting each sensor to the same pin and using the Adafruit example script from my previous post.

Don’t hesitate to use a I2C Scanner, that is the first thing to start with when using the I2C bus.
All the problems that you have read about was a bug in the library and the wrong pullup resistors. The Due is still shipped with the wrong pullup resistors. I don’t know why.

You could show the changed I2C Scanner sketch for SDA1 en SCL1. Is that with your 10k pullup resistors ? It must see two addresses or something is wrong.

Sadly, the “DetailedData” is a single object in the library. Every sensor object uses the same single object.

Have you got the Adafruit library running with Wire1 and both sensors connected to SDA1 en SCL1 ? Can you go on that way ?

You can still remove the onboard pullup resistors of the Due board of 1k or 1k5.