SparkFun_VL53L1X_Arduino_Library icon indicating copy to clipboard operation
SparkFun_VL53L1X_Arduino_Library copied to clipboard

Suggestion: Add getGetRangeStatus() to example to properly handle empty rooms and out of range.

Open jhaand opened this issue 2 years ago • 0 comments

Expected: Doing a getDistance() with the VL53L1x sensor towards an empty room results in a large distance reading. Observed: Sometimes the getDistance() towards an empty room results in values close to the sensor (500 mm or less.) work-around: Check the quality of the measured value by doing a getRangeStatus() over the observed reading. If it's not 0 or 1, then discard the de read distance.

Reference: St forum discussion here. https://community.st.com/s/question/0D50X00009sUiJUSA0/out-of-range-readings-of-vl53l1x

note: This has taken me more than a day to figure out. It would help if the default example would also show the getRangeStatus() of the sensor to help people get their application going. See the example below.

        distanceSensor.startRanging(); // Write configuration bytes to initiate measurement
        while (!distanceSensor.checkForDataReady()) {
            delay(1);
        } 
        distance = distanceSensor.getDistance(); // Get the result of the measurement from the sensor
        sensor_state = distanceSensor.getRangeStatus(); // Check if the sensor actually sees an object.
        distanceSensor.clearInterrupt();
        distanceSensor.stopRanging();
    }
    if (sensor_state > 0) {   // If no object is seen then return an status value. 
        distance = -1;
    }
    return distance;

jhaand avatar Aug 19 '22 10:08 jhaand