From c731cf3e10aeafaf07449547741a19a1435e742c Mon Sep 17 00:00:00 2001 From: affoltep Date: Sun, 4 Feb 2018 10:28:39 +0100 Subject: [PATCH] Remove sleep_us(1) in read_bit and write_bit The 1 us sleep command does not work on pycom devices. It generates a wait time up to 30us. Without waiting time you get an impulse from at least 10us. Removing the waiting time improves significantly the stability of the communication of the new pycom devices as LoPy4, FiPy etc. See whole case at https://forum.pycom.io/topic/2570/onewire-ds18x20-reading-not-stable-with-lopy4-no-problem-with-lopy/ Remark: There would be an additional improvement by adding gc.collect() to read_byte and write_byte, but to keep the lib as basic as possible I propose not to integrate it into the lib --- lib/onewire/onewire.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/onewire/onewire.py b/lib/onewire/onewire.py index ddf14df..5d99ca0 100644 --- a/lib/onewire/onewire.py +++ b/lib/onewire/onewire.py @@ -45,9 +45,7 @@ def read_bit(self): pin(1) # half of the devices don't match CRC without this line i = machine.disable_irq() pin(0) - sleep_us(1) pin(1) - sleep_us(1) value = pin() enable_irq(i) sleep_us(40) @@ -71,7 +69,6 @@ def write_bit(self, value): i = machine.disable_irq() pin(0) - sleep_us(1) pin(value) sleep_us(60) pin(1)