In this article we will connect a VL53L0X Time-of-Flight sensor to an Raspberry Pi
Sensor information
The VL53L0X is a new generation Time-of-Flight (ToF) laser-ranging module housed in the smallest package on the market today, providing accurate distance measurement whatever the target reflectances unlike conventional technologies.
It can measure absolute distances up to 2m, setting a new benchmark in ranging performance levels, opening the door to various new applications.
The VL53L0X integrates a leading-edge SPAD array (Single Photon Avalanche Diodes) and embeds ST’s second generation FlightSenseTM patented technology.
Here is a typical module
The VL53L0X’s 940 nm VCSEL emitter (Vertical Cavity Surface-Emitting Laser), is totally invisible to the human eye, coupled with internal physical infrared filters, it enables longer ranging distances, higher immunity to ambient light, and better robustness to cover glass optical crosstalk.
Parts List
Name | Link |
Raspberry Pi Zero | Aliexpress product link |
VL53L0X ToF Sensor | Aliexpress product linkAmazon link |
Connecting wire | Aliexpress product link |
Schematic
We chose a Pi Zero for this example, any Raspberry Pi should work just fine.
Code
The example library and code examples come from https://github.com/johnbryanmoore/VL53L0X_rasp_python
sudo apt-get install build-essential python-dev
Then use following commands to clone the repository and compile:
cd your_git_directory
git clone https://github.com/johnbryanmoore/VL53L0X_rasp_python.git
cd VL53L0X_rasp_python
make
I used the VL53L0X_example.py example
[python]
#!/usr/bin/python import time import VL53L0X # Create a VL53L0X object tof = VL53L0X.VL53L0X() # Start ranging tof.start_ranging(VL53L0X.VL53L0X_BETTER_ACCURACY_MODE) timing = tof.get_timing() if (timing < 20000): timing = 20000 print ("Timing %d ms" % (timing/1000)) for count in range(1,101): distance = tof.get_distance() if (distance > 0): print ("%d mm, %d cm, %d" % (distance, (distance/10), count)) time.sleep(timing/1000000.00) tof.stop_ranging()
[/python]
you can run this by typing the following in the terminal
sudo python VL53L0X_example.py
Output
In the terminal you should see something like this