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.5.tar.gz (237.3 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.5-py3-none-any.whl (216.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: circuitpython_vl53lxcx-0.0.5.tar.gz
  • Upload date:
  • Size: 237.3 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.5.tar.gz
Algorithm Hash digest
SHA256 63af9d6bb671fa5a91ab09da7ca8402ea93b6bc8b5fe3dc90b2f1b3fce1914f6
MD5 a9e0f7e2b4924d7d769e986fd9041a36
BLAKE2b-256 586c3be325676ef3d81769b73af8fef40f6784687deb5c5576cb1c46d5382e20

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for circuitpython_vl53lxcx-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 57d94e53b44c1e6f8ce3ffa22fd13ec31036e7ef8f4ddf94b1009fb51aee8e12
MD5 2c4e3ecee5bc290a18628fa872e6e343
BLAKE2b-256 72bdbb2b5739e348f88e0fcd1369adaf16b19d5c555db1511763e63b999b8e2d

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