Multiple TOF VL53L0X sensors I2C

I am trying to read data from 3 vl53l0x sensors on the i2c bus. I am using the xshut pins to shut the other sensors off during address setting. I have tried to use the VL53L0X_SetDeviceAddress from the vl53l0x_api.h, and i can change the address with that code but how do i read data from the sensors?

if i connect three sensors and enter this code:

#include “Seeed_vl53l0x.h”
Seeed_vl53l0x VL53L0X;

#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
#define SERIAL SerialUSB
#else
#define SERIAL Serial
#endif

void setup() {
pinMode(6, OUTPUT); //xshut pins
pinMode(7, OUTPUT);
pinMode(8, INPUT);
delay(100); //allow sensor 3 to power -up

VL53L0X_SetDeviceAddress(1, 48);

VL53L0X_Error Status = VL53L0X_ERROR_NONE;
SERIAL.begin(115200);
Status = VL53L0X.VL53L0X_common_init();
if (VL53L0X_ERROR_NONE != Status) {
    SERIAL.println("start vl53l0x mesurement failed!");
    VL53L0X.print_pal_error(Status);
    while (1);
}
VL53L0X.VL53L0X_continuous_ranging_init();
if (VL53L0X_ERROR_NONE != Status) {
    SERIAL.println("start vl53l0x mesurement failed!");
    VL53L0X.print_pal_error(Status);
    while (1);
}

}

void loop() {

VL53L0X_RangingMeasurementData_t RangingMeasurementData;
VL53L0X.PerformContinuousRangingMeasurement(&RangingMeasurementData);
if (RangingMeasurementData.RangeMilliMeter >= 2000) {
    SERIAL.println("out of ranger");
} else {
    SERIAL.print("distance::");
    SERIAL.println(RangingMeasurementData.RangeMilliMeter);
}
delay(100);

}

the code runs and i can see the data from one sensor

how do i read the data from the other sensors? How do i specify that for instance ‘init’ should be performed for sensor 2 and 3

In the library there is a variable called ‘VL53L0X_DEV’, this is the device number. I suppose i have to set this to 1, 2, 3, for sensor 1 2 and 3 but I dont know how

It is necessary to define multiple objects first.

 Seeed_vl53l0x vlx1;
 Seeed_vl53l0x vlx2;
 Seeed_vl53l0x vlx3;
 Seeed_vl53l0x vlx4;

Then you need to modify the I2C address and check if it takes effect. If the I2C address is set successfully, there is no effect between the different objects.

Thank you for your reply

when I define more then 2 objects I get an error message telling me I have ran out of dynamic memory (global variables taking up too much memory). I am at 104% memory use (2138 bytes) when I create 3 objects. Any ideas on changing the library to optimise memory usage?

There isn’t much room for library optimizations at the moment, so I recommend using them on products with more ram. @kpotmake