Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: X_NUCLEO_COMMON ST_INTERFACES
VL53L1X Class Reference
Class representing a VL53L1 sensor component. More...
#include <vl53l1x_class.h>
Public Member Functions | |
VL53L1X (vl53L1X_DevI2C *i2c, DigitalOut *pin, PinName pin_gpio1, uint8_t dev_addr=VL53L1X_DEFAULT_DEVICE_ADDRESS) | |
Constructor. | |
VL53L1X (vl53L1X_DevI2C *i2c, Stmpe1600DigiOut *pin, PinName pin_gpio1, uint8_t dev_addr=VL53L1X_DEFAULT_DEVICE_ADDRESS) | |
Constructor 2 (STMPE1600DigiOut) | |
virtual | ~VL53L1X () |
Destructor. | |
virtual void | VL53L1_On (void) |
PowerOn the sensor. | |
virtual void | VL53L1_Off (void) |
PowerOff the sensor. | |
VL53L1X_ERROR | InitSensor (uint8_t address) |
Initialize the sensor with default values. | |
virtual int | init (void *init) |
One time device initialization. | |
int | init_sensor (uint8_t new_addr) |
Initialize the sensor with default values. | |
int | handle_irq (uint16_t *distance) |
Interrupt handling func to be called by user after an INT is occurred. | |
int | start_measurement (void(*fptr)(void)) |
Start the measure indicated by operating mode. | |
int | stop_measurement () |
Stop the currently running measure indicate by operating_mode. | |
int | get_measurement (uint16_t *distance) |
Get results for the measure. | |
void | enable_interrupt_measure_detection_irq (void) |
Enable interrupt measure IRQ. | |
void | disable_interrupt_measure_detection_irq (void) |
Disable interrupt measure IRQ. | |
void | attach_interrupt_measure_detection_irq (void(*fptr)(void)) |
Attach a function to call when an interrupt is detected, i.e. | |
virtual int | get_distance (uint32_t *piData) |
Get ranging result and only that. | |
VL53L1X_ERROR | VL53L1X_GetSWVersion (VL53L1X_Version_t *pVersion) |
This function returns the SW driver version. | |
VL53L1X_ERROR | VL53L1X_SetI2CAddress (uint8_t new_address) |
This function sets the sensor I2C address used in case multiple devices application, default address 0x52. | |
VL53L1X_ERROR | VL53L1X_SensorInit () |
This function loads the 135 bytes default values to initialize the sensor. | |
VL53L1X_ERROR | VL53L1X_ClearInterrupt () |
This function clears the interrupt, to be called after a ranging data reading to arm the interrupt for the next data ready event. | |
VL53L1X_ERROR | VL53L1X_SetInterruptPolarity (uint8_t IntPol) |
This function programs the interrupt polarity 1=active high (default), 0=active low. | |
VL53L1X_ERROR | VL53L1X_GetInterruptPolarity (uint8_t *pIntPol) |
This function returns the current interrupt polarity 1=active high (default), 0=active low. | |
VL53L1X_ERROR | VL53L1X_StartRanging () |
This function starts the ranging distance operation The ranging operation is continuous. | |
VL53L1X_ERROR | VL53L1X_StopRanging () |
This function stops the ranging. | |
VL53L1X_ERROR | VL53L1X_CheckForDataReady (uint8_t *isDataReady) |
This function checks if the new ranging data is available by polling the dedicated register. | |
VL53L1X_ERROR | VL53L1X_SetTimingBudgetInMs (uint16_t TimingBudgetInMs) |
This function programs the timing budget in ms. | |
VL53L1X_ERROR | VL53L1X_GetTimingBudgetInMs (uint16_t *pTimingBudgetInMs) |
This function returns the current timing budget in ms. | |
VL53L1X_ERROR | VL53L1X_SetDistanceMode (uint16_t DistanceMode) |
This function programs the distance mode (1=short, 2=long(default)). | |
VL53L1X_ERROR | VL53L1X_GetDistanceMode (uint16_t *pDistanceMode) |
This function returns the current distance mode (1=short, 2=long). | |
VL53L1X_ERROR | VL53L1X_SetInterMeasurementInMs (uint16_t InterMeasurementInMs) |
This function programs the Intermeasurement period in ms Intermeasurement period must be >/= timing budget. | |
VL53L1X_ERROR | VL53L1X_GetInterMeasurementInMs (uint16_t *pIM) |
This function returns the Intermeasurement period in ms. | |
VL53L1X_ERROR | VL53L1X_BootState (uint8_t *state) |
This function returns the boot state of the device (1:booted, 0:not booted) | |
VL53L1X_ERROR | VL53L1X_GetSensorId (uint16_t *id) |
This function returns the sensor id, sensor Id must be 0xEEAC. | |
VL53L1X_ERROR | VL53L1X_GetDistance (uint16_t *distance) |
This function returns the distance measured by the sensor in mm. | |
VL53L1X_ERROR | VL53L1X_GetSignalPerSpad (uint16_t *signalPerSp) |
This function returns the returned signal per SPAD in kcps/SPAD. | |
VL53L1X_ERROR | VL53L1X_GetAmbientPerSpad (uint16_t *amb) |
This function returns the ambient per SPAD in kcps/SPAD. | |
VL53L1X_ERROR | VL53L1X_GetSignalRate (uint16_t *signalRate) |
This function returns the returned signal in kcps. | |
VL53L1X_ERROR | VL53L1X_GetSpadNb (uint16_t *spNb) |
This function returns the current number of enabled SPADs. | |
VL53L1X_ERROR | VL53L1X_GetAmbientRate (uint16_t *ambRate) |
This function returns the ambient rate in kcps. | |
VL53L1X_ERROR | VL53L1X_GetRangeStatus (uint8_t *rangeStatus) |
This function returns the ranging status error (0:no error, 1:sigma failed, 2:signal failed, ..., 7:wrap-around) | |
VL53L1X_ERROR | VL53L1X_SetOffset (int16_t OffsetValue) |
This function programs the offset correction in mm. | |
VL53L1X_ERROR | VL53L1X_GetOffset (int16_t *Offset) |
This function returns the programmed offset correction value in mm. | |
VL53L1X_ERROR | VL53L1X_SetXtalk (uint16_t XtalkValue) |
This function programs the xtalk correction value in cps (Count Per Second). | |
VL53L1X_ERROR | VL53L1X_GetXtalk (uint16_t *Xtalk) |
This function returns the current programmed xtalk correction value in cps. | |
VL53L1X_ERROR | VL53L1X_SetDistanceThreshold (uint16_t ThreshLow, uint16_t ThreshHigh, uint8_t Window, uint8_t IntOnNoTarget) |
This function programs the threshold detection mode Example: VL53L1X_SetDistanceThreshold(dev,100,300,0,1): Below 100 VL53L1X_SetDistanceThreshold(dev,100,300,1,1): Above 300 VL53L1X_SetDistanceThreshold(dev,100,300,2,1): Out of window VL53L1X_SetDistanceThreshold(dev,100,300,3,1): In window . | |
VL53L1X_ERROR | VL53L1X_GetDistanceThresholdWindow (uint16_t *window) |
This function returns the window detection mode (0=below; 1=above; 2=out; 3=in) | |
VL53L1X_ERROR | VL53L1X_GetDistanceThresholdLow (uint16_t *low) |
This function returns the low threshold in mm. | |
VL53L1X_ERROR | VL53L1X_GetDistanceThresholdHigh (uint16_t *high) |
This function returns the high threshold in mm. | |
VL53L1X_ERROR | VL53L1X_SetROI (uint16_t X, uint16_t Y) |
This function programs the ROI (Region of Interest) The ROI position is centered, only the ROI size can be reprogrammed. | |
VL53L1X_ERROR | VL53L1X_GetROI_XY (uint16_t *ROI_X, uint16_t *ROI_Y) |
This function returns width X and height Y. | |
VL53L1X_ERROR | VL53L1X_SetSignalThreshold (uint16_t signal) |
This function programs a new signal threshold in kcps (default=1024 kcps . | |
VL53L1X_ERROR | VL53L1X_GetSignalThreshold (uint16_t *signal) |
This function returns the current signal threshold in kcps. | |
VL53L1X_ERROR | VL53L1X_SetSigmaThreshold (uint16_t sigma) |
This function programs a new sigma threshold in mm (default=15 mm) | |
VL53L1X_ERROR | VL53L1X_GetSigmaThreshold (uint16_t *signal) |
This function returns the current sigma threshold in mm. | |
VL53L1X_ERROR | VL53L1X_StartTemperatureUpdate () |
This function performs the temperature calibration. | |
int8_t | VL53L1X_CalibrateOffset (uint16_t TargetDistInMm, int16_t *offset) |
This function performs the offset calibration. | |
int8_t | VL53L1X_CalibrateXtalk (uint16_t TargetDistInMm, uint16_t *xtalk) |
This function performs the xtalk calibration. |
Detailed Description
Class representing a VL53L1 sensor component.
Definition at line 136 of file vl53l1x_class.h.
Constructor & Destructor Documentation
VL53L1X | ( | vl53L1X_DevI2C * | i2c, |
DigitalOut * | pin, | ||
PinName | pin_gpio1, | ||
uint8_t | dev_addr = VL53L1X_DEFAULT_DEVICE_ADDRESS |
||
) |
Constructor.
- Parameters:
-
[in] &i2c device I2C to be used for communication [in] &pin_gpio1 pin Mbed InterruptIn PinName to be used as component GPIO_1 INT [in] DevAddr device address, 0x52 by default
Definition at line 144 of file vl53l1x_class.h.
VL53L1X | ( | vl53L1X_DevI2C * | i2c, |
Stmpe1600DigiOut * | pin, | ||
PinName | pin_gpio1, | ||
uint8_t | dev_addr = VL53L1X_DEFAULT_DEVICE_ADDRESS |
||
) |
Constructor 2 (STMPE1600DigiOut)
- Parameters:
-
[in] i2c device I2C to be used for communication [in] &pin Gpio Expander STMPE1600DigiOut pin to be used as component GPIO_0 CE [in] pin_gpio1 pin Mbed InterruptIn PinName to be used as component GPIO_1 INT [in] device address, 0x29 by default
Definition at line 164 of file vl53l1x_class.h.
virtual ~VL53L1X | ( | ) | [virtual] |
Destructor.
Definition at line 181 of file vl53l1x_class.h.
Member Function Documentation
void attach_interrupt_measure_detection_irq | ( | void(*)(void) | fptr ) |
Attach a function to call when an interrupt is detected, i.e.
measurement is ready
- Parameters:
-
[in] fptr pointer to call back function to be called whenever an interrupt occours
- Returns:
- 0 on Success
Definition at line 367 of file vl53l1x_class.h.
void disable_interrupt_measure_detection_irq | ( | void | ) |
void enable_interrupt_measure_detection_irq | ( | void | ) |
virtual int get_distance | ( | uint32_t * | piData ) | [virtual] |
Get ranging result and only that.
- Parameters:
-
pRange_mm Pointer to range distance
- Returns:
- 0 on success
Definition at line 377 of file vl53l1x_class.h.
int get_measurement | ( | uint16_t * | distance ) |
Get results for the measure.
- Parameters:
-
[out] Data pointer to the distance_data to read data in to
- Returns:
- 0 on Success
Definition at line 1069 of file vl53l1x_class.cpp.
int handle_irq | ( | uint16_t * | distance ) |
Interrupt handling func to be called by user after an INT is occurred.
- Parameters:
-
[out] Data pointer to the distance to read data in to
- Returns:
- 0 on Success
Definition at line 1061 of file vl53l1x_class.cpp.
virtual int init | ( | void * | init ) | [virtual] |
One time device initialization.
- Parameters:
-
void
- Returns:
- 0 on success, CALIBRATION_WARNING if failed
Definition at line 278 of file vl53l1x_class.h.
int init_sensor | ( | uint8_t | new_addr ) |
Initialize the sensor with default values.
- Returns:
- "0" on success
Definition at line 70 of file vl53l1x_class.cpp.
VL53L1X_ERROR InitSensor | ( | uint8_t | address ) |
Initialize the sensor with default values.
- Returns:
- 0 on Success
Definition at line 251 of file vl53l1x_class.h.
int start_measurement | ( | void(*)(void) | fptr ) |
Start the measure indicated by operating mode.
- Parameters:
-
[in] fptr specifies call back function must be !NULL in case of interrupt measure
- Returns:
- 0 on Success
Definition at line 1079 of file vl53l1x_class.cpp.
int stop_measurement | ( | ) |
Stop the currently running measure indicate by operating_mode.
- Returns:
- 0 on Success
Definition at line 1102 of file vl53l1x_class.cpp.
virtual void VL53L1_Off | ( | void | ) | [virtual] |
virtual void VL53L1_On | ( | void | ) | [virtual] |
VL53L1X_ERROR VL53L1X_BootState | ( | uint8_t * | state ) |
This function returns the boot state of the device (1:booted, 0:not booted)
Definition at line 411 of file vl53l1x_class.cpp.
int8_t VL53L1X_CalibrateOffset | ( | uint16_t | TargetDistInMm, |
int16_t * | offset | ||
) |
This function performs the offset calibration.
The function returns the offset value found and programs the offset compensation into the device.
- Parameters:
-
TargetDistInMm target distance in mm, ST recommended 100 mm Target reflectance = grey17%
- Returns:
- 0:success, !=0: failed
- offset pointer contains the offset found in mm
Definition at line 760 of file vl53l1x_class.cpp.
int8_t VL53L1X_CalibrateXtalk | ( | uint16_t | TargetDistInMm, |
uint16_t * | xtalk | ||
) |
This function performs the xtalk calibration.
The function returns the xtalk value found and programs the xtalk compensation to the device
- Parameters:
-
TargetDistInMm target distance in mm
The target distance : the distance where the sensor start to "under range"
due to the influence of the photons reflected back from the cover glass becoming strong
It's also called inflection point
Target reflectance = grey 17%
- Returns:
- 0: success, !=0: failed
- xtalk pointer contains the xtalk value found in cps (number of photons in count per second)
Definition at line 788 of file vl53l1x_class.cpp.
VL53L1X_ERROR VL53L1X_CheckForDataReady | ( | uint8_t * | isDataReady ) |
This function checks if the new ranging data is available by polling the dedicated register.
- Parameters:
-
: isDataReady==0 -> not ready; isDataReady==1 -> ready
Definition at line 170 of file vl53l1x_class.cpp.
VL53L1X_ERROR VL53L1X_ClearInterrupt | ( | ) |
This function clears the interrupt, to be called after a ranging data reading to arm the interrupt for the next data ready event.
Definition at line 117 of file vl53l1x_class.cpp.
VL53L1X_ERROR VL53L1X_GetAmbientPerSpad | ( | uint16_t * | amb ) |
This function returns the ambient per SPAD in kcps/SPAD.
Definition at line 458 of file vl53l1x_class.cpp.
VL53L1X_ERROR VL53L1X_GetAmbientRate | ( | uint16_t * | ambRate ) |
This function returns the ambient rate in kcps.
Definition at line 494 of file vl53l1x_class.cpp.
VL53L1X_ERROR VL53L1X_GetDistance | ( | uint16_t * | distance ) |
This function returns the distance measured by the sensor in mm.
Definition at line 433 of file vl53l1x_class.cpp.
VL53L1X_ERROR VL53L1X_GetDistanceMode | ( | uint16_t * | pDistanceMode ) |
This function returns the current distance mode (1=short, 2=long).
Definition at line 368 of file vl53l1x_class.cpp.
VL53L1X_ERROR VL53L1X_GetDistanceThresholdHigh | ( | uint16_t * | high ) |
This function returns the high threshold in mm.
Definition at line 656 of file vl53l1x_class.cpp.
VL53L1X_ERROR VL53L1X_GetDistanceThresholdLow | ( | uint16_t * | low ) |
This function returns the low threshold in mm.
Definition at line 646 of file vl53l1x_class.cpp.
VL53L1X_ERROR VL53L1X_GetDistanceThresholdWindow | ( | uint16_t * | window ) |
This function returns the window detection mode (0=below; 1=above; 2=out; 3=in)
Definition at line 636 of file vl53l1x_class.cpp.
VL53L1X_ERROR VL53L1X_GetInterMeasurementInMs | ( | uint16_t * | pIM ) |
This function returns the Intermeasurement period in ms.
Definition at line 396 of file vl53l1x_class.cpp.
VL53L1X_ERROR VL53L1X_GetInterruptPolarity | ( | uint8_t * | pIntPol ) |
This function returns the current interrupt polarity
1=active high (default), 0=active low.
Definition at line 139 of file vl53l1x_class.cpp.
VL53L1X_ERROR VL53L1X_GetOffset | ( | int16_t * | Offset ) |
This function returns the programmed offset correction value in mm.
Definition at line 575 of file vl53l1x_class.cpp.
VL53L1X_ERROR VL53L1X_GetRangeStatus | ( | uint8_t * | rangeStatus ) |
This function returns the ranging status error
(0:no error, 1:sigma failed, 2:signal failed, ..., 7:wrap-around)
Definition at line 505 of file vl53l1x_class.cpp.
VL53L1X_ERROR VL53L1X_GetROI_XY | ( | uint16_t * | ROI_X, |
uint16_t * | ROI_Y | ||
) |
This function returns width X and height Y.
Definition at line 685 of file vl53l1x_class.cpp.
VL53L1X_ERROR VL53L1X_GetSensorId | ( | uint16_t * | id ) |
This function returns the sensor id, sensor Id must be 0xEEAC.
Definition at line 422 of file vl53l1x_class.cpp.
VL53L1X_ERROR VL53L1X_GetSigmaThreshold | ( | uint16_t * | signal ) |
This function returns the current sigma threshold in mm.
Definition at line 728 of file vl53l1x_class.cpp.
VL53L1X_ERROR VL53L1X_GetSignalPerSpad | ( | uint16_t * | signalPerSp ) |
This function returns the returned signal per SPAD in kcps/SPAD.
With kcps stands for Kilo Count Per Second
Definition at line 444 of file vl53l1x_class.cpp.
VL53L1X_ERROR VL53L1X_GetSignalRate | ( | uint16_t * | signalRate ) |
This function returns the returned signal in kcps.
Definition at line 470 of file vl53l1x_class.cpp.
VL53L1X_ERROR VL53L1X_GetSignalThreshold | ( | uint16_t * | signal ) |
This function returns the current signal threshold in kcps.
Definition at line 704 of file vl53l1x_class.cpp.
VL53L1X_ERROR VL53L1X_GetSpadNb | ( | uint16_t * | spNb ) |
This function returns the current number of enabled SPADs.
Definition at line 482 of file vl53l1x_class.cpp.
VL53L1X_ERROR VL53L1X_GetSWVersion | ( | VL53L1X_Version_t * | pVersion ) |
This function returns the SW driver version.
Definition at line 50 of file vl53l1x_class.cpp.
VL53L1X_ERROR VL53L1X_GetTimingBudgetInMs | ( | uint16_t * | pTimingBudgetInMs ) |
This function returns the current timing budget in ms.
Definition at line 291 of file vl53l1x_class.cpp.
VL53L1X_ERROR VL53L1X_GetXtalk | ( | uint16_t * | Xtalk ) |
This function returns the current programmed xtalk correction value in cps.
Definition at line 603 of file vl53l1x_class.cpp.
VL53L1X_ERROR VL53L1X_SensorInit | ( | ) |
This function loads the 135 bytes default values to initialize the sensor.
- Parameters:
-
dev Device address
- Returns:
- 0:success, != 0:failed
Definition at line 86 of file vl53l1x_class.cpp.
VL53L1X_ERROR VL53L1X_SetDistanceMode | ( | uint16_t | DistanceMode ) |
This function programs the distance mode (1=short, 2=long(default)).
Short mode max distance is limited to 1.3 m but better ambient immunity.
Long mode can range up to 4 m in the dark with 200 ms timing budget.
Definition at line 333 of file vl53l1x_class.cpp.
VL53L1X_ERROR VL53L1X_SetDistanceThreshold | ( | uint16_t | ThreshLow, |
uint16_t | ThreshHigh, | ||
uint8_t | Window, | ||
uint8_t | IntOnNoTarget | ||
) |
This function programs the threshold detection mode
Example:
VL53L1X_SetDistanceThreshold(dev,100,300,0,1): Below 100
VL53L1X_SetDistanceThreshold(dev,100,300,1,1): Above 300
VL53L1X_SetDistanceThreshold(dev,100,300,2,1): Out of window
VL53L1X_SetDistanceThreshold(dev,100,300,3,1): In window
.
- Parameters:
-
dev : device address ThreshLow(in mm) : the threshold under which one the device raises an interrupt if Window = 0 ThreshHigh(in mm) : the threshold above which one the device raises an interrupt if Window = 1 Window detection mode : 0=below, 1=above, 2=out, 3=in IntOnNoTarget = 1 (No longer used - just use 1)
Definition at line 614 of file vl53l1x_class.cpp.
VL53L1X_ERROR VL53L1X_SetI2CAddress | ( | uint8_t | new_address ) |
This function sets the sensor I2C address used in case multiple devices application, default address 0x52.
Definition at line 61 of file vl53l1x_class.cpp.
VL53L1X_ERROR VL53L1X_SetInterMeasurementInMs | ( | uint16_t | InterMeasurementInMs ) |
This function programs the Intermeasurement period in ms
Intermeasurement period must be >/= timing budget.
This condition is not checked by the API, the customer has the duty to check the condition. Default = 100 ms
Definition at line 382 of file vl53l1x_class.cpp.
VL53L1X_ERROR VL53L1X_SetInterruptPolarity | ( | uint8_t | IntPol ) |
This function programs the interrupt polarity
1=active high (default), 0=active low.
Definition at line 126 of file vl53l1x_class.cpp.
VL53L1X_ERROR VL53L1X_SetOffset | ( | int16_t | OffsetValue ) |
This function programs the offset correction in mm.
- Parameters:
-
OffsetValue:the offset correction value to program in mm
Definition at line 561 of file vl53l1x_class.cpp.
VL53L1X_ERROR VL53L1X_SetROI | ( | uint16_t | X, |
uint16_t | Y | ||
) |
This function programs the ROI (Region of Interest)
The ROI position is centered, only the ROI size can be reprogrammed.
The smallest acceptable ROI size = 4
- Parameters:
-
X:ROI Width; Y=ROI Height
Definition at line 666 of file vl53l1x_class.cpp.
VL53L1X_ERROR VL53L1X_SetSigmaThreshold | ( | uint16_t | sigma ) |
This function programs a new sigma threshold in mm (default=15 mm)
Definition at line 716 of file vl53l1x_class.cpp.
VL53L1X_ERROR VL53L1X_SetSignalThreshold | ( | uint16_t | signal ) |
This function programs a new signal threshold in kcps (default=1024 kcps
.
Definition at line 696 of file vl53l1x_class.cpp.
VL53L1X_ERROR VL53L1X_SetTimingBudgetInMs | ( | uint16_t | TimingBudgetInMs ) |
This function programs the timing budget in ms.
Predefined values = 15, 20, 33, 50, 100(default), 200, 500.
Definition at line 189 of file vl53l1x_class.cpp.
VL53L1X_ERROR VL53L1X_SetXtalk | ( | uint16_t | XtalkValue ) |
This function programs the xtalk correction value in cps (Count Per Second).
This is the number of photons reflected back from the cover glass in cps.
Definition at line 587 of file vl53l1x_class.cpp.
VL53L1X_ERROR VL53L1X_StartRanging | ( | ) |
This function starts the ranging distance operation
The ranging operation is continuous.
The clear interrupt has to be done after each get data to allow the interrupt to raise when the next data is ready
1=active high (default), 0=active low, use SetInterruptPolarity() to change the interrupt polarity if required.
Definition at line 152 of file vl53l1x_class.cpp.
VL53L1X_ERROR VL53L1X_StartTemperatureUpdate | ( | ) |
This function performs the temperature calibration.
It is recommended to call this function any time the temperature might have changed by more than 8 deg C without sensor ranging activity for an extended period.
Definition at line 739 of file vl53l1x_class.cpp.
VL53L1X_ERROR VL53L1X_StopRanging | ( | ) |
This function stops the ranging.
Definition at line 160 of file vl53l1x_class.cpp.
Generated on Tue Jul 19 2022 22:08:04 by
