Using Multiple VL53L0X ToF Sensors
Introduction
The VL53L0X ToF sensor is a relatively low-cost ($15 from Adafruit) LiDAR-based sensor produced by ST that can be used for a variety of distance measurements. One particular benefit of this sensor, though, is that the I2C address (default to 0x52) can be changed on device startup, allowing for multiple sensors on the same I2C bus. This feature is provided through the [https://os.mbed.com/teams/ST/code/VL53L0X//file/8ac15bf6d635/VL53L0X.h/|VL53L0X library], and is further demonstrated below.
Note
Changes to the address of the sensor do not persist across power cycles. As such, it is a requirement to have a DigitalOut pin per sensor in order to program the address each power cycle.
Hello World Demo
Wiring
mbed LPC1768 | VL53L0X | |
---|---|---|
VCC | VIN | |
GND | GND | |
p19 + p20 | SHDN | |
p10 | SCL | |
p9 | SDA |
Code
#include "mbed.h" #include "VL53L0X.h" DevI2C i2c(p9, p10); DigitalOut shdn1(p19), shdn2(p20); VL53L0X ld1(&i2c, &shdn1, NC), ld2(&i2c, &shdn2, NC); int main() { // Turn off all VL53L0X sensors (by grounding the shutdown pin) ld1.VL53L0X_off(); ld2.VL53L0X_off(); // Program the new I2C addresses ld1.init_sensor(0x30); ld2.init_sensor(0x50); while(1) { } }
Please log in to post comments.