2025-08-22 11:42 PM - last edited on 2025-08-23 3:12 AM by Peter BENSCH
Hello,
I am working on a project using an AVR64DB32 MCU and the VL53L1 time-of-flight sensor over I2C.
I downloaded the official API from ST (STSW-IMG007) and adapted vl53l1_platform.c to my environment.
Since my I2C communication library is written in C++, I converted it into vl53l1_platform.cpp.
I also wrote a simple distance measurement test program (main.cpp).
My custom I2C driver (I2cDriver.cpp) is already used in other projects and seems reliable, so I assume the issue is not primarily there. I have attached these files for reference.
Inside the while loop, I repeatedly call VL53L1_WaitMeasurementDataReady.
If successful, I call VL53L1_GetRangingMeasurementData and then VL53L1_ClearInterruptAndStartMeasurement. In this case, I blink an LED once.
If it fails with VL53L1_ERROR_TIME_OUT, I blink the LED twice. For any other error, I blink three times.
After each loop iteration, whether success or failure, I wait one second before retrying.
When running the program, I observe the following behavior:
Several consecutive failures (timeout) occur.
Then, one successful measurement occurs.
This pattern repeats.
When I break in debug mode, I can see that the RangingData values are valid on success.
So, the sensor does measure correctly sometimes.
However, it seems to require many seconds before a measurement succeeds.
According to the documentation, the VL53L1 should be able to deliver measurements at least once per second, but my behavior is much slower.
I experimented with:
VL53L1_SetDistanceMode
VL53L1_SetMeasurementTimingBudgetMicroSeconds
VL53L1_SetInterMeasurementPeriodMilliSeconds
But none of these improved the situation.
Note: For simplicity, the attached code does not check every initialization return value, but in my real program I do, and all calls return VL53L1_ERROR_NONE.
I2C bus speed is 400 kHz.
Power supply: normally from AA batteries, but I also tested with a regulated bench power supply, so I believe insufficient current is not the cause.
Hardware schematic is attached (see image).
GPIO1 is left floating (not used).
XSHUT is not controlled by the MCU; instead, it is pulled up with a 10 kΩ resistor.
Why does VL53L1_WaitMeasurementDataReady fail with repeated timeouts before eventually succeeding?
Is there something fundamental I am missing in the initialization or measurement loop?
Could the way I adapted the vl53l1_platform.c file to my custom C++ I2C driver be the cause?
2025-08-22 11:43 PM