sparkfun / SparkFun_VL53L1X_Arduino_Library

A library for the laser based VL53L1X Time Of Flight distance sensor capable of detecting a target 4m away!
MIT License
88 stars 50 forks source link

Interrupt triggered when out of range #50

Open mine2209 opened 2 years ago

mine2209 commented 2 years ago

I was trying to set up an interrupt for when object comes into range and was getting false triggers when out of range or distant targets. I found the following and worked out what I believe is the issue

Current Library:

void SFEVL53L1X::setDistanceThreshold(uint16_t lowThresh, uint16_t hiThresh, uint8_t window)
{
    _device->VL53L1X_SetDistanceThreshold(lowThresh, hiThresh, window, 1);
}

IntOnTarget is no longer used according to ST datasheet and user guide and should be set to 0 instead

Setting threshold and detection mode
In addition to the regular ranging features, the sensor also has the capability to detect a target with predefined
detection criteria. When the preconfigured criteria are matched the sensor raises an interrupt and returns the
distance.
Use the VL53L1X_ERROR VL53L1X_SetDistanceThreshold (dev, ThreshLow, ThreshHigh, Window,
IntOnNoTarget) to configure the detection criteria.
• ThreshLow is the low distance threshold in millimeters
• ThreshHigh is the high distance threshold in millimeters
• Window :
– Window = 0: Below a certain distance
◦ If object distance > ThreshLow or no object found: no report
◦ If object distance < ThreshLow and object found: report
– Window = 1: Beyond a certain distance
◦ If object distance < ThreshHigh or no object found: no report
◦ If object distance > ThreshHigh and object found: report
– Window = 2: Out of distance range (min/max), "out of Window"
◦ ThreshLow < object distance < ThreshHigh: no report
◦ ThreshLow > object distance > ThreshHigh: report
– Window = 3: Within the distance range (min/max), "inside Window"
◦ ThreshLow > object distance > ThreshHigh: no report
◦ ThreshLow < object distance < ThreshHigh: report
• **IntOnNoTarget is no longer used, set to 0**
To go back to the regular ranging mode, write 0x20 to the 0x46 register (8 bits)

I modified libary as follows and it resolved the issue and I am no longer getting false triggers:

void SFEVL53L1X::setDistanceThreshold(uint16_t lowThresh, uint16_t hiThresh, uint8_t window)
{
    _device->VL53L1X_SetDistanceThreshold(lowThresh, hiThresh, window, 1);
}

Hope this helps, if not could you explain why I noticed the behaviour for my own sanity more than anything else.