cancel
Showing results for 
Search instead for 
Did you mean: 

VL53L0X OffSet Calibration example Does anyone have an VL53L0X OffSet Calibration example they would like to share please. An Arduino sketch would be nice. I have looked at the API document but it is just not clear how you go about writing this app

Iknig.1
Associate II
 
2 REPLIES 2

Hello @Iknig.1​ ,

Take a look at the following example provided under the WB Firmware Package.

  • Path: Projects\STM32WB5MM-DK\Examples\BSP

This may help you.

BeST Regards,

Walid

Anne BIGOT
ST Employee

Hello

The code below is the calibration code for the L1CX. It will work the same way on the L0.

int8_t VL53L1X_CalibrateOffset(uint16_t dev, uint16_t TargetDistInMm, int16_t *offset)

{

uint8_t i, tmp;

int16_t AverageDistance = 0;

uint16_t distance;

VL53L1X_ERROR status = 0;

status |= VL53L1_WrWord(dev, ALGO__PART_TO_PART_RANGE_OFFSET_MM, 0x0);

status |= VL53L1_WrWord(dev, MM_CONFIG__INNER_OFFSET_MM, 0x0);

status |= VL53L1_WrWord(dev, MM_CONFIG__OUTER_OFFSET_MM, 0x0);

status |= VL53L1X_StartRanging(dev); /* Enable VL53L1X sensor */

for (i = 0; i < 50; i++) {

tmp = 0;

while (tmp == 0){

status |= VL53L1X_CheckForDataReady(dev, &tmp);

}

status |= VL53L1X_GetDistance(dev, &distance);

status |= VL53L1X_ClearInterrupt(dev);

AverageDistance = AverageDistance + distance;

}

status |= VL53L1X_StopRanging(dev);

AverageDistance = AverageDistance / 50;

*offset = TargetDistInMm - AverageDistance;

status |= VL53L1_WrWord(dev, ALGO__PART_TO_PART_RANGE_OFFSET_MM, *offset*4);

return status;

}

Duplicate that and it will work fine.

There is some reference code in the L0 library from st.com : VL53L0X_perform_offset_calibration

Anne


Our community relies on fruitful exchanges and good quality content. You can thank and reward helpful and positive contributions by marking them as 'Accept as Solution'. When marking a solution, make sure it answers your original question or issue that you raised.

ST Employees that act as moderators have the right to accept the solution, judging by their expertise. This helps other community members identify useful discussions and refrain from raising the same question. If you notice any false behavior or abuse of the action, do not hesitate to 'Report Inappropriate Content'