summaryrefslogtreecommitdiffstatshomepage
path: root/esp8266/modules/ds18x20.py
diff options
context:
space:
mode:
Diffstat (limited to 'esp8266/modules/ds18x20.py')
-rw-r--r--esp8266/modules/ds18x20.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/esp8266/modules/ds18x20.py b/esp8266/modules/ds18x20.py
index eb22e2ae30..bf06094835 100644
--- a/esp8266/modules/ds18x20.py
+++ b/esp8266/modules/ds18x20.py
@@ -1,6 +1,8 @@
# DS18x20 temperature sensor driver for MicroPython.
# MIT license; Copyright (c) 2016 Damien P. George
+from micropython import const
+
_CONVERT = const(0x44)
_RD_SCRATCH = const(0xbe)
_WR_SCRATCH = const(0x4e)
@@ -43,4 +45,7 @@ class DS18X20:
t = buf[0] >> 1
return t - 0.25 + (buf[7] - buf[6]) / buf[7]
else:
- return (buf[1] << 8 | buf[0]) / 16
+ t = buf[1] << 8 | buf[0]
+ if t & 0x8000: # sign bit set
+ t = -((t ^ 0xffff) + 1)
+ return t / 16