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.3.tar.gz (240.6 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.3-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for circuitpython_vl53lxcx-0.0.3.tar.gz
Algorithm Hash digest
SHA256 3dbdccdada05c2ef0818ebdaca93f103be84590bc522fcdc3a1bda1426c5c204
MD5 6a02a0a3e8afe493126bf72dbc7b5724
BLAKE2b-256 575925262122d00bac84b51fcf086485dfe0becc194605f9d76ad0dcee52f28f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for circuitpython_vl53lxcx-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5dfc3667f7f02fe765ad859cf12e564caddc4e2c6d8ca98dfbbc6dc491e2c4a5
MD5 42c9168c35f83a9a84abaa7e4ffa414e
BLAKE2b-256 8880659a463f10dd7c5fe719d26a5345f2c4d027773e3a3f8e9a5731e8c3c8f1

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