Skip to content

Commit 59c390f

Browse files
committed
time.sleep() is too inaccurate; use microcontroller.delay_us()
1 parent f9606d4 commit 59c390f

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

lcd/i2c_pcf8574_interface.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,14 @@
1818
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1919
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2020

21-
import time
21+
"""Low-level interface to PCF8574."""
2222

2323
import busio
2424
import board
2525
from adafruit_bus_device.i2c_device import I2CDevice
2626

2727
from .lcd import LCD_4BITMODE, LCD_BACKLIGHT, LCD_NOBACKLIGHT, PIN_ENABLE
2828

29-
MICROSECOND = 1e-6
30-
MILLISECOND = 1e-3
3129

3230
class I2CPCF8574Interface:
3331

@@ -81,12 +79,14 @@ def _write4bits(self, value):
8179
"""Pulse the `enable` flag to process value."""
8280
with self.i2c_device:
8381
self._i2c_write(value & ~PIN_ENABLE)
84-
time.sleep(MICROSECOND)
82+
# This 1us delay is probably unnecessary, given the time needed
83+
# to execute the statements.
84+
microcontroller.delay_us(1)
8585
self._i2c_write(value | PIN_ENABLE)
86-
time.sleep(MICROSECOND)
86+
microcontroller.delay_us(1)
8787
self._i2c_write(value & ~PIN_ENABLE)
8888
# Wait for command to complete.
89-
time.sleep(100*MICROSECOND)
89+
microcontroller.delay_us(100)
9090

9191
def _i2c_write(self, value):
9292
self.data_buffer[0] = value

0 commit comments

Comments
 (0)