VL53L0X Distance Sensor interrupt setup

Hi,

I can get VL53L0X to work with Adafrui and/or Pololu library (I will be talking about Pololu library).
I need accurate but not fast measurement (2 times a sec is plenty) – I enabled „HIGH_ACCURACY“ and set time budget to 0,5s, but then Arduino just waits till VL53L0X reports back distance and then continues, that's an issue because it needs to multiplex display and check other stuff.

I've done some digging and find out that VL53L0X can send interrupt when measurement done and data is ready, but as to my knowledge none of those above libraries have this feature.
Is there an easy way to do this?
Maybe it's possible to send "start measure" command to VL53L0X and don't wait, but rather send another command to get data after certain period of time?

Thanks in advance.

I'm using this sensor version:

The several things at a time thread show how to do multiple timed operations in a non-blocking manner.

The several things at a time method builds upon the blink without delay method.

groundFungus:
The several things at a time thread show how to do multiple timed operations in a non-blocking manner.

The several things at a time method builds upon the blink without delay method.

I know what "blink without delay" is and how it works.
I would change library itself if it would be possible to get rid of that nasty delay, but at least for now I do not understand how that delay is defined or works (need to dig more in to library).

So you can understand my level of knowledge – I wrote my own primitive library for MCP23017, I multiplex outputs for buttons and seven segment display with it, so I'm not noob, but far from expert as well.

Well, I tried to get it done lazy way – by asking, guess I have to dig in to VL53L0X API and write my own library.... :slight_smile:

A little update in case any one has this issue as well.

VL53L0X does fire interrupt every time measurement is ready, as for library "delay" till it gets measurement, I'm guessing these 3 while loops keep Arduino ocupied:

// Returns a range reading in millimeters when continuous mode is active
// (readRangeSingleMillimeters() also calls this function after starting a
// single-shot range measurement)
uint16_t VL53L0X::readRangeContinuousMillimeters(void)
{
  startTimeout();
  while ((readReg(RESULT_INTERRUPT_STATUS) & 0x07) == 0)
  {
    if (checkTimeoutExpired())
    {
      did_timeout = true;
      return 65535;
    }
  }

  // assumptions: Linearity Corrective Gain is 1000 (default);
  // fractional ranging is not enabled
  uint16_t range = readReg16Bit(RESULT_RANGE_STATUS + 10);

  writeReg(SYSTEM_INTERRUPT_CLEAR, 0x01);

  return range;
}
// Read an arbitrary number of bytes from the sensor, starting at the given
// register, into the given array
void VL53L0X::readMulti(uint8_t reg, uint8_t * dst, uint8_t count)
{
  Wire.beginTransmission(address);
  Wire.write(reg);
  last_status = Wire.endTransmission();

  Wire.requestFrom(address, count);

  while (count-- > 0)
  {
    *(dst++) = Wire.read();
  }
}
// Write an arbitrary number of bytes from the given array to the sensor,
// starting at the given register
void VL53L0X::writeMulti(uint8_t reg, uint8_t const * src, uint8_t count)
{
  Wire.beginTransmission(address);
  Wire.write(reg);

  while (count-- > 0)
  {
    Wire.write(*(src++));
  }

  last_status = Wire.endTransmission();
}

I'm guessing first one is my biggest problem, I have to update library so "readRangeContinuousMillimeters" is called only when interrupt is triggered.

I'll keep updating here my progress on this issue... If anyone has any ideas please let me know cos I'm not pro at this :slight_smile:

Were you ever able to solve this problem? I have running into the exact same problem trying to use the ToF sensor and neopixels. It messes up my neopixel animations. Really looking for some guidance.