GithubHelp home page GithubHelp logo

adafruit / adafruit_circuitpython_vl53l0x Goto Github PK

View Code? Open in Web Editor NEW
36.0 23.0 26.0 145 KB

CircuitPython module for interacting with the VL53L0X distance sensor.

License: MIT License

Python 100.00%
hacktoberfest

adafruit_circuitpython_vl53l0x's Introduction

Introduction

Documentation Status Discord Build Status Code Style: Black

CircuitPython driver for the VL53L0X distance sensor.

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.

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 adafruit-circuitpython-vl53l0x

To install system-wide (this may be required in some cases):

sudo pip3 install adafruit-circuitpython-vl53l0x

To install in a virtual environment in your current project:

mkdir project-name && cd project-name
python3 -m venv .venv
source .venv/bin/activate
pip3 install adafruit-circuitpython-vl53l0x

Usage Example

See usage in the examples/vl53l0x_simpletest.py file.

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.

adafruit_circuitpython_vl53l0x's People

Contributors

2bndy5 avatar brennen avatar brentru-2 avatar caternuson avatar dhalbert avatar evaherrada avatar foamyguy avatar gamblor21 avatar jepler avatar kattni avatar ladyada avatar rhooper avatar siddacious avatar smankusors avatar sommersoft avatar tannewt avatar tcfranks avatar tdicola avatar tekktrik avatar whogben avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

adafruit_circuitpython_vl53l0x's Issues

Minified version of library?

Is there a simplified version of this library that works on a Trinket M0? The trinket M0 only has 59kb of space; this library + adafruit_bus_device can't both fit on it.

Long Range

Dear all,
thanks for the toolset, very effective.

I don't find a python equivalent to
https://forums.adafruit.com/viewtopic.php?f=19&p=713761
"
#if defined LONG_RANGE
// lower the return signal rate limit (default is 0.25 MCPS)
sensor.setSignalRateLimit(0.1);
// increase laser pulse periods (defaults are 14 and 10 PCLKs)
sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodPreRange, 18);
sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodFinalRange, 14);
#endif
"
in order to use the Long Range mode.

I found the "signal_rate_limit" property, but periodPreRange and FinalRange.

Can you help ?

Best

Cannot turn vl53l0x on after shutdown

Adafruit CircuitPython 5.3.1 on 2020-07-13; Adafruit Feather M4 Express with samd51j19

The VL53L0X does not appear to return from shutdown mode. When SHDN has been brought low, and then high, the next read of the sensor will hang. See wiring here:

Vl53L0x

Code is:

lee_vl53L0x.txt

Documentation at:
https://learn.adafruit.com/adafruit-vl53l0x-micro-lidar-distance-sensor-breakout/pinouts

seems to indicate this pin is already pulled high. Does the board require additional pull-up in circuit? Is there a fault in the library?

reading range is an order of magnitude slower than expected

I have a Trinket M0 with the module connected to gpio pins 0/2 and gpio pin 3 as a pwm output for an LED (through a transistor). Circuitpython bundle build is 3.x dated 20180809 with the 3.0.0 uf2 firmware.

For some reason with the default configuration the sensor is taking approximately 2 seconds to take a reading:

sensor distance 8191mm, time 2.08398
sensor distance 257mm, time 2.08203
sensor distance 190mm, time 2.08203
sensor distance 294mm, time 2.08179

i2c = busio.I2C(board.SCL, board.SDA)
sensor = adafruit_vl53l0x.VL53L0X(i2c)
#sensor.measurement_timing_budget = 20000

while True:
    start = time.monotonic()
    distance = sensor.range
    print("sensor distance " + str(distance) + "mm, time " + str(time.monotonic() - start))

Dropping the timing budget to 20ms helps by roughly 300ms and in both modes there is the occasional fast read:

sensor distance 8191mm, time 1.76489
sensor distance 8190mm, time 0.0290527
sensor distance 8190mm, time 1.76611
sensor distance 149mm, time 1.76904
sensor distance 212mm, time 1.76587
sensor distance 296mm, time 1.76392
sensor distance 8190mm, time 1.76611

Any idea what would cause such a delay?

No continuous Mode

Hello,

I need continuous mode for one of my projet using multiple VL53L0X.

Do you planned to make the support for in your lib ?

Does I need to do the support myself ?

Regards,

DisplayIO Example Wanted

Add a Basic DisplayIO Based Example

We would like to have a basic displayio example for this library. The example should be written for microcontrollers with a built-in display. At a minimum it should show a Label on the display and update it with live readings from the sensor.

The example should not be overly complex, it's intended to be a good starting point for displayio based projects that utilize this sensor library. Try to keep all visual content as near to the top left corner as possible in order to best fascilitate devices with small built-in display resolutions.

The new example should follow the naming convention examples/libraryname_displayio_simpletest.py with "libraryname" being replaced by the actual name of this library.

You can find an example of a Pull Request that adds this kind of example here: adafruit/Adafruit_CircuitPython_BME680#72

We have a guide that covers the process of contributing with git and github: https://learn.adafruit.com/contribute-to-circuitpython-with-git-and-github

