First results of VL53L1X are always inaccurate

I’m using this sensor with a microcontroller that goes into deepsleep after taking a measurement. Because I want it to take as minimal mAh as possible I thought it would be a good idea to switch from continuously operation (and cutting it after receiving 5 results) to single measurements without the continuously measurement in the background. However when doing this I noticed the first 2-3 results are always inaccurate. Any idea why this is the case?

#include <Wire.h>
#include <VL53L1X.h>

VL53L1X sensor;

void setup()
{
  Serial.begin(115200);
  Wire.begin();
  Wire.setClock(400000); // use 400 kHz I2C

  sensor.setTimeout(500);
  if (!sensor.init(true))
  {
    Serial.println("Failed to detect and initialize sensor!");
    while (1);
  }

  sensor.setDistanceMode(VL53L1X::Short);
  sensor.setMeasurementTimingBudget(200000);
}

void loop()
{
   sensor.readSingle(false);

  while (!sensor.dataReady())
  {
    delay(10);
  }

  Serial.print("function output: ");
  Serial.print(sensor.readRangeSingleMillimeters());
  Serial.print("\trange: ");
  Serial.print(sensor.ranging_data.range_mm);
  Serial.print(" mm\tstatus: ");
  Serial.print(VL53L1X::rangeStatusToString(sensor.ranging_data.range_status));
  Serial.print("\tpeak signal: ");
  Serial.print(sensor.ranging_data.peak_signal_count_rate_MCPS);
  Serial.print("\tambient: ");
  Serial.print(sensor.ranging_data.ambient_count_rate_MCPS);
  Serial.print("\tb: ");
  Serial.print(sensor.getMeasurementTimingBudget());

  Serial.println();
  delay(1000);
}

Serial output:

19:26:37.812 -> function output: 41	range: 41 mm	status: range valid	peak signal: 260.68	ambient: 0.21	b: 199426
19:26:39.233 -> function output: 97	range: 97 mm	status: range valid	peak signal: 39.15	ambient: 0.02	b: 199426
19:26:40.620 -> function output: 103	range: 103 mm	status: range valid	peak signal: 17.70	ambient: 0.01	b: 199426
19:26:42.040 -> function output: 103	range: 103 mm	status: range valid	peak signal: 17.69	ambient: 0.01	b: 199426
19:26:43.412 -> function output: 103	range: 103 mm	status: range valid	peak signal: 17.62	ambient: 0.02	b: 199426
19:26:44.848 -> function output: 104	range: 104 mm	status: range valid	peak signal: 17.80	ambient: 0.01	b: 199426
19:26:46.225 -> function output: 103	range: 103 mm	status: range valid	peak signal: 17.73	ambient: 0.02	b: 199426

Thanks in advance

Hello.

Unfortunately, the first couple readings being inaccurate seems to be normal behavior, so you might consider just ignoring the first few readings.

Brandon

Thank you! Would peak signal being lower than 20 the correct way to determin if its a good reading?

The peak signal being higher for the first few readings could be an indication that the sensor is getting too strong of a return signal and needs a few readings to adjust its sensitivity and start giving good results. You might be able to look at that value to decide whether the readings are good, but it might vary if your conditions or target distance will not always be consistent, so you will probably need to do some testing to make sure that works for you.

Alternatively, we generally find that discarding the first few readings is enough to get reliable measurements (though you might want to experiment to see how many readings you need to ignore).

Brandon