Skip to main content

vl53l1x distance sensor driver for Raspberry Pi

Project description

# vl53l1x-python

Revised Python library for the VL53L1X Laser Ranger.

# Installing

sudo pip3 install smbus2
sudo pip3 install VL53L1X2

# Usage

import VL53L1X

tof = VL53L1X.VL53L1X(i2c_bus=1, i2c_address=0x29) # Initialise the i2c bus and configure the sensor
tof.start_ranging(1) # Start ranging, 1 = Short Range, 2 = Medium Range, 3 = Long Range
distance_in_mm = tof.get_distance() # Grab the range in mm
tof.stop_ranging() # Stop ranging

See examples and tests for more advanced usage.


* @josemotta ported it to python 3.6 as part of a homeassistant component.

Please see basic sample:

from homeassistant.const import TEMP_CELSIUS
from homeassistant.helpers.entity import Entity

REQUIREMENTS = ['smbus2==0.2.2', 'VL53L1X2==0.1.2']

def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the sensor platform."""

class TofSensor(Entity):
"""Representation of a Sensor."""

def __init__(self):
"""Initialize the sensor."""
self._state = None

def name(self):
"""Return the name of the sensor."""
return 'VL53L1X'

def state(self):
"""Return the state of the sensor."""
return self._state

def unit_of_measurement(self):
"""Return the unit of measurement."""

def update(self):
"""Fetch new state data for the sensor.

This is the only method that should fetch new data for Home Assistant.
self._state = 23


* @NagyAttila upgrade focusing on working with more than 1 range sensors, also changed quit a lot to make it bit more robust.


* Improved search for .so file to pick up arch-specific files.


* Initial release.

Project details

Release history Release notifications

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
VL53L1X2-0.1.5-cp35-cp35m-linux_armv6l.whl (131.3 kB) Copy SHA256 hash SHA256 Wheel cp35
VL53L1X2-0.1.5-cp35-cp35m-linux_armv7l.whl (131.3 kB) Copy SHA256 hash SHA256 Wheel cp35
VL53L1X2-0.1.5-cp36-cp36m-linux_armv6l.whl (118.1 kB) Copy SHA256 hash SHA256 Wheel cp36
VL53L1X2-0.1.5-cp36-cp36m-linux_armv7l.whl (120.0 kB) Copy SHA256 hash SHA256 Wheel cp36
VL53L1X2-0.1.5-cp37-cp37m-linux_armv6l.whl (118.1 kB) Copy SHA256 hash SHA256 Wheel cp37
VL53L1X2-0.1.5-cp37-cp37m-linux_armv7l.whl (118.1 kB) Copy SHA256 hash SHA256 Wheel cp37
VL53L1X2-0.1.5.tar.gz (80.3 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page