Closed Idirianuk closed 2 years ago
Having looked more closely, it seems that some defaults have changed.
It's now working if I specify a distance_mode (it seems to have been defaulting to 1, SHORT, I needed LONG) and check the validity of the returned distance.
vl53.distance_mode = 2
vl53.timing_budget = 100
I've also added a check for the returned distance being out of range:
if vl53.data_ready:
distance = vl53.distance
if distance: # Check for valid range
text = "Distance: {:.1f}cm".format(distance)
print(text)
oled.fill(0)
oled.text(text, 0, 0, 1)
vl53.clear_interrupt()
This is expected and what you've done is the correct general fix - i.e, you need to check the validity of distance
in your code since it may now return None
if the ranging was invalid for some reason. For example, if there is no object in front of the sensor.
The basic example is tolerant of this since it does not do any special formatting in the print:
print("Distance: {} cm".format(vl53.distance))
and will simply print Distance: None cm
.
Here is the PR that added this feature: https://github.com/adafruit/Adafruit_CircuitPython_VL53L1X/pull/8 and the associated issue: https://github.com/adafruit/Adafruit_CircuitPython_VL53L1X/issues/7
Many thanks. It was the apparent change in behaviour which threw me.
Closing. 😀
I can't ascertain the previous version (at previous code update, 2022-05-30, so before then, whichever bundle that was, worked perfectly, bundle dated 2022-06-11 is not working). I've currently reverted to the older version.
Code Snippet (generating a string because I want to send it to an oled):
In this context (in my main code loop) it quits to the REPL on the second line above. Error Generated:
The error is not always generated, but after a few iterations, it does fail, giving a distance reading of "None"
This is the code and sample output from the example code given on learn.adafruit.com