-
Notifications
You must be signed in to change notification settings - Fork 25
Reading from the sensor in Continuous mode is blocking, and the continuous mode example mis-reports the call timing. #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
it'll always take 33ms (at least) to measure, plus 20ms for processing, since thats the timing budget. if it says less something is wonky with your timing. 49ms sounds right! |
Thanks for the quick reply! Do you know if there is another adafruit sensor where it would be possible for the sensor to perform readings on it's own, and the circuitpython program to just get the latest reading back? I'm trying to use a distance sensor for a realtime system, and can't afford to suspend execution while the sensor is working. |
you can read thru the driver code to see how continuous works, basically you need to check if the data is ready before you try to read it, otherwise it will block |
I'm attempting it now, and will try to make it my first pull request, but I've run into a snag: It seems the time is being eaten up by the I2C device read/write calls, and not any looping inside the sensor module. Looking at the read_range() function, I assumed this is where we wait for the data to be ready:
However, when I profiled the function, the loop is only evaluated and it's contents never executed. The delays are coming from the _read_u8 and _write_u16 methods, in which it's the base I2C device that's using the time. For example, this _read_u8 method takes 19ms on my Feather S2:
If the base I2C device read/write are where the time is taken, does that mean that it's not possible to check if data is available from the sensor faster than this (without modifying the I2C device implementation)? What's strange is I am also using I2C device with the PCA9865 driver, only the I2C device writes don't appear produce similar delays in that driver - though I haven't explicitly measured. |
(Also, this bug report was based on me misunderstanding what continuous_mode is supposed to do - it can be closed or moved to a more appropriate venue.) |
The maximum block time can be reduced from 50ms to 2.5ms* using two methods:
*testing with Feather S2, measurement_timing_budget of 200ms, calling read_range every 50ms |
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:
This includes my attempt at measuring around the existing time measurement, and output looks like this:
Can anyone confirm if:
Thanks for your time.
The text was updated successfully, but these errors were encountered: