Skip to main content

CircuitPython driver for VL53L5CX and VL53L8CX ToF sensors

Project description

Introduction

Documentation Status Discord Build Status Code Style: Ruff

CircuitPython driver for VL53L5CX and VL53L8CX ToF sensors

Dependencies

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.

Installing from PyPI

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

Installing to a Connected CircuitPython Device with Circup

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

Important: Binary File Requirement

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.

Usage Example

# 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()

Documentation

API documentation for this library can be found on Read the Docs.

For information on building library documentation, please check out this guide.

Contributing

Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

circuitpython_vl53lxcx-0.0.4.tar.gz (238.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

circuitpython_vl53lxcx-0.0.4-py3-none-any.whl (216.8 kB view details)

Uploaded Python 3

File details

Details for the file circuitpython_vl53lxcx-0.0.4.tar.gz.

File metadata

  • Download URL: circuitpython_vl53lxcx-0.0.4.tar.gz
  • Upload date:
  • Size: 238.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for circuitpython_vl53lxcx-0.0.4.tar.gz
Algorithm Hash digest
SHA256 c8a101c1e1e10284828db16983b552a30ad8b05355279d3a89eaf7db8e3e79be
MD5 790ffe1a127135ae10d75319ef01e6a0
BLAKE2b-256 9da6ad77551c4ab96f4dd0ef860fa39967f908e87286d2855f85d34fe702506f

See more details on using hashes here.

File details

Details for the file circuitpython_vl53lxcx-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for circuitpython_vl53lxcx-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 36a587a731f24be98dad4f5c5caed54691115fd3a7c545b2bd8ce183eafcffc2
MD5 423c4eb8e68d33332212fea5c4805921
BLAKE2b-256 545a85dcad3957d767f1c36e1d6873a15722c9de7a5acd3c6baacad423df4844

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page