I made a fixture so that the sensor stayed a fixed distance from a target (approx 60mm) and collected data over hours (attached). This resulted in a long term data trend of 56000 samples, taken roughly 1 per second over the course of roughly 15 hours. The data reflects some basic smoothing of the measurement in the Arduino code.
Notice that it took about 45 minutes for the sensor to stabilize, and then there appears to be a 20 minute cyclical trend in the data. My guess that this is temperature dependent, and this 20 min cycle is related to my furnace cycling.
Here are some details of the 20 minute cycle.
Arduino Code:
#include <Wire.h>
#include <VL6180X.h>
VL6180X sensor;
float dist, sens;
int count;
void setup()
{
Wire.begin();
sensor.init();
sensor.configureDefault();
// Reduce range max convergence time and ALS integration
// time to 30 ms and 50 ms, respectively, to allow 10 Hz
// operation (as suggested by Table 6 ("Interleaved mode
// limits (10 Hz operation)") in the datasheet).
sensor.writeReg(VL6180X::SYSRANGE__MAX_CONVERGENCE_TIME, 05);
//sensor.writeReg16Bit(VL6180X::SYSALS__INTEGRATION_PERIOD, 10);
sensor.setTimeout(500);
// stop continuous mode if already active
sensor.stopContinuous();
// in case stopContinuous() triggered a single-shot
// measurement, wait for it to complete
delay(300);
//READOUT__AVERAGING_SAMPLE_PERIOD
sensor.writeReg(0x10A, 0x08);
// start interleaved continuous mode with period of 100 ms
//sensor.startInterleavedContinuous(100);
sensor.startRangeContinuous(10);
Serial.begin(57600);
//ideas
// Look at docs to see how to improve accuracy
// only use samples that converged
// look into whether samples are used twice or other issues with the uncoltrolled loop
// allow more variability in the output of the sensor and average in the mcu
// measure drift by connecting to the CNC machine to get precise moves
count=100;
}
void loop()
{
//Serial.print("Ambient: ");
//Serial.print(sensor.readAmbientContinuous());
//if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
sens=sensor.readRangeContinuous();
if(sens<255)
{
if( abs(sens-dist)>10.0) {dist=sens;}
dist = .995* dist + .005 * sens;
}
count=count-1;
if (count ==0)
{
count=100;
//Serial.print("\t Range: ");
Serial.print(dist);
Serial.println();
}
if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
}
I did some experiments using the setup and i think i could get it up to about +/- .3mm accuracy by using multiple nested loops and picking the mean value out of each loop. Ended up with a 4x - 8x -8x loop that does then take about 15s to finish a single measurement. Theoretically i think you should use 6 or more sensors (maybe with a center mirroring cone to make them sense a single point), and then you could make the measuring speed go down to 1s with some smart coding, and you should get more precise readings ofcourse.
Also, the VL53L3CX sensor has the same short range of min 1cm and seems a lot more accurate in this video at least:
How accurate are time of flight sensors? - YouTube