Setting precision failure in Si7021 library? [fixed]

Started by SabineT, August 26, 2017, 02:54:45 PM

SabineT

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 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

ChemE

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.

SabineT

#2
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!


Felix

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?

SabineT

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!

Felix


gianmarko

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