Pololu Robotics & Electronics
My account Comments or questions? About Pololu Contact Ordering information Distributors

Pololu Forum

VL53L1X API STSW-IMG007 - how to set distance threshold

I have a working sketch using the Fast Ranging (100Hz) setup shown in ST App Note AN5263. The application also requires a maximum threshold distance which I am attempting to set using VL53L1_SetThresholdConfig(Dev, detectionConfig);.

Can you provide some guidance on the correct C++ syntax for listing the parameters:

detectionConfig->DetectionMode = 1;
detectionConfig->Distance.CrossMode = 0;
detectionConfig->Distance.Low = 80;

This does not compile. The error is: ‘detectionConfig does not name a type’

Thank you


How are you declaring detectionConfig? It looks like it should be a struct of type VL53L1_DetectionConfig_t.


That’s my question - what is the syntax for that struct? For example:

struct VL53L1_DetectionConfig_t {
detectionConfig.DetectionMode = 1;
detectionConfig.Distance.CrossMode = 0;
detectionConfig.Distance.Low = 80;


Something like this. There is no example provided in the documentation. That would be a very useful addition to the example code.


Could you try this and see if it works?

VL53L1_DetectionConfig_t detectionConfig;

detectionConfig.DetectionMode = 1;
detectionConfig.Distance.CrossMode = 0;
detectionConfig.Distance.Low = 80;

VL53L1_SetThresholdConfig(Dev, &detectionConfig);


This did not compile. There error is:

cannot convert ‘VL53L1_DetectionConfig_t’ to ‘VL53L1_DetectionConfig_t*’ for argument ‘2’ to ‘VL53L1_Error VL53L1_SetThresholdConfig(VL53L1_DEV, VL53L1_DetectionConfig_t*)’

Are you missing the ampersand in the last line?

That did it!

Compiled and working!

Thank you.


I have some additional questions regarding my implementation which uses multiple VL53L1X sensors used simply as proximity sensors. I don’t need to know the distance, just need the interrupt to trigger and the ISR records the elapsed time using millis(). Each sensor should continuously range and when an object is detected in the threshold I want to read the interrupt. I’m using I2C to set addresses and to clear the sensor interrupt.

I have a sketch functioning (modified the provided example sketch) using a single sensor where I can change the address. The following function:

status = VL53L1_WaitMeasurementDataReady(Dev);

works but seems to have a timeout. I don’t want a timeout. Is this the best function to use?


All of the information we have about ST’s VL53L1X API comes from the documentation that they provide, and our work with it has generally been limited to writing the Arduino platform layer and verifying that it works properly, so for any in-depth questions about the API functions, you would probably be better off trying to contact ST directly. You might try posting your question on their community site.


Can you provide some guidance on how to handle the threshold settings for multiple sensor objects? Ideally I would like to provide a different threshold low distance for each sensor.


I do not have any specific recommendations about doing that. Are you having trouble working with multiple sensors?


The sensors have some variation in the threshold distance so it would be useful to be able to have a different distance quantity for each. I tried putting each sensor setup in a function with the dedicated structure:

//sensor 14 ************************************************************
void sensor14Setup() {

VL53L1_DetectionConfig_t detectionConfig14;

detectionConfig14.DetectionMode = 1;
detectionConfig14.Distance.CrossMode = 0;
detectionConfig14.Distance.Low = 70;

VL53L1_SetThresholdConfig(Dev14, &detectionConfig14);

This doesn’t seem to work.

We have not really done much with thresholds in the API, so I don’t think we have any particular advice to offer. One troubleshooting step you could try is looking at the actual distance readings reported by the sensors to see if they are what you expect (that would tell you whether the distances themselves seem wrong or the threshold configuration doesn’t seem to be working as intended).

Otherwise, for issues that are not specific to our VL53L1X carrier board, ST should be better able to help you with the API and the VL53L1X sensor itself.