If you're interested in contributing but need additional help, or just want to say hi, feel free to join the Discord server to ask questions: https://adafru.it/discord

Discord Link : Invite Invalid

On the readme there's Discord chat badge. When clicked, Discord says "This invite may be expired, or you might not have permission to join."

Missing Type Annotations

There are missing type annotations for some functions in this library.

The typing module does not exist on CircuitPython devices so the import needs to be wrapped in try/except to catch the error for missing import. There is an example of how that is done here:

try:
    from typing import List, Tuple
except ImportError:
    pass

Once imported the typing annotations for the argument type(s), and return type(s) can be added to the function signature. Here is an example of a function that has had this done already:

def wrap_text_to_pixels(
    string: str, max_width: int, font=None, indent0: str = "", indent1: str = ""
) -> List[str]:

If you are new to Git or Github we have a guide about contributing to our projects here: https://learn.adafruit.com/contribute-to-circuitpython-with-git-and-github

There is also a guide that covers our CI utilities and how to run them locally to ensure they will pass in Github Actions here: https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/check-your-code In particular the pages: Sharing docs on ReadTheDocs and Check your code with pre-commit contain the tools to install and commands to run locally to run the checks.

If you are attempting to resolve this issue and need help, you can post a comment on this issue and tag both @FoamyGuy and @kattni or reach out to us on Discord: https://adafru.it/discord in the #circuitpython-dev channel.

The following locations are reported by mypy to be missing type annotations:

  • adafruit_vl53l0x.py:103
  • adafruit_vl53l0x.py:108
  • adafruit_vl53l0x.py:122
  • adafruit_vl53l0x.py:127
  • adafruit_vl53l0x.py:140
  • adafruit_vl53l0x.py:303
  • adafruit_vl53l0x.py:311
  • adafruit_vl53l0x.py:319
  • adafruit_vl53l0x.py:326
  • adafruit_vl53l0x.py:367
  • adafruit_vl53l0x.py:380
  • adafruit_vl53l0x.py:401
  • adafruit_vl53l0x.py:445
  • adafruit_vl53l0x.py:472
  • adafruit_vl53l0x.py:548

Issue with implementation of VL53L0X and TCA9548A multiplexer

I've been trying to work one vl53l0x with a TCA9548A. My code is as follows:

import time
import board
import busio
import adafruit_vl53l0x
import adafruit_tca9548a

# Create I2C bus as normal
i2c = busio.I2C(board.SCL, board.SDA)

# Create the TCA9548A object and give it the I2C bus
tca = adafruit_tca9548a.TCA9548A(i2c)

# For each sensor, create it using the TCA9548A channel instead of the I2C object
vl53a = adafruit_vl53l0x.VL53L0X(tca[0])
#vl53b = adafruit_vl53l0x.VL53L0X(tca[1])

#tsl2 = adafruit_tsl2591.TSL2591(tca[1])

# print range 1 per second
while True:
    print("Range: {0}mm".format(vl53a.range))
#    print("Range: {0}mm".format(vl53b.range))
    time.sleep(1.0)

# Optionally adjust the measurement timing budget to change speed and accuracy.
# See the example here for more details:
#   https://github.com/pololu/vl53l0x-arduino/blob/master/examples/Single/Single.ino
# For example a higher speed but less accurate timing budget of 20ms:
# Measured in microseconds
# 1 second = 1000 millisecond = 1000000 microsecond
# vl53.measurement_timing_budget = 20000
# Or a slower but more accurate timing budget of 200ms:
# vl53.measurement_timing_budget = 200000
# The default timing budget is 33ms, a good compromise of speed and accuracy.

but every attempt leads to the following error.

%Run test-i2c.py
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/adafruit_bus_device/i2c_device.py", line 154, in __probe_for_device
    self.i2c.writeto(self.device_address, b"")
  File "/home/pi/.local/lib/python3.7/site-packages/adafruit_tca9548a.py", line 67, in writeto
    return self.tca.i2c.writeto(address, buffer, **kwargs)
  File "/home/pi/.local/lib/python3.7/site-packages/busio.py", line 116, in writeto
    return self._i2c.writeto(address, buffer, stop=stop)
  File "/home/pi/.local/lib/python3.7/site-packages/adafruit_blinka/microcontroller/generic_linux/i2c.py", line 49, in writeto
    self._i2c_bus.write_bytes(address, buffer[start:end])
  File "/home/pi/.local/lib/python3.7/site-packages/Adafruit_PureIO/smbus.py", line 308, in write_bytes
    self._device.write(buf)
OSError: [Errno 121] Remote I/O error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/adafruit_bus_device/i2c_device.py", line 160, in __probe_for_device
    self.i2c.readfrom_into(self.device_address, result)
  File "/home/pi/.local/lib/python3.7/site-packages/adafruit_tca9548a.py", line 61, in readfrom_into
    return self.tca.i2c.readfrom_into(address, buffer, **kwargs)
  File "/home/pi/.local/lib/python3.7/site-packages/busio.py", line 106, in readfrom_into
    return self._i2c.readfrom_into(address, buffer, stop=stop)
  File "/home/pi/.local/lib/python3.7/site-packages/adafruit_blinka/microcontroller/generic_linux/i2c.py", line 56, in readfrom_into
    readin = self._i2c_bus.read_bytes(address, end - start)
  File "/home/pi/.local/lib/python3.7/site-packages/Adafruit_PureIO/smbus.py", line 179, in read_bytes
    return self._device.read(number)
