Browse Source

Also support DS18S20

The DS18S20 has only 1 fractional bit whereas DS18B20 has 4, and their
temperature register alignment differs. Check the family code to choose
the correct multiplier for both devices.

Closes #610

Signed-off-by: Nick Andrew <nick@nick-andrew.net>
Nick Andrew 8 years ago
parent
commit
53eee16894
1 changed files with 5 additions and 0 deletions
  1. 5 0
      lua_examples/onewire-ds18b20.lua

+ 5 - 0
lua_examples/onewire-ds18b20.lua

@@ -41,6 +41,11 @@ else
           print("CRC="..crc)
           if (crc == data:byte(9)) then
              t = (data:byte(1) + data:byte(2) * 256) * 625
+             if (addr:byte(1) == 0x28) then
+                t = t * 625  -- DS18B20, 4 fractional bits
+             else
+                t = t * 5000 -- DS18S20, 1 fractional bit
+             end
              t1 = t / 10000
              t2 = t % 10000
              print("Temperature= "..t1.."."..t2.." Centigrade")