hardware: raspberry pi pico
language: adafruit-circuitpython
TL;DR: 0.001 sec is the maximum precision that time.sleep() can perform. how can we get over it, using circuitpython? The 'utime' library works only on micropython...
The long story: look at the following code:
import time
x = time.monotonic_ns()
for i in range(10):
time.sleep(1.0005)
print (time.monotonic_ns()-x)
You would expect the output to be something like
- 1000500000
- 2001000000
- 3001500000
- 4002000000
- ...
But the output is:
- 1000976563 (almost 1001000000 )
- 2000976563 (almost 2001000000 )
- 3000976563 (almost 3001000000 )
- 4000976563 (almost 4001000000 )
- 5000976563 (almost 5001000000 )
I believe somewhere along the way there is an issue of floats representation using not enough bits, because:
1,000,000,000 / 1024 = 976562.5
But I'm really new to all of this stuff so I'll be glad to get help from you all.