Python library for using the VL53-400 laser rangerfinder via serial port
Project description
vl53-400 Laser RangeFinder Library
Python Library and CLI for the VL53-400 laser rangefinder with Serial interface
NOTE: This is still a bit underconstruction. The Functions here do seem to work, but not all capabilities of the chipset is handled yet. You should be able to do measurements though.
This is for the MJ-VL53-400 unit Sold by MengJie.
Its basically a STMicroelectronics VL53L0X with a UART so you can use it via a USB -> TTL Serial adapter and not deal with IIC or Modbus.
It seems to actually be a WitMotion Laser Distance Sensor WT-VL53L0 Distance Module UART Output repackaged by MengJie
Library Functions
Class device_access.SerialAccess contains all the methods for using it
Instantiate the RangeFinder Class
RangeFinder(serial_port: str, baud_rate: int, timeout: int, debug: bool)
Arguments
Need to supply all of these for now
serial_port: str- The serial port the RangeFinder is connected too such as/dev/tty.usbserial-910baud_rate: int- Baud Rate. Should be115200timeout: int- Timeout. Should use1return_rate: float- Should be one of"0.1", "0.2", "0.5", "1", "2", "5", "10", "20", "50", "100"debug: bool- SetTrueto enable debugging, otherwiseFalse
Example:
from vl53_400_lib import RangeFinder
range_finder = RangeFinder("/dev/tty.usbserial-910", 115200, 1, 10, False)
Reset
This method resets the Rangefinder.
range_finder.reset()
Set Sensor mode
This method sets the sensor mode between serial (default), modbus and iic.
Arguments
mode: str- The mode to set. (serial,modbus,iic) Probably only want to use serial or modbus. modbus will stop the serial updates
Example:
range_finder.set_sensor_mode("modbus")
Get Return Rate
Gets the return rate setting
Returns
str: The return rate in Hz
Example
rate = range_finder.get_return_rate()
Set Return Rate
Arguments
rate: str - One of "0.1", "0.2", "0.5", "1", "2", "5", "10", "20", "50", "100"
Example
range_finder.set_return_rate("0.5")
Stream Data
Only prints the data to stdout
This method streams data from the serial port to stdout. It does not return anything and will block until interrupted if loop is True.
Argument
loop: bool - Whether or not to loop forever.
Defaults to True.
Set to false to exit after one loop (for testing)
range_finder.stream_data(True)
Get Distance
This is the main workhorse function to use. It will fetch the distance data from the Rangefinder Reads data from the serial port and returns a dictionary.
Returns
data: dict - A dictionary containing the distance and units,
as well as the state and state_code.
data = range_finder.get_distance()
Main.py has a CLI for exercising all functions
Install and run cli
git clone
cd vl53_400_lib
poetry install
To run the cli:
> poetry run vl53 --help
Usage: vl53 [OPTIONS]
Options:
--serial-port TEXT The serial port to connect to.
--baud-rate INTEGER The baud rate to use.
--timeout INTEGER The timeout to use.
--return-rate [0.1|0.2|0.5|1|2|5|10|20|50|100]
Set Return Rate in Hz
--mode [serial|modbus|iic] Comm mode (modbus stops serial spew)
--op [stream|get_return_rate|lstream|reset]
The operation to perform.
--debug Enable debug logging.
--help Show this message and exit.
TODO:
- Make initialization key/values with defaults
- Calibration
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file vl53_400_lib-0.1.2.tar.gz.
File metadata
- Download URL: vl53_400_lib-0.1.2.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.11.4 Darwin/22.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
db7ced6de38a23e481446fee219989bbb223c65c64a88f6dfa6f39ecbfce0184
|
|
| MD5 |
636616f5b4fda58c94012430e31231ac
|
|
| BLAKE2b-256 |
fe446cab03ced32c8e9bb26dd16a96ef03753571d4260c16a7ff9a9c6714821e
|
File details
Details for the file vl53_400_lib-0.1.2-py3-none-any.whl.
File metadata
- Download URL: vl53_400_lib-0.1.2-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.11.4 Darwin/22.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b92137c6baa9cedd4b13841c1f85d939838f650ec32f181e9664bc3f1cd74814
|
|
| MD5 |
8ea41994a80b1b4edc61b96ce2b3fb37
|
|
| BLAKE2b-256 |
75474214942334b46831d755a3a991ff2f29b4b4364b74dca6f030ae926aa7cc
|