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

VL53L0X fails PerformRefCalibration
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

VL53L0X fails PerformRefCalibration

by jerryn on Fri Dec 02, 2016 5:15 am

I am trying to test the VL53L0X on an Arduino Uno:
The example loads and runs but I always get a constant response.
I modified the example as below to enable "debug" and to print the return value.
It appears to be failing in VL53L0X_PerformRefCalibration.

Here is what I see in the terminal window:
Reading a measurement... Call of VL53L0X_StaticInit
Call of VL53L0X_PerformRefCalibration
result: -6
Distance (mm): 0

Note - I have seen values there than 0, but it is always constant once started.

Any suggestions?
Thanks


void loop() {
VL53L0X_RangingMeasurementData_t measure;
int8_t result;
Serial.print("Reading a measurement... ");
result=lox.rangingTest(&measure, true) ; // pass in 'true' to get debug data printout!
Serial.print(" result: ");
Serial.println(result);
if (measure.RangeStatus != 4) { // phase failures have incorrect data
Serial.print("Distance (mm): "); Serial.println(measure.RangeMilliMeter);
} else {
Serial.println(" out of range ");
}

delay(1000);
}

jerryn
 
Posts: 1314
Joined: Sat Sep 14, 2013 9:05 am

Re: VL53L0X fails PerformRefCalibration

by jerryn on Sat Dec 03, 2016 10:08 pm

I have had no success getting beyond this. Is it reasonable to conclude that the board damaged or defective?
I have tried several times using both the Arduino Uno and an AtmegaU34 Feather but get the same response of a constant measurement and
failed response to the RefCalibration. The -6 response appears to indicate a failure to determine the range during the calibration.
Please advise if I there are any tests I can run or if I should assume the board is damaged.

Thanks

jerryn
 
Posts: 1314
Joined: Sat Sep 14, 2013 9:05 am

Re: VL53L0X fails PerformRefCalibration

by franklin97355 on Sat Dec 03, 2016 11:10 pm

Can you post pictures of your soldering and connections? Make sure they are large and clear but less than 1 meg in size.

franklin97355
 
Posts: 21609
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: VL53L0X fails PerformRefCalibration

by jerryn on Sun Dec 04, 2016 7:07 am

Thank you for your help.
Here are the requested pictures of the soldering and connections.
the connections are 5V(red),GND(blue),SDA(orange),SCL(yellow)
IMG_2312.jpeg
vl53l0xsoldering2
IMG_2312.jpeg (67.94 KiB) Viewed 5987 times
IMG_2311.jpeg
vl53l0xsoldering1
IMG_2311.jpeg (65.25 KiB) Viewed 5987 times
IMG_2308.jpeg
vl53l0xconnect1
IMG_2308.jpeg (106.35 KiB) Viewed 5987 times

jerryn
 
Posts: 1314
Joined: Sat Sep 14, 2013 9:05 am

Re: VL53L0X fails PerformRefCalibration

by franklin97355 on Sun Dec 04, 2016 6:30 pm

Can you post you entire code? Please use [code] tags when posting code or logs to the forums by clicking the </> button above the reply box and pasting your code between the tags created.

franklin97355
 
Posts: 21609
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: VL53L0X fails PerformRefCalibration

by jerryn on Sun Dec 04, 2016 6:34 pm

Sure. This is the modified sketch.
Thanks

Code: Select all | TOGGLE FULL SIZE
#include "Adafruit_VL53L0X.h"

Adafruit_VL53L0X lox = Adafruit_VL53L0X();

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"));
}


void loop() {
  VL53L0X_RangingMeasurementData_t measure;
  int8_t result; 
  Serial.print("Reading a measurement... ");
  result=lox.rangingTest(&measure, true) ; // pass in 'true' to get debug data printout!
  Serial.print(" result: ");
  Serial.println(result);
  if (measure.RangeStatus != 4) {  // phase failures have incorrect data
    Serial.print("Distance (mm): "); Serial.println(measure.RangeMilliMeter);
  } else {
    Serial.println(" out of range ");
  }
   
  delay(1000);
}

