Cover glass calibration for vl53l0x

I am planning to place a piece of cover glass in front of vl53l0x and then seal it with silicone to make the sensor waterproof and splash proof. I see there is a user manual by ST electronics to calibrate for this but there does not appear to be an equivalent for arduino.

I found some code online and added some code for the vl53l0x and was wondering if I could get some feedback on it as I am not sure if it is working properly....

#include <Wire.h>
#include "Adafruit_VL53L0X.h"


Adafruit_VL53L0X lox = Adafruit_VL53L0X();


#define CALIBRATE_DISTANCE_OFFSET                   (0x61)
#define CALIBRATE_SPAD                              (0x75)
#define TEMPERATURE_CALIBRATION                     (0x55)


void setup() {
 Serial.begin(115200);


 // wait until serial port opens for native USB devices
 while (! Serial) {
   delay(1);
 }
 
 Serial.println("Adafruit VL53L0X test");
 if (!lox.begin()) {
   Serial.println(F("Failed to boot VL53L0X"));
   while(1);
 }
 // power 
 Serial.println(F("VL53L0X API Simple Ranging example\n\n")); 
}




void mm_to_bytes(uint8_t *bytes, uint16_t mm)
{
   bytes[0] = (mm >> 8 & 0xFF);
   bytes[1] = (mm & 0xFF);
}


void offset_calibration_routine()
{
 
 /* Calibrate SPADs */
 Wire.beginTransmission(0x29);
 Wire.write(CALIBRATE_SPAD);
 Wire.endTransmission();


 delay(1000);






 /* Calibrate Temperature */


 Wire.beginTransmission(0x29);
 Wire.write(TEMPERATURE_CALIBRATION);
 Wire.endTransmission();


 delay(1000);


 /* Calibrate Offset */


 uint8_t calib_dist = 100; //In millimeters
 uint8_t dist_bytes[2];
 mm_to_bytes(dist_bytes, calib_dist);
 Wire.beginTransmission(0x29);
 Wire.write(CALIBRATE_DISTANCE_OFFSET);
 Wire.write(dist_bytes[0]);
 Wire.write(dist_bytes[1]);
 Wire.endTransmission();


 delay(10000);


 Serial.println("Calibration Complete");
}


void loop() {
 VL53L0X_RangingMeasurementData_t measure;
   
 Serial.print("Reading a measurement... ");
 lox.rangingTest(&measure, false); // pass in 'true' to get debug data printout!


 if (measure.RangeStatus != 4) {  // phase failures have incorrect data
   Serial.print("Distance (mm): "); Serial.println(measure.RangeMilliMeter);
 } else {
   Serial.println(" out of range ");
 }
   
 delay(500);
}

The VL53L0X uses 940nm wavelength. That is infrared. It can not go through glass very well. I think that plexiglass or poly-carbonate have less problems with it.

Please follow the advice on posting code given in Read this before posting a programming question

In particular note the advice to Auto format code in the IDE and to use code tags when posting code here as it prevents some combinations of characters in code being interpreted as HTML commands such as italics, bold or a smiley character, all of which render the code useless

If the code exceeds the 9000 character inline limit then attach it to a post

Koepel:
The VL53L0X uses 940nm wavelength. That is infrared. It can not go through glass very well. I think that plexiglass or poly-carbonate have less problems with it.

This is some of the benchtop data I got. I did 3 trials with the cover glass parallel to the sensor and 3 trials without the ccover glass. The specific type of cover glass I am using is one used for scientific purposes. There appears to be no difference with or without the cover glass but the sensor appears to be inaccurate after 130 mm.

That is infrared.It can not go through glass very well

For this purpose, glass cover slips do not absorb significantly at 940 nm. Nor does common "window glass".

Typical spectrum:

Thank you both for the extra information and correction.

You have this example: Adafruit_VL53L0X/vl53l0x.ino at master · adafruit/Adafruit_VL53L0X · GitHub.
A function offset_calibration_routine() is added, but not used.

Manufacturer's page of the VL53L0X: https://www.st.com/en/imaging-and-photonics-solutions/vl53l0x.html with datasheet.

Video: VL53L0X: Calibration-Free Dirty Environment Cover Glass Solution.

Application Note AN4907 VL53L0X ranging module cover window guidelines.

Can you tell something about the "some code online" and the "user manual" for calibration ?

Possibly useful : https://www.st.com/content/st_com/en/products/embedded-software/proximity-sensors-software/stsw-img005.html?dl=obHin8FAIw0ZzTEQMe2gtQ%3D%3D%2CXXQm0y07BtSdi9Akq7DM1ImPqu9rfv3E1JpCMGElRUI6c7NZ7dI7tLwScxvNoMXHY1DYy1bxpjK8tbqrlWjVncuCtOs403gcJfFnaC0nszWSHZH4xuByumNGF%2Fgv4SEue%2FwhELDhN4%2BcHyJQxkaEqNGog0RvxSdvfEA14fO2%2BSQ5e7lgPiZL4x7tKyXgygjQwAguZVkhUDBWk9marj2nGhNbl4F2xc8aZYMYthY%2BMa2XW0mOBLoNIzRnpl%2BURfIL3RZYBnh7hOf3PJyA4lCTtFbWpAxXsHRy6VR0KPP9CQkCyZvc%2Fg8q6QpTVAPcTlqx&uid=Ecs0/xALZNzzmeYF7QA5xXzefvsCS4H8

