Fast VL53L0X readings

Hello,

I am using two VL53L0X sensors with an arduino nano.
They are connected on the I2C bus and I am able to read values sequentially without any problem.

The next step for me is to make these readings real fast, without much need for accuracy.
I set the sensors parameters as desired using the provided library, no problem there.
Now, I want to use the GPIO interrupt mode on both sensors to make it run continuously and simply read the register when necessary. I connected the GPIO pins on the Arduino’s interrupt pins and checked that the interrupt procedures are called. OK.
The thing is, even in continuous mode (back to back measurements), the interrupt is only thrown when I call the readRangeContinuousMillimeters() function. I would like the chip to run continuously and just send me a signal on GPIO whenever the measurement is ready and I can read the register.
Is that possible with this sensor? With your library? Or do I have to modify some functions?

Thanks for your time !
François

Hello,

The sensor can function like that, but the readRangeContinuousMillimeters() function in our library is blocking. The following code shows how to do this with the interrupt pin:

/* This example shows how to use continuous mode with
 *  with the interrupt pin to take range measurements 
 *  with the VL53L0X. 
 * The range readings are in units of mm. 
*/

#include <Wire.h>
#include <VL53L0X.h>

VL53L0X sensor;

void setup()
{
  Serial.begin(9600);
  Wire.begin();
  pinMode(12, INPUT);   //Interrupt pin on VL53L0X sensor is connected to Pin 12 on the Arduino

  sensor.init();
  sensor.setTimeout(500);

  // Start continuous back-to-back mode (take readings as
  // fast as possible).  To use continuous timed mode
  // instead, provide a desired inter-measurement period in
  // ms (e.g. sensor.startContinuous(100)).
  sensor.startContinuous(50);
}

void loop()
{
  
  if(digitalRead(12)==LOW)
  {
    uint16_t range = sensor.readReg16Bit(sensor.RESULT_RANGE_STATUS + 10);
    sensor.writeReg(sensor.SYSTEM_INTERRUPT_CLEAR, 0x01);
  }

}

By the way, I am not using hardware interrupts in that code, but it should be possible to modify it to do that. Also, you might look at the sensor.setMeasurementTimingBudget() function in the Single.ino example in our library to see how to decrease the time needed for a single measurement.

-Nathan

4 posts were split to a new topic: Calling the VL53L0X library from an ISR