VL6180 TOF distance sensor crosstalk compensation - anybody done it?

I got one of these for a project. Hooked it up, ran the example program and all’s good - except for I can’t get COM3 talking at 115200, but that’s not the issue. Having this little board naked to the world is ok for initial tests and 'Ooh, that’s neat!" but I want to protect it with a piece of glass. Naturally, putting glass in front of the laser aperture disturbs the force and the readings go south. This document from ST explains how to compensate for glass in front of the laser. Here’s an excerpt -

An example of how to implement the cross talk compensation, assuming the device is
setup with a test setup as shown in Figure 4 above is described. The system takes 10
successive measurements for raw range. The equation shown below will give the cross talk
compensation value to write to the SYSRANGE__CROSSTALK_COMPENSATION_RATE,
Reg 0x001E.

Here’s a snippet from the Adafruit .cpp file which commands the 6180 to take a distance measurement

 // Start a range measurement
  write8(VL6180X_REG_SYSRANGE_START, 0x01);
          So would my line look like:


// which I'm guessing resolves to:  write8(0x1e,oxnn)

//        No?

And the Adafruit example file

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

Adafruit_VL6180X vl = Adafruit_VL6180X();

void setup() {

  // wait for serial port to open on native usb devices
  while (!Serial) {
  Serial.println("Adafruit VL6180x test!");
  if (! vl.begin()) {
    Serial.println("Failed to find sensor");
    while (1);
  Serial.println("Sensor found!");

void loop() {
  float lux = vl.readLux(VL6180X_ALS_GAIN_5);

  Serial.print("Lux: "); Serial.println(lux);
  uint8_t range = vl.readRange();
  uint8_t status = vl.readRangeStatus();

  if (status == VL6180X_ERROR_NONE) {
    Serial.print("Range: "); Serial.println(range);

  // Some error occurred, print it out!
  if  ((status >= VL6180X_ERROR_SYSERR_1) && (status <= VL6180X_ERROR_SYSERR_5)) {
    Serial.println("System error");
  else if (status == VL6180X_ERROR_ECEFAIL) {
    Serial.println("ECE failure");
  else if (status == VL6180X_ERROR_NOCONVERGE) {
    Serial.println("No convergence");
  else if (status == VL6180X_ERROR_RANGEIGNORE) {
    Serial.println("Ignoring range");
  else if (status == VL6180X_ERROR_SNR) {
    Serial.println("Signal/Noise error");
  else if (status == VL6180X_ERROR_RAWUFLOW) {
    Serial.println("Raw reading underflow");
  else if (status == VL6180X_ERROR_RAWOFLOW) {
    Serial.println("Raw reading overflow");
  else if (status == VL6180X_ERROR_RANGEUFLOW) {
    Serial.println("Range reading underflow");
  else if (status == VL6180X_ERROR_RANGEOFLOW) {
    Serial.println("Range reading overflow");

In the .h file there’s a list of #defines equating register names like that above to hex values. As in:


Would a define of my own work just the same as the ones in the library?

Must the ‘VL6180X_’ preface any commands I make which aren’t included in the library?

Am I overcomplicating it?

Does it have to be glass?
I use a piece of kapton tape stuck directly onto the sensor. This works without compensation.

Thanks for the reply! That's a pretty nifty idea. I was contemplating having the post moved to a more active forum to get a response.

Does it have to be glass? No. I just never considered anything else since the manufacturer only discusses compensating for glass. It would certainly simplify matters to only have to issue a read command. Besides, cutting and mounting the glass has its own complications besides the programming aspect.

Amazon has this stuff pretty cheap but it still seems such a waste to buy yards of the stuff and only use a postage stamp size piece. But, if it works...

What thickness do you use?

The cheap stuff on Ebay is about 20 microns in thickness and works OK.
Cheap = thin = good.

Try experimenting with whatever transparent tape you have to hand. For indoor use, the cheapest office sticky tape might work.
For outdoor use look for a polyester tape, or something that specifically says "weatherproof" in the description.

Kapton is space rated so it will easily survive the indoor and outdoor conditions encountered on earth.

Try experimenting with whatever transparent tape you have to hand.

Lacking transparent tape, everything around here is the frosted type, in the interest of science, I tried a piece. It works but at a certain point distance reported got greater when it was supposed to be decreasing. I tried a clear CD jewel case. Didn't work half bad but due to the rim on the case I couldnt' get the sensor flat against it. I think it's important that whatever is used it be right against the chip surface. My theory is this cuts down on the reflections bouncing between laser and sensor.

More experimenting to do.