Core Electronics Forum

Accessing functions from the PiicoDev VL53L1X MicroPython Library

Hello All,

I am having problems getting correct readings from the PiicoDev VL53L1X Distance Sensor. I would like to ignore the values that the sensor returns when it is out of range.

I am using it with the Raspberry Pi Pico and MicroPython.

I have looked at the PiicoDev libary for the sensor and this document and it seems as though the PiicoDev library supports thresholds and detection modes. As far as I can work out, using these functions would allow me to only get values when it is within accurate range (4m).

Any help as to how I would enable the thresholds and detection modes would be greatly appreciated.

Thanks,
Jaden

2 Likes

Hi @Jaden130809 - the PiicoDev VL53L1X module only supports basic ranging functions (for now :wink: ). The linked document is for the VL53L1X C/C++ API which has a lot more functionality that we haven’t ported to MicroPython.
If you’re up for a bit of reverse engineering, I believe this is the official page where you can download the C/C++ libraries for the VL53L1X. And here’s Pololu’s version for Arduino. If you do end up porting any functionality to MicroPython, consider creating a pull request on the repo!

For now, if you’re just after a quick fix, does it make sense to just ignore values that fall outside a given range?
eg.

d = sensor.read()
if d < 15 or d > 3000:
    d = None

2 Likes

Hello @Michael,

Thanks for your response. I will have a look at those links.

The problem with the code you suggested is once the sensor is out of range it starts returning values that are likely to be within the limits (less than 15 or greater than 3000). Hope this makes sense.

I actually tried to modify the VL53L1X module by uncommenting the if, elseif, and else statements for the range status and added in return status into each statement.

The results were great. When it was in range it returned OK and when it was out of range it returned SignalFail.

Will keep experimenting and try to modify my code. Can’t wait till its completely ported to MicroPython. :slightly_smiling_face:

Thanks again for your support.

Jaden

3 Likes

You’re right @Jaden130809, the functionality is in there. I must have had a brainfart. Glad you dug into the module :slight_smile:

Maybe it makes sense to set the status as a property of the class, and access that with a ‘getter’ function. So code to check validation might look like:

d = sensor.read()
if sensor.rangeIsValid() == True:
    # do something with the range
else:
    print('Data is out of range')

In any case, I’ll open an issue on our repo and earmark it to work on - this functionality is too useful to ignore. Thanks :smiley:

4 Likes