Skip to content

Commit 59a9509

Browse files
committed
esp8266/modules/ds18x20.py: Add support for DS18S20 devices.
1 parent 8e9b98e commit 59a9509

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

esp8266/modules/ds18x20.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def __init__(self, onewire):
1111
self.buf = bytearray(9)
1212

1313
def scan(self):
14-
return [rom for rom in self.ow.scan() if rom[0] == 0x28]
14+
return [rom for rom in self.ow.scan() if rom[0] == 0x10 or rom[0] == 0x28]
1515

1616
def convert_temp(self):
1717
self.ow.reset(True)
@@ -35,4 +35,12 @@ def write_scratch(self, rom, buf):
3535

3636
def read_temp(self, rom):
3737
buf = self.read_scratch(rom)
38-
return (buf[1] << 8 | buf[0]) / 16
38+
if rom[0] == 0x10:
39+
if buf[1]:
40+
t = buf[0] >> 1 | 0x80
41+
t = -((~t + 1) & 0xff)
42+
else:
43+
t = buf[0] >> 1
44+
return t - 0.25 + (buf[7] - buf[6]) / buf[7]
45+
else:
46+
return (buf[1] << 8 | buf[0]) / 16

0 commit comments

Comments
 (0)