CircuitPython driver for VL53L5CX and VL53L8CX ToF sensors
This driver depends on:
Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle or individual libraries can be installed using circup.
On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally from PyPI. To install for current user:
pip3 install circuitpython-vl53lxcx
To install system-wide (this may be required in some cases):
sudo pip3 install circuitpython-vl53lxcx
To install in a virtual environment in your current project:
mkdir project-name && cd project-name
python3 -m venv .venv
source .env/bin/activate
pip3 install circuitpython-vl53lxcx
Make sure that you have circup
installed in your Python environment.
Install it with the following command if necessary:
pip3 install circup
With circup
installed and your CircuitPython device connected use the
following command to install:
circup install vl53lxcx
Or the following command to update an existing version:
circup update
When using this library with CircuitPython, you must also copy the corresponding .bin
file to the /lib
folder on your CircuitPython device, alongside the .mpy
file. This binary file contains the firmware required for the VL53L5CX/VL53L8CX sensors to function properly.
The binary file should be placed in the same /lib
directory as the vl53lxcx.mpy
file on your CircuitPython filesystem.
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
# SPDX-FileCopyrightText: Copyright (c) 2025 senseBox for senseBox
#
# SPDX-License-Identifier: Unlicense
import board
import busio
from digitalio import DigitalInOut, Direction
from vl53lxcx import (
DATA_DISTANCE_MM,
DATA_TARGET_STATUS,
RESOLUTION_8X8,
STATUS_VALID,
VL53L8CX,
)
lpn_pin = board.D3
i2c = busio.I2C(board.SCL, board.SDA, frequency=1_000_000)
lpn = DigitalInOut(lpn_pin)
lpn.direction = Direction.OUTPUT
lpn.value = True
tof = VL53L8CX(i2c, lpn=lpn)
def main():
tof.reset()
if not tof.is_alive():
raise ValueError("VL53L8CX not detected")
tof.init()
tof.resolution = RESOLUTION_8X8
grid = 7
tof.ranging_freq = 2
tof.start_ranging({DATA_DISTANCE_MM, DATA_TARGET_STATUS})
while True:
if tof.check_data_ready():
results = tof.get_ranging_data()
distance = results.distance_mm
status = results.target_status
for i, d in enumerate(distance):
if status[i] == STATUS_VALID:
print(f"{d:4}", end=" ")
else:
print("xxxx", end=" ")
if (i & grid) == grid:
print("")
print("")
main()
API documentation for this library can be found on Read the Docs.
For information on building library documentation, please check out this guide.
Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.