The parameter to be adjusted/calibrated for a cover glass is 'cross talk'.

Koepel:
Thank you both for the extra information and correction.

You have this example: Adafruit_VL53L0X/examples/vl53l0x/vl53l0x.ino at master · adafruit/Adafruit_VL53L0X · GitHub.
A function offset_calibration_routine() is added, but not used.

Manufacturer's page of the VL53L0X: VL53L0X - Time-of-Flight (ToF) ranging sensor - STMicroelectronics with datasheet.

Video: VL53L0X: Calibration-Free Dirty Environment Cover Glass Solution.

Application Note AN4907 VL53L0X ranging module cover window guidelines.

Can you tell something about the "some code online" and the "user manual" for calibration ?

The calibration code I found was for mappydots, totally different system but thought I would give it a try. Code runs when I put upload it but I am not sure if its doing the right thing. The ST user manual has code and functions that do not apply to the adafruit vl53l0x library. Since I am a beginner, I found myself stuck trying to sketch up some calibration code for the sensor. Furthermore for my bench top tests, it appears that the sensor is deviating a lot from the control while the cover glass does not appear to be influencing the readings.

dougp:
Possibly useful : https://www.st.com/content/st_com/en/products/embedded-software/proximity-sensors-software/stsw-img005.html?dl=obHin8FAIw0ZzTEQMe2gtQ%3D%3D%2CXXQm0y07BtSdi9Akq7DM1ImPqu9rfv3E1JpCMGElRUI6c7NZ7dI7tLwScxvNoMXHY1DYy1bxpjK8tbqrlWjVncuCtOs403gcJfFnaC0nszWSHZH4xuByumNGF%2Fgv4SEue%2FwhELDhN4%2BcHyJQxkaEqNGog0RvxSdvfEA14fO2%2BSQ5e7lgPiZL4x7tKyXgygjQwAguZVkhUDBWk9marj2nGhNbl4F2xc8aZYMYthY%2BMa2XW0mOBLoNIzRnpl%2BURfIL3RZYBnh7hOf3PJyA4lCTtFbWpAxXsHRy6VR0KPP9CQkCyZvc%2Fg8q6QpTVAPcTlqx&uid=Ecs0/xALZNzzmeYF7QA5xXzefvsCS4H8

The parameter to be adjusted/calibrated for a cover glass is 'cross talk'.

Sorry, i see now why there is a bit of confusion as to why I didn't try the ST manual. I am using the adafruit vl53l0x sensor so the functions provided by ST don't apply.

@coolbeansdog, the Adafruit VL53L0X is the real sensor. Everything that is in the datasheet also applies to the Adafruit module. There are extra components on the module to make it work and make it compatible with 3.3V and 5V Arduino boards.
When you mention something in the manual, can you give a link to the manual and tell what page ? What does not apply ?
Can you give a link to mappydots so we can find the calibration ?
I have added links in my post, so others don't have to search for it. But I'm not Google service to find what you have and what you are talking about. Since you have problem, you should provide the information.
You don't have to quote our posts, what we wrote is already there. Use the "Reply" button or the "Quick Reply" instead of Quote.

@dougp, it is often possible to cut off a link after the .html. The rest is often tracing information. Was that link to a page, then cut it off after the .html. Was that link a direct download link ? Have you tried the link ?

Koepel:
@dougp, it is often possible to cut off a link after the .html. The rest is often tracing information. Was that link to a page, then cut it off after the .html. Was that link a direct download link ? Have you tried the link ?

Link takes me directly to this page -

I tried truncating the URL and this also works - STSW-IMG005 - VL53L0X API (Application Programming Interface and documentation) - STMicroelectronics.

@koepel Yes, my bad. Here is the link to mappydots calibration https://sensordots.org/mappydotcalibration

I attached an image of the calibration flow chart. For example, the first step "DataInit()" is not recognizable by arduino or the sensor. Please see the following code I wrote below by following their steps. The code will run but it doesn't appear to affect the sensor readings. This is apparent when I close this sketch and then run another sketch provided by Adafruit such as the "vl53l0x_oled" sketch.

#include <Wire.h>
#include "Adafruit_VL53L0X.h"
#include "vl53l0x_api_calibration.h"


Adafruit_VL53L0X lox = Adafruit_VL53L0X();


void setup() {
  // put your setup code here, to run once:
VL53L0X_DEV DataInit();
VL53L0X_DEV StaticInit();
VL53L0X_DEV SetReferenceSpadManagement();
VL53L0X_DEV SetRefCalibration();
VL53L0X_DEV SetOffsetCalibration();
VL53L0X_DEV SetXTalkValue();
}


void loop() {
  // put your main code here, to run repeatedly:
}

I'm sorry, but that is too much to read :frowning:
The "UM2039 User Manual" writes about the one-time initialization and the normal offset initialization, but that is with the functions of the library from ST.

The sensor seems to have a NVM (Non Volatile Memory).

On page 7 they show two options: Use the calibration functions each time the sensor is turned on (that takes some time). Or use calibration data that was gathered before (then the Arduino has to store the data in its own EEPROM).

If you choose option 1, then the offset calibration has to be done in setup() every time.

I'm not sure when calibration data is stored in the NVM of the sensor and when not :confused:

Thanks for your help @koepel.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.