Adafruit vl53l0x Micro Lidar Distance Sensor Breakout
Adafruit vl53l0x Micro Lidar Distance Sensor Breakout
Adafruit vl53l0x Micro Lidar Distance Sensor Breakout
https://learn.adafruit.com/adafruit-vl53l0x-micro-lidar-distance-sensor-breakout
Overview 3
• Sensing Capablities
Pinouts 7
• Power Pins:
• I2C Logic pins:
• Control Pins:
Assembly 9
• Prepare the header strip:
• Solder!
Arduino Code 12
• Download Adafruit_VL53L0X
• Load Demo
• Connecting Multiple Sensors
Python Docs 21
Downloads 21
• Files & Datasheets
• Schematic & Fabrication Print - STEMMA QT Version
• Schematic & Fabrication Print - Original Version
The VL53L0X is a Time of Flight distance sensor like no other you've used! The
sensor contains a very tiny invisible laser source, and a matching sensor. The
VL53L0X can detect the "time of flight", or how long the light has taken to bounce
back to the sensor. Since it uses a very narrow light source, it is good for determining
distance of only the surface directly in front of it. Unlike sonars that bounce ultrasonic
waves, the 'cone' of sensing is very narrow. Unlike IR distance sensors that try to
measure the amount of light bounced, the VL53L0x is much more precise and doesn't
have linearity problems or 'double imaging' where you can't tell if an object is very far
or very close.
This is the 'big sister' of the VL6180X ToF sensor, and can handle about 50 - 1200 mm
of range distance. If you need a smaller/closer range, check out the VL6180X which
can measure 5mm to 200mm.
There are two versions of this board - the STEMMA QT version shown above, and
the original header-only version shown below. Code works the same on both!
Communicating to the sensor is done over I2C with an API written by ST, so its not too
hard to port it to your favorite microcontroller. We've written a wrapper library for
Arduino so you can use it with any of your Arduino-compatible boards.
Sensing Capablities
The sensor can measure approximately 50mm to 1.2 meter in default mode.
Depending on ambient lighting and distance, you'll get 3 to 12% ranging accuracy -
better lighting and shiny surfaces will give you best results. Some experimentation will
be necessary since if the object absorbs the laser light you won't get good readings.
For future reference, the default I2C address is 0x29. You can change it, but only in
software. That means you have to wire the SHUTDOWN pin and hold all but one
sensor in reset while you reconfigure one sensor at a time
Control Pins:
• GPIO - this is a pin that is used by the sensor to indicate that data is ready. It's
useful for when doing continuous sensing. Note there is no level shifting on this
pin, you may not be able to read the 2.8V-logic-level voltage on a 5V
microcontroller (we could on an arduino UNO but no promises). Our library
doesn't make use of this pin but for advanced users, it's there!
Assembly
Don't forget to remove the protective cover off the sensor, it may be a clear or
slightly tinted plastic! Otherwise you will get incorrect readings
This page shows the VL53L0X or VL6180X sensor - the procedure is identical!
Arduino Code
You can easily wire this breakout to any microcontroller, we'll be using an Arduino. For
another kind of microcontroller, just make sure it has I2C, then port the API code. We
strongly recommend using an Arduino to start though!
You can change it, but only in software. That means you have to wire the SHUTDOWN
pin and hold all but one sensor in reset while you reconfigure one sensor at a time
Download Adafruit_VL53L0X
To begin reading sensor data, you will need to install the Adafruit_VL53L0X Library ().
Load Demo
Open up File->Examples->Adafruit_VL53L0X->vl53l0x and upload to your Arduino
wired up to the sensor
Move your hand up and down to read the sensor data. Note that when nothing is
detected, it will say the reading is out of range
Don't forget to remove the protective plastic cover from the sensor before using!
To set the new address you can do it one of two ways. During initialization, instead of
calling lox.begin(), call lox.begin(0x30) to set the address to 0x30. Or you can,
later, call lox.setAddress(0x30) at any time.
1. Reset all sensors by setting all of their XSHUT pins low for delay(10), then set all
XSHUT high to bring out of reset
2. Keep sensor #1 awake by keeping XSHUT pin high
3. Put all other sensors into shutdown by pulling XSHUT pins low
4. Initialize sensor #1 with lox.begin(new_i2c_address) Pick any number but 0x29
and it must be under 0x7F. Going with 0x30 to 0x3F is probably OK.
5. Keep sensor #1 awake, and now bring sensor #2 out of reset by setting its
XSHUT pin high.
6. Initialize sensor #2 with lox.begin(new_i2c_address) Pick any number but 0x29
and whatever you set the first sensor to
7. Repeat for each sensor, turning each one on, setting a unique address.
Note you must do this every time you turn on the power, the addresses are not
permanent!
You can use this sensor with any CircuitPython microcontroller board or with a
computer that has GPIO and Python thanks to Adafruit_Blinka, our CircuitPython-for-
Python compatibility library ().
First make sure you are running the latest version of Adafruit CircuitPython () for your
board.
Remember for non-express boards like the, you'll need to manually install the
necessary libraries from the bundle:
• adafruit_vl53l0x.mpy
• adafruit_bus_device
Before continuing make sure your board's lib folder or root filesystem has the adafruit
_vl53l0x.mpy, and adafruit_bus_device files and folders copied over.
Once that's done, from your command line run the following command:
If your default Python is version 3 you may need to run 'pip' instead. Just make sure
you aren't trying to use CircuitPython on Python 2.x, it isn't supported!
import board
import busio
import adafruit_vl53l0x
i2c = busio.I2C(board.SCL, board.SDA)
sensor = adafruit_vl53l0x.VL53L0X(i2c)
Now you're ready to read values from the sensor using any of these properties:
print('Range: {}mm'.format(sensor.range))
In addition you can adjust the measurement timing budget to change the speed and
accuracy of the sensor. Get and set the measurement_timing_budget property with a
value in nanoseconds. For example to increase the timing budget to a more accurate
but slower 200ms value:
sensor.measurement_timing_budget = 200000
See the simpletest.py example () for a complete demo of printing the range every
second. Save this as code.py on the board and examine the REPL output to see the
range printed every second.
import board
import adafruit_vl53l0x
# Optionally adjust the measurement timing budget to change speed and accuracy.
# See the example here for more details:
# https://github.com/pololu/vl53l0x-arduino/blob/master/examples/Single/Single.ino
# For example a higher speed but less accurate timing budget of 20ms:
# vl53.measurement_timing_budget = 20000
# Or a slower but more accurate timing budget of 200ms:
# vl53.measurement_timing_budget = 200000
# The default timing budget is 33ms, a good compromise of speed and accuracy.
# Main loop will read the range and print it every second.
while True:
print("Range: {0}mm".format(vl53.range))
time.sleep(1.0)
Python Docs
Python Docs ()
Downloads
Files & Datasheets
• Datasheet for the VL53L0X ()
• ST product page () with more details including API downloads
• Fritzing object in Adafruit Fritzing library ()
• EagleCAD PCB files in GitHub ()