LowPowerLab Forum

Hardware support => General topics => Topic started by: SabineT on August 26, 2017, 02:54:45 PM

Title: Setting precision failure in Si7021 library? [fixed]
Post by: SabineT on August 26, 2017, 02:54:45 PM
Hi!

I think in the library for the Si7021 is a failure for setting the precision. The code there is:
// 00 = 14 bit temp, 12 bit RH
// 01 = 12 bit temp, 8 bit RH
// 10 = 13 bit temp, 10 bit RH (default)
// 11 = 11 bit temp, 11 bit RH
void SI7021::setPrecision(byte setting) {
    byte reg = USER1_READ;
    _writeReg(&reg, 1);
    _readReg(&reg, 1);

    reg = (reg & 0xFC) | (setting & 3);
    byte userwrite[] = {USER1_WRITE, reg};
    _writeReg(userwrite, sizeof userwrite);
}

Here bit 0 and 1 are used. The datasheet https://www.silabs.com/documents/public/data-sheets/Si7021-A20.pdf (https://www.silabs.com/documents/public/data-sheets/Si7021-A20.pdf) page 26 shows bit 7 and 0 (see my attached screenshot).

BTW the HTU21D can also be used with this library (it is pin and register compatible), only getDeviceId() will not work.

Best regards, Sabine
Title: Re: Failure in Si7021 library?
Post by: ChemE on August 26, 2017, 05:41:03 PM
This is how I do it with my HTU21D; I only use the lowest resolution for the fastest measurement time:


#define   ELEVEN_BIT_TEMP               B10000011
#define   EIGHT_BIT_RH                  B00000011


You are correct though.  Note that bit 1 should always be 1 since OTP reload isn't recommended to be turned off.
Title: Re: Failure in Si7021 library?
Post by: SabineT on August 27, 2017, 01:03:07 AM
If I'm right, this should work for all possible resolutions:
// 0x00 = 14 bit temp, 12 bit RH (default)
// 0x01 = 12 bit temp, 8 bit RH
// 0x80 = 13 bit temp, 10 bit RH
// 0x81 = 11 bit temp, 11 bit RH
void SI7021::setPrecision(byte setting) {
    byte reg = USER1_READ;
    _writeReg(&reg, 1);
    _readReg(&reg, 1);

    reg = (reg & 0x7E) | (setting & 0x81);
    byte userwrite[] = {USER1_WRITE, reg};
    _writeReg(userwrite, sizeof userwrite);
}

The default is 12bit RH and 14bit Temp!
Title: Re: Failure in Si7021 library?
Post by: SabineT on October 13, 2017, 01:45:23 PM
https://github.com/LowPowerLab/SI7021/blob/master/SI7021.cpp (https://github.com/LowPowerLab/SI7021/blob/master/SI7021.cpp) is still wrong.
Title: Re: Failure in Si7021 library?
Post by: Felix on October 13, 2017, 01:57:22 PM
SabineT,
Your code is correct, those two bits are the 8th bit and 1st bit, the library creator probably overlooked the two bit specification and thought they are first and second bits.
Do you want to submit a PR in github which I can merge or should I just make the changes myself?
Title: Re: Failure in Si7021 library?
Post by: SabineT on October 13, 2017, 02:04:14 PM
Quote from: Felix on October 13, 2017, 01:57:22 PM
SabineT,
Your code is correct, those two bits are the 8th bit and 1st bit, the library creator probably overlooked the two bit specification and thought they are first and second bits.
Do you want to submit a PR in github which I can merge or should I just make the changes myself?
please make the changes yourself, as I'm not so firm doing a PR.
Thanks and best regards!
Title: Re: Setting precision failure in Si7021 library? [fixed]
Post by: Felix on October 13, 2017, 02:31:17 PM
Fixed, thanks for the contribution!
Title: Re: Setting precision failure in Si7021 library? [fixed]
Post by: gianmarko on October 24, 2018, 09:13:39 AM
hi all
i am using the SI7021 for temp/rh readings, and i have noticed something strange
when temperature is low (5-6C or less) and humidity is high (more than 100%, typically in cold foggy weather) the rh readings become erroneous and start indicating again low values
cant tell when the values "invert" as i have a function limiting rh readings to 99.99% (the sensor will indicate rh  values well above 100%, which is "normal" according to data sheet)

i havent been able to reproduce again the issue due to good weather, but i have seen this many times. this happens also using other libraries.

wonder if anyone has noticed something similar