Pololu Arduino library for VL53L0X time-of-flight distance sensor
Release date: 2020 Sep 24
This is a library for the Arduino IDE that helps interface with ST's VL53L0X time-of-flight distance sensor. The library makes it simple to configure the sensor and read range data from it via I²C.
This library is designed to work with the Arduino IDE versions 1.6.x or later; we have not tested it with earlier versions. This library should support any Arduino-compatible board, including the Pololu A-Star 32U4 controllers.
Make the following connections between the Arduino and the VL53L0X board:
(including Arduino Uno, Leonardo, Mega; Pololu A-Star 32U4)
Arduino VL53L0X board ------- ------------- 5V - VIN GND - GND SDA - SDA SCL - SCL
(including Arduino Due)
Arduino VL53L0X board ------- ------------- 3V3 - VIN GND - GND SDA - SDA SCL - SCL
If you are using version 1.6.2 or later of the Arduino software (IDE), you can use the Library Manager to install this library:
If this does not work, you can manually install the library:
Several example sketches are available that show how to use the library. You can access them from the Arduino IDE by opening the "File" menu, selecting "Examples", and then selecting "VL53L0X". If you cannot find these examples, the library was probably installed incorrectly and you should retry the installation instructions above.
Most of the functionality of this library is based on the VL53L0X API provided by ST (STSW-IMG005), and some of the explanatory comments in the code are quoted or paraphrased from the API source code, API user manual (UM2039), and the VL53L0X datasheet. For more explanation about the library code and how it was derived from the API, see the comments in VL53L0X.cpp.
This library is intended to provide a quicker and easier way to get started using the VL53L0X with an Arduino-compatible controller, in contrast to customizing and compiling ST's API for the Arduino. The library has a more streamlined interface, as well as smaller storage and memory footprints. However, it does not implement some of the more advanced functionality available in the API (for example, calibrating the sensor to work well under a cover glass), and it has less robust error checking. For advanced applications, especially when storage and memory are less of an issue, consider using the VL53L0X API directly.
Wire.endTransmission()documentation for return values.
void setBus(TwoWire * bus)
busshould be a pointer to a
TwoWireobject; the default bus is
Wire, which is typically the first or only I²C bus on an Arduino. If your Arduino has more than one I²C bus and you have the VL53L0X connected to the second bus, which is typically called
Wire1, you can call
TwoWire * getBus()
void setAddress(uint8_t new_addr)
bool init(bool io_2v8 = true)
io_2v8is true (the default if not specified), the sensor is configured for 2V8 mode (2.8 V I/O); if false, the sensor is left in 1V8 mode. The return value is a boolean indicating whether the initialization completed successfully.
void writeReg(uint8_t reg, uint8_t value)
Register address constants are defined by the regAddr enumeration type in VL53L0X.h.
void writeReg16Bit(uint8_t reg, uint16_t value)
void writeReg32Bit(uint8_t reg, uint32_t value)
uint8_t readReg(uint8_t reg)
uint16_t readReg16Bit(uint8_t reg)
uint32_t readReg32Bit(uint8_t reg)
void writeMulti(uint8_t reg, uint8_t const * src, uint8_t count)
void readMulti(uint8_t reg, uint8_t * dst, uint8_t count)
bool setSignalRateLimit(float limit_Mcps)
bool setMeasurementTimingBudget(uint32_t budget_us)
bool setVcselPulsePeriod(vcselPeriodType type, uint8_t period_pclks)Sets the VCSEL (vertical cavity surface emitting laser) pulse period for the given period type (
VL53L0X::VcselPeriodFinalRange) to the given value (in PCLKs). Longer periods increase the potential range of the sensor. Valid values are (even numbers only):
Pre: 12 to 18 (initialized to 14 by default)
Final: 8 to 14 (initialized to 10 by default)
The return value is a boolean indicating whether the requested period was valid.
uint8_t getVcselPulsePeriod(vcselPeriodType type)
void startContinuous(uint32_t period_ms = 0)
period_msis 0 (the default if not specified), continuous back-to-back mode is used (the sensor takes measurements as often as possible); if it is nonzero, continuous timed mode is used, with the specified inter-measurement period in milliseconds determining how often the sensor takes a measurement.
void setTimeout(uint16_t timeout)
init()and added a check for its return value in examples; fixed a few other issues.