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:
*/
write8(VL6180X_SYSRANGE__CROSSTALK_COMPENSATION_RATE, 0xnn) // Reg. 0x001E
// 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() {
Serial.begin(115200);
// wait for serial port to open on native usb devices
while (!Serial) {
delay(1);
}
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");
}
delay(50);
}
In the .h file there's a list of #defines equating register names like that above to hex values. As in:
#define VL6180X_REG_SYSTEM_FRESH_OUT_OF_RESET 0x016
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?