Hi,
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.
Olivier,
#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);
delay(500);
// Initialisation I2C
Wire.begin();
Wire.setClock(400000);
Serial.begin (115200);
// Initialisation TOF 1, 0x31
digitalWrite(Pin_0, HIGH);
delay(50);
Dev_0->I2cDevAddr = 0x52;
VL53L1_software_reset(Dev_0);
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);
if(status_0)
{ Serial.println(F(" VL53L1_StartMeasurement failed "));
while(1);}
// Initialisation TOF 2, 0x33
digitalWrite(Pin_1, HIGH);
delay(50);
Dev_1->I2cDevAddr = 0x52;
VL53L1_software_reset(Dev_1);
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);
if(status_1)
{ Serial.println(F(“VL53L1_StartMeasurement failed”));
while(1);}
}
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);
}