VL53L0X settings

Hey guys, I am working with VL53LOX time-of-flight sensor along with arduino. I want to know how to change ranging profile of the sensor through arduino and also which profile is default profile? Can we set two profiles to work simultaneously, if so how to do it?

By two profiles to work simultaneously, I meant LONG RANGE and HIGH ACCURACY. sorry for the confusion. tell me how to do it with arduino.

Hello.

I merged your posts together since they are about the same thing. It is possible to set both the LONG_RANGE and HIGH_ACCURACY options in our Single example sketch. If you look at lines 42-57 of that sketch, you can see what parameters we are changing for the sensor for those options:

#if defined LONG_RANGE
  // lower the return signal rate limit (default is 0.25 MCPS)
  sensor.setSignalRateLimit(0.1);
  // increase laser pulse periods (defaults are 14 and 10 PCLKs)
  sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodPreRange, 18);
  sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodFinalRange, 14);
#endif

#if defined HIGH_SPEED
  // reduce timing budget to 20 ms (default is about 33 ms)
  sensor.setMeasurementTimingBudget(20000);
#elif defined HIGH_ACCURACY
  // increase timing budget to 200 ms
  sensor.setMeasurementTimingBudget(200000);
#endif
}

We have the defaults for those parameters in the comments there. Our Readme.md file for the library has a little more detailed explanation of what changing those parameters does. You might also look at ST’s documentation for the sensor for more information about how those parameters affect the sensor’s measurement.

-Nathan

Thanks a lot @nathanb . Appreciate your concern. I am just using High accuracy profile in my code, so perhaps I don’t need to use if, elif, endif statements. I am trying to compile the code with just using high accuracy statement, and my setup code looks as following:

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

VL53L0X sensor;

Adafruit_VL53L0X lox = Adafruit_VL53L0X();

int pospulse = 11;
int negpulse = 12;
int clockwise = 7;
int anticlockwise = 8;


float sum = 0;

float  sensorvalue = 0;


void setup() {
  Serial.begin(115200);

  // wait until serial port opens for native USB devices
  while (! Serial) {
    delay(1);
  }

  Serial.println("Adafruit VL53L0X test");
  if (!lox.begin()) {
    Serial.println(F("Failed to boot VL53L0X"));
    while (1);
  }
  // power
  Serial.println(F("VL53L0X API Simple Ranging example\n\n"));

  sensor.setMeasurementTimingBudget(200000);
}

When I try to compile it says, “Error compiling for board Arduino/Genuino Mega or Mega 2560.”

I did the following way earlier and it worked (atleast that’s what I think!). However it did compile not sure it went exactly as I meant. The code is as follows:

#include "Adafruit_VL53L0X.h"
#include "Wire.h"


Adafruit_VL53L0X lox = Adafruit_VL53L0X();

int pospulse = 11;
int negpulse = 12;
int clockwise = 7;
int anticlockwise = 8;


float sum = 0;

float  sensorvalue = 0;


void setup() {
  Serial.begin(115200);

  // wait until serial port opens for native USB devices
  while (! Serial) {
    delay(1);
  }

  Serial.println("Adafruit VL53L0X test");
  if (!lox.begin()) {
    Serial.println(F("Failed to boot VL53L0X"));
    while (1);
  }
  // power
  Serial.println(F("VL53L0X API Simple Ranging example\n\n"));

  VL53L0X_DEV Dev;
  VL53L0X_SetMeasurementTimingBudgetMicroSeconds(Dev,200000);
}

Which way should I go? which way would give me results I want?
Thanks in advance

Hello.

Using two different libraries for the same sensor is not likely to work well. You should pick one of the two. Also, the IDE should return additional information below the error message you quoted that will have more details helpful for debugging.

-Nathan

The complete error is as such:

C:\Users\admin\Documents\Arduino\quardun__in_two\quardun__in_two.ino:3:21: fatal error: VL53L0X.h: No such file or directory

 #include <VL53L0X.h>
compilation terminated.

exit status 1
Error compiling for board Arduino/Genuino Mega or Mega 2560.

I’m finding trouble in writing the right code, can you help me with it?
What I basically want to do is set the High Accuracy mode with 200 ms timing budget.

It sounds like you might not have the library installed correctly. You can find instructions for installing the library under the “Software” heading here.

-Nathan

I’m already using adafruit library,would installing the library you mentioned in your comment be a good idea? using which statement can I set high accuracy mode for my sensor under adafruit library? Also I have verified that I have the right library installed.

I assumed you were using our carrier board for the VL53L0X and our library, but it seems like that is not the case. What board are you using? Our library is designed specifically to work with our carrier board, although it might still work for you if you are using Adafruit’s breakout or another board.

It is possible to change the ranging profile in our library as I mentioned, and you can look at our example sketch to see how it does this. If you want to keep using the Adafruit library, though, I recommend looking at their library documentation or contacting their support directly, since we do not know if it can do what you want.

-Nathan

I ordered it from rhydolabz, and it is your make. Here is the link from where I purchased.

