2 ToF VL53L1x, ST Api, Insufficient memory problem

I am using 4 VL53L1X without problems.
As I need to redefine the ROI, I change and try the following configuration : 2 VL53L1X, ST API, Arduino Pro.

The adapted Arduino code works fine with one VL53L1X.
As soon as I declare a second one in the code, an “out of memory” message appears during the compilation (line “Dev_1->I2cDevAddr = 0x52;” hereafter)

Here is my code. Any advice would be really thank.


#include <Wire.h>
#include “vl53l1_api.h”

VL53L1_Dev_t sensor_0;
VL53L1_Dev_t sensor_1;

VL53L1_DEV Dev_0 = &sensor_0;
VL53L1_DEV Dev_1 = &sensor_1;

int Pin_0 = 7;
int Pin_1 = 8;

int status_0;
int status_1;

void setup()
pinMode(Pin_0, OUTPUT);
pinMode(Pin_1, OUTPUT);
digitalWrite(Pin_0, LOW);
digitalWrite(Pin_1, LOW);


// Initialisation I2C
Serial.begin (115200);

// Initialisation TOF 1, 0x31
digitalWrite(Pin_0, HIGH);

Dev_0->I2cDevAddr = 0x52;
status_0 = VL53L1_SetDeviceAddress(Dev_0, 0x31);
Dev_0->I2cDevAddr = 0x31;
status_0 = VL53L1_WaitDeviceBooted(Dev_0);
status_0 = VL53L1_DataInit(Dev_0);
status_0 = VL53L1_StaticInit(Dev_0);
status_0 = VL53L1_SetDistanceMode(Dev_0, VL53L1_DISTANCEMODE_LONG);
status_0 = VL53L1_SetMeasurementTimingBudgetMicroSeconds(Dev_0, 50000);
status_0 = VL53L1_SetInterMeasurementPeriodMilliSeconds(Dev_0, 50);
status_0 = VL53L1_StartMeasurement(Dev_0);
{ Serial.println(F(" VL53L1_StartMeasurement failed "));

// Initialisation TOF 2, 0x33
digitalWrite(Pin_1, HIGH);

Dev_1->I2cDevAddr = 0x52;
status_1 = VL53L1_SetDeviceAddress(Dev_1, 0x33);
Dev_1->I2cDevAddr = 0x33;
status_1 = VL53L1_WaitDeviceBooted(Dev_1);
status_1 = VL53L1_DataInit(Dev_1);
status_1 = VL53L1_StaticInit(Dev_1);
status_1 = VL53L1_SetDistanceMode(Dev_1, VL53L1_DISTANCEMODE_LONG);
status_1 = VL53L1_SetMeasurementTimingBudgetMicroSeconds(Dev_1, 50000);
status_1 = VL53L1_SetInterMeasurementPeriodMilliSeconds(Dev_1, 50);
status_1 = VL53L1_StartMeasurement(Dev_1);
{ Serial.println(F(“VL53L1_StartMeasurement failed”));


void loop()
static VL53L1_RangingMeasurementData_t RangingData_0;
status_0 = VL53L1_WaitMeasurementDataReady(Dev_0);
if (!status_0) status_0 = VL53L1_GetRangingMeasurementData(Dev_0, &RangingData_0);
if (status_0 == 0) Serial.println(RangingData_0.RangeMilliMeter);
status_0 = VL53L1_ClearInterruptAndStartMeasurement(Dev_0);

static VL53L1_RangingMeasurementData_t RangingData_1;
status_1 = VL53L1_WaitMeasurementDataReady(Dev_1);
if (!status_1) status_1 = VL53L1_GetRangingMeasurementData(Dev_1, &RangingData_1);
if (status_1 == 0) Serial.println(RangingData_1.RangeMilliMeter);
status_1 = VL53L1_ClearInterruptAndStartMeasurement(Dev_1);

Hi, Olivier.

Unfortunately, I think my answer is going to be about the same as what I wrote this other topic about “Multiple VL53L1X and memory problems”. The full API is just too big to be able to fit more than one sensor object into memory on a standard ATmega328P-based Arduino, so if you need to use it to change the ROI, you might need to consider a controller with more memory.

Alternatively, ST provides an “Ultra Lite Driver” that you could look into, although we have not used it and I am not sure whether it supports configuring the VL53L1X’s ROI.


Ruben Sluiman adapted ST’s ultra lite driver for Arduino here: https://github.com/rneurink/VL53L1X_ULD. I haven’t used it, but on first glance it looks pretty good and I know the original ST ultra lite driver supports ROI adjustments. If that doesn’t work for you, post back and I’ll upload my adaptation for you to try.

BTW, I had several exchanges with the ST engineer who wrote all the VL53l1X drivers and he said the ultra lite was inspired by Pololu’s driver! He was very complimentary of your work, congrats

1 Like

Thanks for your answer.
I 'll try and let you know.

James, Kevin,

Everything works very well with Ruben Sluiman ULD API for Arduino (29% of dynamic memory with 4 ToF, where it was over 100% with 2 ToF!!)

Next step, couting people with this API !

Merci from France.

Hey @jlo I used this ULD for the VL53L1X Satel from STM.
can I use this for the VL53L1X from Pololu? if not can u recommend me a ULD for VL53L1X pololu.
Thank you

I assume so because @OTelle reported that everything was working and I assume he was using Pololu’s carrier, but again, I haven’t used that library (I made my own adaptation).

@OTelle Hey, can you clarify if the Ruben Sluiman adapted ST’s ultra lite driver is working good with the VL53L1X sensors from Pololu.
I was using 3 Vl53l1x satel boards with the same driver with arduino nano, now I am just gonna change the sensors alone to Pololu.
Thank you