Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Problem with VL53L0X interrogation rate
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Problem with VL53L0X interrogation rate

by APEX_FLUX on Thu Jan 16, 2020 6:13 pm

Hello all, new member. We are working on a project that requires us to continuously interrogate four VL53L0X sensors and update variables in our code to indicate if the sensors detect an object within a certain range. We are amateur coders at best. Please be gentle..

We are using an Arduino Nano, with the sensors connected via TCA9548A multiplexer on pins 4 through 7.

We would like to be able to read each sensor and update the corresponding variables in our code as fast as possible, however our testing indicates the following loop count rates. We performed our performance testing by commenting out the tcaselects associated with each sensor in the code. As you can see from the results, even once sensor enable slows the loop rate by a factor of 10000.

0 sensors enabled: 217000 times per second
1 sensor enabled: 25 times per second
2 sensors enabled: 13 times per second
3 sensors enabled: 9 times per second
4 sensors enabled: 7 times per second

Here is our test code. We would be happy with 50 to 100 times per second with all 4 sensors enabled. Is that an achievable goal? Any ideas/suggestions?



Code: Select all | TOGGLE FULL SIZE
#include "Wire.h"
extern "C" {
  #include "utility/twi.h"  // from Wire library, so we can do bus scanning
}
#include "Adafruit_VL53L0X.h"

Adafruit_VL53L0X lox = Adafruit_VL53L0X();

#define TCAADDR 0x70

byte LO = 0;
byte LI = 0;
byte RI = 0;
byte RO = 0;

int ToF_Thresh = 350;

long LC = 0;
unsigned long startMillis;  //some global variables available anywhere in the program
unsigned long currentMillis;
const unsigned long period = 1000;  //the value is a number of milliseconds

void tcaselect(uint8_t i) {
  if (i > 7) return;
 
  Wire.beginTransmission(TCAADDR);
  Wire.write(1 << i);
  Wire.endTransmission(); 
}

void setup() {
 

    Wire.begin();
    Serial.begin(115200);

    //Serial.println(F("Start Setup."));
   
    tcaselect(4);
    if (!lox.begin()) {
    //Serial.println(F("Failed to boot VL53L0X"));
    while(1);
    }
    tcaselect(5);
    if (!lox.begin()) {
    //Serial.println(F("Failed to boot VL53L0X"));
    while(1);
    }
    tcaselect(6);
    if (!lox.begin()) {
    //Serial.println(F("Failed to boot VL53L0X"));
    while(1);
    }
    tcaselect(7);
    if (!lox.begin()) {
    //Serial.println(F("Failed to boot VL53L0X"));
    while(1);
    } 
   
    startMillis = millis();  //initial start time
}

void Read_Sensors()
{
  //Serial.println(F("Starting Sensor Reading"));

  //Serial.print(F("LC = ")); Serial.println(LoopCount);
  VL53L0X_RangingMeasurementData_t measure;

  tcaselect(4);
    lox.rangingTest(&measure, false); // pass in 'true' to get debug data printout!

    if (measure.RangeStatus != 4)
    {  // phase failures have incorrect data
      if (measure.RangeMilliMeter < ToF_Thresh)
      {
        LO = 1;
       
      }
      else
      {
        LO = 0;
       
      }
    }
    else
    {
      LO = 0;
     
    }
   
    tcaselect(5);
    lox.rangingTest(&measure, false); // pass in 'true' to get debug data printout!

    if (measure.RangeStatus != 4)
    {  // phase failures have incorrect data
      if (measure.RangeMilliMeter < ToF_Thresh)
      {
        LI = 1;
       
      }
      else
      {
        LI = 0;
       
      }
    }
    else
    {
      LI = 0;
     
    }
   
    tcaselect(6);
    lox.rangingTest(&measure, false); // pass in 'true' to get debug data printout!

    if (measure.RangeStatus != 4)
    {  // phase failures have incorrect data
      if (measure.RangeMilliMeter < ToF_Thresh)
      {
        RI = 1;
      }
      else
      {
        RI = 0;
      }
    }
    else
    {
      RI = 0;
    }
   
    tcaselect(7);
    lox.rangingTest(&measure, false); // pass in 'true' to get debug data printout!

    if (measure.RangeStatus != 4)
    {  // phase failures have incorrect data
      if (measure.RangeMilliMeter < ToF_Thresh)
      {
        RO = 1;
      }
      else
      {
        RO = 0;
      }
    }
    else
    {
      RO = 0;
    }

    //delay(20);
}

void loop() {
 
  currentMillis = millis();  //get the current "time" (actually the number of milliseconds since the program started)

  Read_Sensors();
 
  if (currentMillis - startMillis >= period)  //test whether the period has elapsed
  {
    Serial.print("LC = :"); Serial.println(LC);
    startMillis = currentMillis;
    LC = 0;
  }
LC++;

}

APEX_FLUX
 
Posts: 1
Joined: Thu Jan 16, 2020 3:50 pm

Re: Problem with VL53L0X interrogation rate

by dastels on Thu Jan 16, 2020 7:02 pm

Those timings seem about right. Each measurement takes roughly 33mS.

Maybe if you use continuous ranging mode? You might want to dig deeper into the API and datasheet to figure out how to get better performance out of them.

Dave

dastels
 
Posts: 3401
Joined: Tue Oct 20, 2015 3:22 pm

Re: Problem with VL53L0X interrogation rate

by zener on Sat Jan 18, 2020 3:29 pm

APEX_FLUX wrote:We would be happy with 50 to 100 times per second with all 4 sensors enabled. Is that an achievable goal?


Sometimes it helps to distill a question down to a list of simpler questions.

Is it fair to say that reading 4 senors would take at least as much time as reading one sensor? Or maybe even more time? If so, then would it be reasonable to first ask: "Can we read one sensor 50 times per second"?

After reading pages 14 and 15 of the data sheet, how would you answer that question?

zener
 
Posts: 4567
Joined: Sat Feb 21, 2009 2:38 am

Re: Problem with VL53L0X interrogation rate

by sreeji561 on Fri Mar 27, 2020 5:15 am

I also face the same problem. Maximum response frequency/ interrogation rate I am getting is 20 Hz with one sensor.
Please help if someone know how to increse sampling frequency/ interrogation rate.

Is there any method to increase this 20 Hz.
Or is there any other sensor which can achieve this?

sreeji561
 
Posts: 3
Joined: Fri Mar 27, 2020 3:50 am

Please be positive and constructive with your questions and comments.