• Hi,
    I know that is because the B20 differs from S20, but could u recomend, how I can get correct temp? Now I have 3,25 °C when real temp is ~25. Will It be correct to just multiple to some koef. and\or shift the value?
    Sorry for possible offtop.
    Thanks.

  • Hi, I think there is a thread on this here: http://forum.espruino.com/conversations/­317/#comment3172

    Please let me know how you get on - it'd be nice to improve the DS18B20 library so it works with both

  • Hello Andrey,
    for me it works this way. Type of sensor can be recognized in device info of sensor
    regards
    Juergen

    function OneWireTemp(pin){
      var me = this;
      me.ow = new OneWire(pin);
      me.device = me.ow.search()[0];
      me.deviceType = me.device - ((me.device >> 8) << 8);
      me.readRegister = function(callback,n){
        if(!n)n = 8;
        var reg = [];
        me.ow.reset();me.ow.select(me.device);me­.ow.write(0x44,true);
        me.ow.reset();me.ow.select(me.device);me­.ow.write(0xBE);
        for(var i = 0; i < n; i++){reg.push(me.ow.read());}
        return reg;
      };
      me.getTemp = function(callback){
        var t,reg = me.readRegister(2);
        t = reg[0] + (reg[1] << 8); if(t > 32767) t -= 65536;
        switch(me.deviceType){
          case 40: t = t / 16; break;//ds18B20
          case 16: t = t / 2; break;//ds18S20
        }
        return t;
      };
    }
    
  • Hi JumJum,

    Thanks! By the way, when you post code in the forum please could you surround it with 3 backticks? See https://help.github.com/articles/github-­flavored-markdown#fenced-code-blocks

    I've just updated your post above, and it makes it syntax highlight correctly :)

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

DS18S20 instead of DS18B20 gives the wrong value. How I can manage It?

Posted by Avatar for Andrey @Andrey

Actions