HCVL53L0X - Library for LV530X range sensor (HCMODU0127)

Useful guides, libraries, and example sketches to support our Arduino based products.
Post Reply
admin
Site Admin
Posts: 725
Joined: Sun Aug 05, 2012 4:02 pm

HCVL53L0X - Library for LV530X range sensor (HCMODU0127)

Post by admin » Thu Feb 15, 2018 1:31 pm

Image





Arduino library for the VL53L0X TOF laser ranging sensor.
Products currently supported by this library:

VL53L0X TOF laser ranging sensor module (SKU: HCMODU0127)
available from hobbycomponents.com


You will need to download (please log in to download the library) and unzip this library to the Arduino development environments library area.

On Windows:
My Documents\Arduino\libraries\

On Mac:
Documents/Arduino/libraries/

Linux:
Usually found within the users home area under /Arduino/libraries/




Using the HCVL53L0X library

To use the library just include the HCVL53L0X.h header file and then create an instance of the library. E.g:

Code: Select all

#include <HCVL53L0X .h>
HCVL53L0X HCVL53L0X(I2C_ADD);

Where I2C_Add is the I2C address of the AM2315.


To initialise the library add the following line to the setup() section of your sketch:

Code: Select all

HCVL53L0X.init();



The following functions are available with this library:



VL53L0X_Error HCVL53L0X.measure(void)

Performs a single sensor measurement.

Returns an error code of type VL53L0X_Error (see error code section for a list of returned error codes)


Example:

Code: Select all

HCVL53L0X.measure();


uint16_t HCVL53L0X.rangeMilliMeter(void)

Gets the latest distance measurement. HCVL53L0X.measure() must be run to update this value.

Returns a 16 bit value of type uint16_t containing the distance measurement in millimeters.


Example:

Code: Select all

uint16_t Result = HCVL53L0X.rangeMilliMeter();



FixPoint1616_t HCVL53L0X.reflectance(void)

Gets the target reflectance measurement. HCVL53L0X.measure() must be run to update this value.

Returns a 16.16 fix point value of type FixPoint1616_t (uint32_t) containing the target reflectance.


Example:

Code: Select all

uint32_t Result = HCVL53L0X.reflectance();




FixPoint1616_t HCVL53L0X.ambientLight(void)

Gets the measurement of the ambient light. HCVL53L0X.measure() must be run to update this value.

Returns a 16.16 fix point value of type FixPoint1616_t (uint32_t) containing the ambient light measurement.


Example:

Code: Select all

uint32_t Result = HCVL53L0X.ambientLight();



uint8_t HCVL53L0X.spadRtnCount(void)

Gets the effective SPAD count for the return signal. HCVL53L0X.measure() must be run to update this value.

Returns a byte value of type uint8_t containing the effective SPAD count.

Example:

Code: Select all

uint8_t Result = HCVL53L0X.spadRtnCount();



uint8_t HCVL53L0X.rangeStatus(void)

Gets the range status for the last measurement. HCVL53L0X.measure() must be run to update this value.

Returns a byte value of type uint8_t containing the status of the last measurement where:
0 = Last measurement was valid
1 = Sigma Fail
2 = Signal Fail
3 = Min Range Fail
4 = Phase Fail
5 = HardWare Fail
255 = None

Example:

Code: Select all

uint8_t Result = HCVL53L0X.rangeStatus();



Image

Code: Select all

/* FILE:    HCVL53L0X_Example
   DATE:    15/02/18
   VERSION: 0.1
   AUTHOR:  Andrew Davies
   
15/02/18 version 0.1: Original version

This example sketch uses the HCVL53L0X library to read distance measurements from
the VL53L0X TOF laser ranging sensor. The sketch repeatedly reads the sensor once a 
second and outputs the result to the serial UART. 

Hobby Components (HobbyComponents.com) products currently supported by this library:

VL53L0X TOF laser ranging sensor module  (SKU: HCMODU0127) 

More information about the library can be found in the software section of our support 
forum here:

http://forum.hobbycomponents.com/software

You may copy, alter and reuse this code in any way you like, but please leave
reference to HobbyComponents.com in your comments if you redistribute this code.
This software may not be used directly for the purpose of selling products that
directly compete with Hobby Components Ltd's own range of products.
THIS SOFTWARE IS PROVIDED "AS IS". HOBBY COMPONENTS MAKES NO WARRANTIES, WHETHER
EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR LACK OF NEGLIGENCE.
HOBBY COMPONENTS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR ANY DAMAGES,
INCLUDING, BUT NOT LIMITED TO, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
REASON WHATSOEVER.
*/


#include "HCVL53L0X.h"      //Include the HCVL53L0X library.

#define I2CADD 0x29         //I2C address of the VL53L0X


HCVL53L0X HCVL53L0X;        //Create an instance of the library.

void setup() 
{
  Serial.begin(9600);       //Initialise the Arduino serial library.

  VL53L0X_Error error = HCVL53L0X.init(I2CADD); //Initiliase the library.
  
  if (error != VL53L0X_ERROR_NONE)
  {
    Serial.print("Error: ");
    Serial.println(error);
  }
}


void loop() 
{
  //Trigger a new range measurement.
  VL53L0X_Error error = HCVL53L0X.measure();

  //Check for an error.
  if (error != VL53L0X_ERROR_NONE)
  {
    Serial.print("Error: ");
    Serial.println(error);
  }else //If data is valid then print out results
  {
    Serial.print("Range (mm): "); 
    Serial.println(HCVL53L0X.rangeMilliMeter());
    
    Serial.print("Reflectance: "); 
    Serial.println(HCVL53L0X.reflectance());
    
    Serial.print("Ambient light: "); 
    Serial.println(HCVL53L0X.ambientLight());
    
    Serial.print("Spad return count: ");
    Serial.println(HCVL53L0X.spadRtnCount());
    
    //Print status of the last measurement
    Serial.print("Range status: ");
    
    if(HCVL53L0X.rangeStatus() == 0)
      Serial.println("Valid");
    else if(HCVL53L0X.rangeStatus() == 4)
      Serial.println("Out of range");
    else
      Serial.println("Error: ");
  
    Serial.println(); 
  }

  //Wait a second before taking another measurement.
  delay(1000);
}



Image
HCVL53L0X.zip


Diagrams, libraries, and example code are provided as an additional free service by Hobby Components and are not sold as part of this product. We do no provide any guarantees or warranties as to their accuracy or fitness for purpose.

Descriptions and diagrams on this page are copyright Hobby Components Ltd and may not be reproduced without permission.
You do not have the required permissions to view the files attached to this post.

Post Reply