OSError: [Errno 121] Remote I/O error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pi/Desktop/test-i2c.py", line 19, in <module>
    vl53l0x = adafruit_vl53l0x.VL53L0X(tca9548a[0])
  File "/usr/local/lib/python3.7/dist-packages/adafruit_vl53l0x.py", line 142, in __init__
    self._device = i2c_device.I2CDevice(i2c, address)
  File "/usr/local/lib/python3.7/dist-packages/adafruit_bus_device/i2c_device.py", line 50, in __init__
    self.__probe_for_device()
  File "/usr/local/lib/python3.7/dist-packages/adafruit_bus_device/i2c_device.py", line 163, in __probe_for_device
    raise ValueError("No I2C device at address: 0x%x" % self.device_address)
ValueError: No I2C device at address: 0x29

Reading from the sensor in Continuous mode is blocking, and the continuous mode example mis-reports the call timing.

Hi there,

I came across this issue while trying to read a VL53l0x without blocking program execution for a long time. No matter how I tried it, I tended to get blocked for 40-60ms on reading the sensor.

I tried using this Simple Continuous Example and noticed that it was reporting 0.00 and 1.00 ms for the continuous mode read times - perfect! Except, when I added my own timing check around the loop, I am getting 49ms for each read call:

with vl53.continuous_mode():
    while True:
        # try to adjust the sleep time (simulating program doing something else)
        # and see how fast the sensor returns the range
        time.sleep(0.2)

        curTime = time.time()
        ns = time.monotonic_ns() # new line
        print("Range: {0}mm ({1:.2f}ms)".format(vl53.range, time.time() - curTime))
        real_ms = (time.monotonic_ns() - ns)/1_000_000 # new line
        print('(real ms ' + str(real_ms) + ')') # new line

This includes my attempt at measuring around the existing time measurement, and output looks like this:

Range: 301mm (0.00ms)
  (real ms 49.3774)
  Range: 301mm (0.00ms)
  (real ms 49.4079)
  Range: 301mm (0.00ms)
  (real ms 49.4079)

Can anyone confirm if:

  1. my time measurement is correct and the example is in fact reporting a smaller number of ms than it takes?
  2. continous_mode is supposed to make it so that you can read_range() quickly (ie in a few ms or less?)

Thanks for your time.

Project dependencies may have API risk issues

Hi, In Adafruit_CircuitPython_VL53L0X, inappropriate dependency versioning constraints can cause risks.

Below are the dependencies and version constraints that the project is using

Adafruit-Blinka
adafruit-circuitpython-busdevice

The version constraint == will introduce the risk of dependency conflicts because the scope of dependencies is too strict.
The version constraint No Upper Bound and * will introduce the risk of the missing API Error because the latest version of the dependencies may remove some APIs.

After further analysis, in this project,
The version constraint of dependency Adafruit-Blinka can be changed to >=0.1.5,<=8.0.2.

The above modification suggestions can reduce the dependency conflicts as much as possible,
and introduce the latest version as much as possible without calling Error in the projects.

The invocation of the current project includes all the following methods.

The calling methods from the Adafruit-Blinka
micropython.const
The calling methods from the all methods
self._device.readinto
format
int
self._get_spad_info
self._device.write
_timeout_microseconds_to_mclks
adafruit_vl53l0x.VL53L0X.continuous_mode
float
i.vl53.set_address
time.time
sphinx_rtd_theme.get_html_theme_path
self._write_u16
power_pin.switch_to_output
RuntimeError
print
stop_continuous
self._perform_single_ref_calibration
bytearray
self._write_u8
_encode_timeout
digitalio.DigitalInOut
len
busio.I2C
os.path.abspath
time.sleep
adafruit_vl53l0x.VL53L0X
self._read_u16
board.I2C
_decode_timeout
adafruit_bus_device.i2c_device.I2CDevice
range
self.read_range
str
self._get_sequence_step_timeouts
self._get_vcsel_pulse_period
time.monotonic
i.vl53.start_continous
datetime.datetime.now
self._read_u8
math.pow
detect_range
sensor.stop_continuous
self.do_range_measurement
vl53.insert
micropython.const
_timeout_mclks_to_microseconds
self.stop_continuous
enumerate
self._get_sequence_step_enables
os.environ.get
self.start_continuous
sys.path.insert
ValueError

@developer
Could please help me check this issue?
May I pull a request to fix it?
Thank you very much.

Multiple sensors using Qwiic connector

I have two of these sensors I want to use at once. I assumed I could use them at the same time, but when I try to do the multi read:

xshut = [
    DigitalInOut(board.D7),
    DigitalInOut(board.D9),
    # add more VL53L0X sensors by defining their SHDN pins here
]

It just hangs there. I'm not sure exactly how to switch it to support running two at once. Any suggestions?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.