I thought your library or adafruit’s library is applicable for all types of VL53LOX carrier boards. Anyways it appears that I am using adafruit’s library in your board, can that be a reason for problem? The distance measured by this sensor is in the ±5 mm of actual distance. Can setting the profile to high accuracy bring it down to 0.5 mm because that is the accuracy I need for my project.
To be honest, Adafruit’s code is little bit easy to understand than yours. But still I am more than willing to use your library and code for my project. can you give me the link to some of your examples where you have been using this sensor for continuous mode? Also I am not using long range for my project, I just need to measure distance up to 650 mm. In that case what signal rate limit should I set?

Adafruit’s library will probably work with our boards, but we cannot help you use it since we do not know if it is possible to use it to change the parameters we discussed earlier. It is possible to install our VL53L0x library in your IDE without breaking the Adafruit library, but you should only use one or the other in any sketch.

We have some examples including a continuous mode example sketch included with our library. You might try loading the library (using the instructions I mentioned above) and test the results from the example sketch with your sensor with target at a few known distances around 650 mm to see how it behaves. If you get poor results with the default sketch, we should be able to help you modify the sketch to see if it is possible to improve the results.

By the way, the resolution of the sensor’s measurements is only 1.0mm, so you will not be able to get down to 0.5mm without some kind of averaging of multiple measurements. It is not clear if getting 0.5mm accuracy from the sensor is practical.

-Nathan

would this code work?

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

VL53L0X sensor;
int pospulse = 11;
int negpulse = 12;
int clockwise = 7;
int anticlockwise = 8;


float sum = 0;

float  sensorvalue = 0;


void setup()
{
  Serial.begin(9600);
  Wire.begin();

  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();
  sensor.setMeasurementTimingBudget(200000);
}

You should call the setMeasurementTimingBudget() function before startContinuous(), but otherwise your code seems fine. You might do that, add some code to return values via the serial monitor (we have that in the examples), and then point the sensor at a target and check the results.

-Nathan

I am doing something like this to achieve better accuracy,

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

VL53L0X sensor;
int pospulse = 11;
int negpulse = 12;
int clockwise = 7;
int anticlockwise = 8;


float sum = 0;

float  sensorvalue = 0;


void setup()
{
  Serial.begin(9600);
  Wire.begin();

  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.setMeasurementTimingBudget(200000);
  sensor.startContinuous();

}

void loop()
{
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(clockwise, OUTPUT);
  pinMode(8, OUTPUT);




  float  arrayofreadings[20];
  for (int i = 0; i < 20; i++)
  {
    arrayofreadings[i] = sensor.readRangeContinuousMillimeters();
    if (sensor.timeoutOccurred()) {
      Serial.print(" TIMEOUT");
    }
    sum = sum + arrayofreadings[i];

    Serial.println(sum);
  }

  sensorvalue = sum  / 20;
  //sensorvalue = measure.RangeMilliMeter;
  Serial.println("sensorvalue = ");
  Serial.print(sensorvalue);
  Serial.println();

I am reading continuous values in millimeters from the sensor and adding them together to eventually find mean (mathematical). Is what am I doing correct?

When I examine this code practically it gives consistent readings but when it “fails to boot” (according to adafruit’s library) it gives constant reading of 17476 mm. I don’t know where did this come from and how to control this? I mean I have to stop execution of the code when such sort of error occurs and show some message on the serial monitor.

Hello, Dhruvan.

That code looks like it should work. We are not familiar with the “failure to boot” error or readings that are consistently 17476mm. Our library will return a reading of 8190 or 8191 if it does not get a strong enough return from the target. You might look at your individual measurements and discard any with those two values before you perform your averaging if you will be using the sensor in conditions where it is not likely to see your intended target. You might also check your electrical connections to the sensor to make sure they are not intermittent.

-Nathan

Thanks a lot Nathan, I guess I can carry on from here. Although I’ll get back to you if I need any further assistance. Once again, thanks for all your help.

I am getting a lot of fluctuations in readings from the sensor is there anyway I can make it constant?

Hello.

Can you post your latest code here?

-Nathan

#include <VL53L0X.h>

VL53L0X sensor;
int pospulse = 11;
int negpulse = 12;
int clockwise = 7;
int anticlockwise = 8;


float sum = 0;

float  sensorvalue = 0;


void setup()
{
  Serial.begin(9600);
  Wire.begin();

  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.setMeasurementTimingBudget(200000);
  sensor.startContinuous();

}

void loop()
{
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);




  float  arrayofreadings[20];
  for (int i = 0; i < 20; i++)
  {
    arrayofreadings[i] = sensor.readRangeContinuousMillimeters();
    if (sensor.timeoutOccurred()) {
      Serial.print(" TIMEOUT");
    }
    sum = sum + arrayofreadings[i];

    Serial.println(sum);
  }

  sensorvalue = sum  / 20;
  //sensorvalue = measure.RangeMilliMeter;
  Serial.println("sensorvalue = ");
  Serial.print(sensorvalue);
  Serial.println();

I’m taking an average of 20 readings still it isn’t correct one.

1 Like

What kind of variation do you currently see in the measurements and how long do you have to take your measurements? You might try using these following functions to increase the return signal rate limit and laser pulse periods:

  // set the return signal rate limit (default is 0.25 MCPS)
  sensor.setSignalRateLimit(0.25);
  // set laser pulse periods (defaults are 14 and 10 PCLKs)
  sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodPreRange, 14);
  sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodFinalRange, 10);

I am not certain those settings will help, but it seems like they might. They are discussed more in section 7 of the API User Manual ST provides.

-Nathan