adafruit / Adafruit_CircuitPython_VL53L1X

CircuitPython module for interacting with the VL53L1X distance sensor.
MIT License
8 stars 10 forks source link

Sensor returns false readings when no object is detected #7

Closed thekakester closed 2 years ago

thekakester commented 2 years ago

Steps to repeat: Leave a really long air gap (10+ meters) in front of the sensor. The sensor will report false readings, often saying it detects an object 100-500mm away when in reality there is nothing.

Test was done indoors with no covering over the prox sensor. This was repeated on a sample set of 50x sensors using 50x development boards and they all behave accordingly.

Changing the timing budget and distance mode has no effect on these readings. I'm curious if there's some crosstalk settings that can be changed, but this library doesn't support it unlike the arduino library counterpart.

caternuson commented 2 years ago

Thanks. Seeing same thing testing locally. This library is very simple translation from the Arduino library. So there could be some things missing or different.

Are you able to test with the Arduino library in your setup? If so, what behavior do you get from that in the same scenario? With the 10+ meter gap and running this example: https://github.com/adafruit/Adafruit_VL53L1X/blob/main/examples/VL53L1X_simpletest/VL53L1X_simpletest.ino is it more in line with expected results?

caternuson commented 2 years ago

Actually, nevermind about testing with Arduino. Looks like this can be fixed fairly simply. PR submitted.

thekakester commented 2 years ago

Thanks for looking into this. Do you have a ballpark idea of what's happening? I was digging through the datasheet for this sensor a bit, but it doesn't seem very technical in terms of registers/commands or a programming guide, so right now I'm referencing the official ST library that they made for STM32 and Linux.

Could you let me know what area you're investigating? I'd like to familiarize myself with the ST code as well just as an exercise. Thanks

caternuson commented 2 years ago

The driver was returning the distance data without doing any validity checking. So it was not possible to discern bad data from good data from just the distance value. The simple fix is to read and check the value of the VL53L1X_RESULT__RANGE_STATUS register.

Unfortunately, this information does not appear to be provided in any datasheets. So it requires reading through the available driver source code: https://github.com/stm32duino/VL53L1X

The Adafruit Arduino driver is just a fork of that same repo, with some additional wrapper code: https://github.com/adafruit/Adafruit_VL53L1X

thekakester commented 2 years ago

You are a saint! Thanks for looking at this so quickly.