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.
Dependents: BigBot_v1 PololuDistanceSensorTest Lidar Ares test ... more
VL53L0X Class Reference
Class for Proximity Sensor VL53L0X. More...
#include <VL53L0X.h>
Public Member Functions | |
VL53L0X (I2C *p_i2c_device) | |
Construct a new VL53L0X object. | |
bool | setDeviceAddress (uint8_t address=ADDRESS_DEFAULT) |
Set new Device Address. | |
bool | init () |
Initializes the Sensor. | |
bool | setModeContinuous () |
Set Mode to Continuous. | |
bool | startContinuous () |
Starts the Continuous Measurement Session. | |
uint16_t | getRangeMillimeters () |
Returns measured Range in Millimeters. |
Detailed Description
Class for Proximity Sensor VL53L0X.
The VL53L0X is a laser based proximity sensor which can measure up to 2m. This library is a wrapper for the API from STMicrocontrollers and the goal of this library is the easier access to this sensor.
Something really cool about these sensors is the ability to change the I2C-address. So you can hook multiple, identical sensors on the same I2C-line.
Examples
One Sensor
Using one sensor is pretty simple, connect the I2C-pins to the sensor (Shutdown should be pulled high using a pull-up resistor).
#include "mbed.h" #include "VL53L0X.h " I2C i2c(p9, p10); VL53L0X vl_sensor(&i2c); DigitalOut vl_shutdown(p11); Serial usb(USBTX, USBRX, 115200); int main(void) { usb.printf("Single VL53L0X\n\n\r"); vl_shutdown = 1; //turn VL53L0X on vl_sensor.init(); vl_sensor.setModeContinuous(); vl_sensor.startContinuous(); while(1) { usb.printf("%4imm\n\r", vl_sensor.getRangeMillimeters()); } }
Multiple Sensors
To use multiple sensors, at the start of the programm every sensor needs to be turned off by setting their shutdown pin to low. Now one sensor is turned on, and configured with the new address. After that's done, the next sensor can be configured.
#include "mbed.h" #include "VL53L0X.h " I2C i2c(p9, p10); VL53L0X vl_sensors[6] = {(&i2c),(&i2c),(&i2c),(&i2c),(&i2c),(&i2c)}; BusOut vl_shutdown(p11,p12,p13,p14,p15,p16); Serial usb(USBTX, USBRX, 115200); int main(void) { usb.printf("Multiple VL53L0X\n\n\r"); uint8_t expander_shutdown_mask = 1; for(uint8_t i = 0; i < 6 ; i++) { vl_shutdown = expander_shutdown_mask; expander_shutdown_mask = (expander_shutdown_mask << 1) + 1; vl_sensors[i].init(); vl_sensors[i].setDeviceAddress(0x40 + i); vl_sensors[i].setModeContinuous(); vl_sensors[i].startContinuous(); } uint16_t results[6]; while(1) { for(uint8_t i = 0; i < 6 ; i++) { results[i] = vl_sensors[i].getRangeMillimeters(); } usb.printf("1: %4imm 2: %4imm 3: %4imm) 4: %4imm 5: %4imm 6: %4imm)\n\r", results[0], results[1], results[2], results[3], results[4], results[5]); } }
NOTE - The library is gigantic, so it is recommended to use this library on devices with enough storage.
Definition at line 105 of file VL53L0X.h.
Constructor & Destructor Documentation
VL53L0X | ( | I2C * | p_i2c_device ) |
Construct a new VL53L0X object.
The constructor is used to assign the needed values to the VL53L0X-Dev structure.
- Parameters:
-
p_i2c_device A pointer to an mbed I2C-object
Definition at line 24 of file VL53L0X.cpp.
Member Function Documentation
uint16_t getRangeMillimeters | ( | ) |
Returns measured Range in Millimeters.
- Returns:
- uint16_t distance in [mm]
Definition at line 117 of file VL53L0X.cpp.
bool init | ( | ) |
Initializes the Sensor.
After constructing a VL53L0X object, the sensor needs to be initialized by calling this funciton.
- Returns:
- true never going to happen
- false maybe a success
Definition at line 61 of file VL53L0X.cpp.
bool setDeviceAddress | ( | uint8_t | address = ADDRESS_DEFAULT ) |
Set new Device Address.
Replaces the current I2C-Address with a new one. Every value can be used. Currently there is a small problem on reseting the mbed board: after reset (no power reset) the sensor still uses it's new slave address. A power-reset is needed to reset the proximity sensors to their factory settings.
- Parameters:
-
address New desired 7-Bit address
- Returns:
- true no success
- false success
Definition at line 43 of file VL53L0X.cpp.
bool setModeContinuous | ( | ) |
Set Mode to Continuous.
Configures the data acquisition of the sensor to 'continuous'
- Returns:
- true never going to happen
- false maybe a success
Definition at line 86 of file VL53L0X.cpp.
bool startContinuous | ( | ) |
Starts the Continuous Measurement Session.
- Returns:
- true never going to happen
- false maybe a success
Definition at line 106 of file VL53L0X.cpp.
Generated on Wed Jul 13 2022 23:40:16 by
