Page 1 of 1

DS1820

Posted: 02 May 2016, 00:34
by stefbo
Dear all,
I changed the Plugin_004_DS_readTemp function such that it gives also correct values for DS1820 or DS18s20 (both with family id 0x10). The code is based on the DallasTemperature-lib 3.7.3

Stefan

Code: Select all

boolean Plugin_004_DS_readTemp(uint8_t ROM[8], float *value)
{
  int16_t DSTemp;
  byte ScratchPad[12];
  
  Plugin_004_DS_reset();
  Plugin_004_DS_write(0x55);           // Choose ROM
  for (byte i = 0; i < 8; i++)
    Plugin_004_DS_write(ROM[i]);
  Plugin_004_DS_write(0x44);

  delay(800);

  Plugin_004_DS_reset();
  Plugin_004_DS_write(0x55);           // Choose ROM
  for (byte i = 0; i < 8; i++)
    Plugin_004_DS_write(ROM[i]);
  Plugin_004_DS_write(0xBE); // Read scratchpad

  for (byte i = 0; i < 9; i++)            // copy 8 bytes
    ScratchPad[i] = Plugin_004_DS_read();

  if (Plugin_004_DS_crc8(ScratchPad, 8) != ScratchPad[8])
    {
      *value=0;
      return false;
    }

  if(ROM[0] == 0x28 ) //DS18B20
    {
      DSTemp = (ScratchPad[1] << 8) + ScratchPad[0];
      *value = (float(DSTemp) * 0.0625);
    }
  else if(ROM[0] == 0x10 ) //DS1820 DS18S20
    {
      DSTemp = (ScratchPad[1] << 11) + ScratchPad[0] << 3;
      DSTemp = ((DSTemp & 0xfff0) << 3) - 16 + 
        (
          ((ScratchPad[7] - ScratchPad[6]) << 7) /
            ScratchPad[7]
        );
    *value = float(DSTemp) * 0.0078125;
  }

  return true;
}


Re: DS1820

Posted: 04 May 2016, 11:37
by bennybubble
Great job, I've been waiting for this for a long time !

Are you planning to incorporate this into GITHUB so everybody can benefit ?

-ben

Re: DS1820

Posted: 07 May 2016, 13:19
by tozett
hello Developer,
could you inform us (here, and/or in the changelog), if you adopted this bugfix/ehancement?
(topic was on the wishlist...)
thankx ;) :D

Re: DS1820

Posted: 08 May 2016, 14:18
by Martinus
tozett wrote:hello Developer,
could you inform us (here, and/or in the changelog), if you adopted this bugfix/ehancement?
(topic was on the wishlist...)
thankx ;) :D
Will be added in R106

Re: DS1820

Posted: 09 May 2016, 09:32
by bennybubble
Thanks !