jerryn
 
Posts: 1314
Joined: Sat Sep 14, 2013 9:05 am

Re: VL53L0X fails PerformRefCalibration

by adafruit2 on Sun Dec 04, 2016 9:27 pm

hmm can you try the Pololu library? not sure why but sometimes that works better than ours (we're using the official code so unsure why)
https://github.com/pololu/vl53l0x-arduino

adafruit2
Site Admin
 
Posts: 19399
Joined: Fri Mar 11, 2005 7:36 pm

Re: VL53L0X fails PerformRefCalibration

by jerryn on Sun Dec 04, 2016 10:08 pm

I did a quick try - just compiled loaded and ran both the "single" and "continuous" examples, but I see no output in the Serial Monitor. I did set the baud rate to 9600 as set in the examples. Is there more to running these?

I assume it is hanging somewhere waiting for a response that does not arrive.
I can try to dig into the code tomorrow to see where it is hanging up.

Any suggestions?

jerryn
 
Posts: 1314
Joined: Sat Sep 14, 2013 9:05 am

Re: VL53L0X fails PerformRefCalibration

by jerryn on Sun Dec 04, 2016 10:20 pm

A bit more information. I have been able to determine that it never returns from the call to sensor.init() ...

jerryn
 
Posts: 1314
Joined: Sat Sep 14, 2013 9:05 am

Re: VL53L0X fails PerformRefCalibration

by adafruit2 on Sun Dec 04, 2016 10:36 pm

try unplugging the arduino, and then re-plugging in - the sensor can get confused and needs a full power reset

adafruit2
Site Admin
 
Posts: 19399
Joined: Fri Mar 11, 2005 7:36 pm

Re: VL53L0X fails PerformRefCalibration

by jerryn on Mon Dec 05, 2016 6:17 am

Power cycling did enable it to return from sensor.init(). It now returns a constant reading of 8190.
I get the same response in the continuous or single example.
Thanks

jerryn
 
Posts: 1314
Joined: Sat Sep 14, 2013 9:05 am

Re: VL53L0X fails PerformRefCalibration

by jerryn on Mon Dec 05, 2016 6:28 am

Sorry - my error. T.he constant reading was only if I did not place anything in its path!!!
It does appear to be working now!
The 8190 appears to be an "out of range" response.
Nice to see it responding.

Just for "fun" I reloaded the AdaFruit example and it failed as before and had to be power cycled to resume operation with the poll example.

Thanks for your help - I'll dig into it to see I I can find out what is going wrong on the Adafruit example.

jerryn
 
Posts: 1314
Joined: Sat Sep 14, 2013 9:05 am

Re: VL53L0X fails PerformRefCalibration

by jerryn on Mon Dec 05, 2016 6:31 am

The "spell-checker" got me again. Just to be clear. The pololu example works. The Adafruit example causes it to fail and it requires a power cycle to function again with the pololu example.

jerryn
 
Posts: 1314
Joined: Sat Sep 14, 2013 9:05 am

Re: VL53L0X fails PerformRefCalibration

by adafruit2 on Mon Dec 05, 2016 1:22 pm

weird because we're using the official firmware - but glad you got it working :)

adafruit2
Site Admin
 
Posts: 19399
Joined: Fri Mar 11, 2005 7:36 pm

Re: VL53L0X fails PerformRefCalibration

by jerryn on Mon Dec 05, 2016 9:23 pm

hmm - I think I found it.
According to the API the call to PerformRefSpadManagement must come before the call to PerformRefCalibration.
Here is a link to the API - see step 2.4.1 (it was confusing, but I think after several reading, this is the correct order for the steps!)
http://www.st.com/content/ccc/resource/ ... 279088.pdf

I modified Adafruit_VL53L0X.cpp to swap the calls in rangingtest and it now works!!

In the Pololu code, they have reworked this to apparently use some stored values but it appears that it it is OK to repeat this calibration bu they do do the Spad management before the RefCalibration as well.

here is the modified file:
Code: Select all | TOGGLE FULL SIZE
#include "Adafruit_VL53L0X.h"

#define VERSION_REQUIRED_MAJOR 1
#define VERSION_REQUIRED_MINOR 0
#define VERSION_REQUIRED_BUILD 1
#define STR_HELPER(x) #x
#define STR(x) STR_HELPER(x)


boolean Adafruit_VL53L0X::begin(void) {
  int32_t status_int;
  int32_t init_done = 0;

  // Initialize Comms
  pMyDevice->I2cDevAddr      = 0x29;  // 7 bit addr
  pMyDevice->comms_type      =  1;
  pMyDevice->comms_speed_khz =  400;

 
  Wire.begin();  // VL53L0X_i2c_init();

  // unclear if this is even needed:
  if( VL53L0X_IMPLEMENTATION_VER_MAJOR != VERSION_REQUIRED_MAJOR ||
      VL53L0X_IMPLEMENTATION_VER_MINOR != VERSION_REQUIRED_MINOR ||
      VL53L0X_IMPLEMENTATION_VER_SUB != VERSION_REQUIRED_BUILD )  {

    Serial.println(F("Found " STR(VL53L0X_IMPLEMENTATION_VER_MAJOR) "." STR(VL53L0X_IMPLEMENTATION_VER_MINOR) "."  STR(VL53L0X_IMPLEMENTATION_VER_SUB) " rev " STR(VL53L0X_IMPLEMENTATION_VER_REVISION)));
    Serial.println(F("Requires " STR(VERSION_REQUIRED_MAJOR) "." STR(VERSION_REQUIRED_MINOR) "." STR(VERSION_REQUIRED_BUILD)));
    return false;
  }

  Status = VL53L0X_DataInit(&MyDevice); // Data initialization

  Status = VL53L0X_GetDeviceInfo(&MyDevice, &DeviceInfo);
  if (Status != VL53L0X_ERROR_NONE)
    return false;

  if(Status == VL53L0X_ERROR_NONE)  {
  /*
     Serial.println(F("VL53L0X_GetDeviceInfo:"));
     Serial.print(F("Device Name : ")); Serial.println(DeviceInfo.Name);
     Serial.print(F("Device Type : ")); Serial.println(DeviceInfo.Type);
     Serial.print(F("Device ID : ")); Serial.println(DeviceInfo.ProductId);
     Serial.print(F("ProductRevisionMajor : ")); Serial.println(DeviceInfo.ProductRevisionMajor);
     Serial.print(F("ProductRevisionMinor : ")); Serial.println(DeviceInfo.ProductRevisionMinor);
  */
     if ((DeviceInfo.ProductRevisionMinor != 1) && (DeviceInfo.ProductRevisionMinor != 1)) {
       /*
       Serial.print(F("Error expected cut 1.1 but found cut "));
       Serial.print(DeviceInfo.ProductRevisionMajor);
       Serial.print('.');
       Serial.println(DeviceInfo.ProductRevisionMinor);
       */
       Status = VL53L0X_ERROR_NOT_SUPPORTED;
       return false;     
     }
  }
  return true;
}


VL53L0X_Error Adafruit_VL53L0X::rangingTest(VL53L0X_RangingMeasurementData_t *RangingMeasurementData, boolean debug = false)
{
    VL53L0X_Error Status = VL53L0X_ERROR_NONE;
    int i;
    FixPoint1616_t LimitCheckCurrent;
    uint32_t refSpadCount;
    uint8_t isApertureSpads;
    uint8_t VhvSettings;
    uint8_t PhaseCal;

    if(Status == VL53L0X_ERROR_NONE)
    {
      if (debug)
   Serial.println(F("Call of VL53L0X_StaticInit"));
      Status = VL53L0X_StaticInit(pMyDevice); // Device Initialization
    }
   
    if(Status == VL53L0X_ERROR_NONE)
    {
      if (debug)
        Serial.println(F("Call of VL53L0X_PerformRefSpadManagement"));
      Status = VL53L0X_PerformRefSpadManagement(pMyDevice,
            &refSpadCount, &isApertureSpads); // Device Initialization
      if (debug) {
   Serial.print(F("refSpadCount = "));
        Serial.print(refSpadCount);
        Serial.print(F(", isApertureSpads = "));
        Serial.println(isApertureSpads);
      }
    }


    if(Status == VL53L0X_ERROR_NONE)
    {
      if (debug)
        Serial.println(F("Call of VL53L0X_PerformRefCalibration"));
      Status = VL53L0X_PerformRefCalibration(pMyDevice,
      &VhvSettings, &PhaseCal); // Device Initialization
    }

    if(Status == VL53L0X_ERROR_NONE)
    {
        // no need to do this when we use VL53L0X_PerformSingleRangingMeasurement
      if (debug)
        Serial.println(F("Call of VL53L0X_SetDeviceMode"));
      Status = VL53L0X_SetDeviceMode(pMyDevice, VL53L0X_DEVICEMODE_SINGLE_RANGING); // Setup in single ranging mode
    }

    // Enable/Disable Sigma and Signal check
    if (Status == VL53L0X_ERROR_NONE) {
        Status = VL53L0X_SetLimitCheckEnable(pMyDevice,
            VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE, 1);
    }
    if (Status == VL53L0X_ERROR_NONE) {
        Status = VL53L0X_SetLimitCheckEnable(pMyDevice,
            VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE, 1);
    }

    if (Status == VL53L0X_ERROR_NONE) {
        Status = VL53L0X_SetLimitCheckEnable(pMyDevice,
            VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD, 1);
    }

    if (Status == VL53L0X_ERROR_NONE) {
        Status = VL53L0X_SetLimitCheckValue(pMyDevice,
            VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD,
            (FixPoint1616_t)(1.5*0.023*65536));
    }


    /*
     *  Step  4 : Test ranging mode
     */

    if(Status == VL53L0X_ERROR_NONE)
    {
      if (debug)
   Serial.println(F("Call of VL53L0X_PerformSingleRangingMeasurement"));
      Status = VL53L0X_PerformSingleRangingMeasurement(pMyDevice,
                         RangingMeasurementData);
     
      if (debug)
   print_range_status(RangingMeasurementData);
     
      VL53L0X_GetLimitCheckCurrent(pMyDevice,
               VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD, &LimitCheckCurrent);
     
      if (debug) {
   Serial.print(F("RANGE IGNORE THRESHOLD: "));
   Serial.println((float)LimitCheckCurrent/65536.0);
   
   Serial.print(F("Measured distance: "));
   Serial.println(RangingMeasurementData->RangeMilliMeter);
      }
    }
    return Status;
}




void Adafruit_VL53L0X::print_range_status(VL53L0X_RangingMeasurementData_t* pRangingMeasurementData){
    char buf[VL53L0X_MAX_STRING_LENGTH];
    uint8_t RangeStatus;

    /*
     * New Range Status: data is valid when pRangingMeasurementData->RangeStatus = 0
     */

    RangeStatus = pRangingMeasurementData->RangeStatus;

    VL53L0X_GetRangeStatusString(RangeStatus, buf);
    Serial.print(F("Range Status: "));
    Serial.print(RangeStatus);
    Serial.print(" : ");
    Serial.println(buf);

}

jerryn
 
Posts: 1314
Joined: Sat Sep 14, 2013 9:05 am

Please be positive and constructive with your questions and comments.