Yesterday I published a material about VL53L0X in which we connected this sensor to Arduino. Today we will connect the VL53L0X sensor to the Raspberry Pi.
About VL53L0X
In this article I will show an example of connecting a VL53L0X laser rangefinder to a Raspberry Pi board. The VL53L0X is a next generation Time-of-Flight (ToF) laser rangefinder housed in the smallest form factor to date, providing accurate distance measurement regardless of target reflectivity unlike traditional technologies.
It can measure absolute distances up to 2 meters, setting a new benchmark in a range of performance levels, opening the door to a variety of new applications.
The VL53L0X integrates an advanced SPAD (Single Photon Avalanche Diode) array and incorporates ST’s patented second generation FlightSenseTM technology. A typical module looks like this:
The VCSEL 940nm VL53L0X (Vertical Cavity Surface Laser) emitter is completely invisible to the human eye, when combined with internal physical infrared filters, it provides longer distances, higher ambient light immunity and better glass optical crosstalk immunity.
Components
By tradition, I give a list of components for working with our example:
- Raspberry Pi Zero W (wireless) (2017 model)
- VL53L0X (ToF) – laser rangefinder
- Connecting jumpers
Connection diagram
We chose the Pi Zero, but any Raspberry Pi should work just fine. We connect everything according to the diagram below.
Example code
We take the example of the library and the code itself from the repository on GitHub – https://github.com/johnbryanmoore/VL53L0X_rasp_python…
sudo apt-get install build-essential python-dev
Then we use the 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
Change your_git_directory to the directory we need. Next, we use the example code itself in the VL53L0X_example.py file:
#!/usr/bin/python import time import VL53L0X # Создаем VL53L0X объект tof = VL53L0X.VL53L0X() # Запуск start_ranging tof.start_ranging(VL53L0X.VL53L0X_BETTER_ACCURACY_MODE) timing = tof.get_timing() if (timing < 20000): timing = 20000 print ("Тайминг %d ms" % (timing/1000)) for count in range(1,101): distance = tof.get_distance() if (distance > 0): print ("%d мм, %d см, %d" % (distance, (distance/10), count)) time.sleep(timing/1000000.00) tof.stop_ranging()
You can run this by typing the following in a terminal:
sudo python VL53L0X_example.py
You should see something like this in the terminal:
That’s all. More information about the VL53l0X sensor can be found in this material.