I apologize up front for a “fuzzy” set of data to diagnose my problem…
I have two VL53LOX sensors connected (I2C) to a A* Micro. I use them in continuous mode to minimize the time between readings. To use two sensors I obviously have to change the I2C address of one of them. I successfully unit tested address change and continuous mode (or so I thought) using the pair prior to integrating them into my project.
In my project, sensor address change and initialization are in setup(). loop() looks for incoming commands from Serial. For one command, loop() turns on continuous mode for both sensors, starts reading as fast as possible, and looks at the readings to detect certain conditions. When those conditions occur, loop() turns off continuous mode. It then starts looking for commands again.
Assuming the A* program is loaded, if I power up the sensors (using a power bank), plug in the A* to my laptop, fire up Monitor and send the command, both sensors report valid readings and everything works fine. However, generally this only works for the first command. The vast majority of attempts to repeat the command the sensor with the changed address reports 8190/1 (no report) instead of valid data; the other sensor reports valid data. The only way to fix this that I’ve found is to unplug the A*, remove power to the sensors, power up the sensors, plug in the A*.
I created a simpler test sketch that does something similar (see below). It uses only one sensor with its address changed. The sketch simply starts continuous mode, samples a few times, then stops continuous mode, and repeats the sequence. If simply left running, it does not fail. However, It does sometimes fail as above. The approach that causes failure most easily is: power on the sensors, plug the A* into laptop, start Monitor, run for a bit (will see good data), unplug A*, plug in A* (in essence a reset), kill Monitor, start Monitor. After doing this, the sensor reports 8190/1. Sometimes, the problem occurs when: power on the sensors, plug the A* into laptop, start Monitor, run for a bit (will see good data), kill Monitor, unplug A*, plug in A* (in essence a reset), start Monitor.
I created a sketch that does the same thing, but with no address change. That too would fail using the first approach.
Just to go further, I created a similar sketch that reads both sensors. Same failure (one reads correctly, the one whose address is changed reads 8190/1). The order of reading does not matter; the sensor with the changed address is always the one that fails. The first approach frequently causes a failure. The second approach may not.
I don’t understand at all what is happening. There certainly appears to be something unique about the behavior of the sensor with the changed address. There may be some affect from the use of serial communications. I am hoping for an answer, but would gladly accept suggestions for further diagnosis.
#include <Wire.h>
#include <VL53L0X.h>
VL53L0X sensor;
void setup()
{
Serial.begin(9600);
Wire.begin();
// change address
sensor.setAddress(44);
sensor.init();
sensor.setTimeout(500);
}
void loop()
{
// take readings
sensor.startContinuous();
for (int i = 0; i < 20; i++) {
Serial.print(sensor.readRangeContinuousMillimeters());
if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
Serial.println();
}
// stop continuous mode
sensor.stopContinuous();
delay(200);
Serial.println(".");
}