Left here for archival purposes.

User avatar
By manawyrm
#4805 Hello,

I'm currently trying to get a DS18B20 module to work with the ESP8266.

I'm using the lib: https://github.com/nodemcu/nodemcu-firm ... 8b20.EN.md
with the following code:

Code: Select allds18b20 = require("ds18b20")
ds18b20.setup(8)
addrs = ds18b20.addrs()
if (addrs ~= nil) then
  print("Total DS18B20 sensors: "..table.getn(addrs))
end
print(ds18b20.readNumber(addrs[1],ds18b20.C))
print(ds18b20.readNumber(addrs[1],ds18b20.F))
print(ds18b20.readNumber(addrs[1],ds18b20.K))


This returns:
Code: Select allTotal DS18B20 sensors: 1
2 5625
36 6125
275 7125


As you can see, it is reading a temperature of 2,5625°C, which is ofcourse wrong.
I tested the hardware setup by connecting the datapin to an arduino and got the correct readout of about 21°C.

My DS18B20 is a geniune one, not a chinese clone. Any ideas what could be wrong here?

Thanks,
Tobias
User avatar
By manawyrm
#4809 Hm, got it to work.

As it turns out, my sensors are DS18S20, which are similar but not identical. They have a slightly different way of storing the data.

I added this into the routine to get the sensors to work.
Code: Select allt = t * 8
 if (data:byte(8) == 0x10) then
    t = BitAND(t, 0xFFF0) + 12 - data:byte(7)
end
User avatar
By sfinx
#17643
manawyrm wrote:Hm, got it to work.

As it turns out, my sensors are DS18S20, which are similar but not identical. They have a slightly different way of storing the data.

I added this into the routine to get the sensors to work.
Code: Select allt = t * 8
 if (data:byte(8) == 0x10) then
    t = BitAND(t, 0xFFF0) + 12 - data:byte(7)
end

Could you show the complete script you're using? I'm also trying to use a DS18S20 but can't get the readings right. Thanks!