@@ -37,6 +37,10 @@ class US100:
37
37
38
38
def __init__ (self , uart : UART ) -> None :
39
39
self ._uart = uart
40
+ # Some chips, such as ESP32-S3, may have junk input bytes immediately after UART creation.
41
+ # Wait enough time for those to appear, and then clear the buffer.
42
+ time .sleep (0.1 )
43
+ uart .reset_input_buffer ()
40
44
41
45
@property
42
46
def distance (self ) -> Optional [float ]:
@@ -52,6 +56,9 @@ def distance(self) -> Optional[float]:
52
56
objects over 460 cm away.
53
57
:return: Distance in centimeters.
54
58
:rtype: float or None
59
+
60
+ May block for up to 400 msecs while attempting a read.
61
+ Will always block for at least 100 msecs.
55
62
"""
56
63
for _ in range (2 ): # Attempt to read twice.
57
64
self ._uart .write (bytes ([0x55 ]))
@@ -74,7 +81,11 @@ def distance(self) -> Optional[float]:
74
81
75
82
@property
76
83
def temperature (self ) -> Optional [int ]:
77
- """Return the on-chip temperature, in Celsius"""
84
+ """Return the on-chip temperature, in Celsius
85
+
86
+ May block for up to 200 msecs while attempting a read.
87
+ Will always block for at least 100 msecs.
88
+ """
78
89
for _ in range (2 ): # Attempt to read twice.
79
90
self ._uart .write (bytes ([0x50 ]))
80
91
time .sleep (0.1 )
0 commit comments