error in SI7021 library?

Started by gianmarko, October 29, 2018, 01:12:03 PM

gianmarko

thanks to some REALLY crappy weather (atmospheric pressure dropped a whopping 43 millibar) i was able to reproduce the error

the four values shown on the display are sensor.getCelsiusHundredths(),sensor.getHumidityPercent(),data.celsiusHundredths, data.humidityBasisPoints

looks like that when the humidity goes above 128% there is an overflow of some sort

i tested other libraries and they all mess things up in this conditions



code is as follows
#include <Wire.h>
#include <SI7021.h>


SI7021 sensor;

#define I2C_ADDRESS 0x3C
#include "SSD1306Ascii.h"
#include "SSD1306AsciiAvrI2c.h"

SSD1306AsciiAvrI2c oled;
void setup() {

    sensor.begin();
    Serial.begin(115200);
     oled.begin(&Adafruit128x64, I2C_ADDRESS);
  oled.setFont(Verdana12);  
//   oled.clear();
//   oled.println(1234567);
//      oled.println(1234567);
 //  delay(1000);
}


void loop() {
oled.clear();
    // temperature is an integer in hundredths
    int temperature = sensor.getCelsiusHundredths();
Serial.println(temperature);
oled.println(temperature);
    
    // humidity is an integer representing percent
    int humidity = sensor.getHumidityPercent();
  Serial.println(humidity);
oled.println(humidity);

    


    


    // get humidity and temperature in one shot, saves power because sensor takes temperature when doing humidity anyway
    si7021_env data = sensor.getHumidityAndTemperature();
    Serial.println(data.celsiusHundredths);
    oled.println(data.celsiusHundredths);
    Serial.println(data.humidityBasisPoints);
    oled.println(data.humidityBasisPoints);
    Serial.println("---");
    delay(10000);
}

LukaQ

I don't think I use the same library, but even still I saw values for humidity that went past 100%, don't know why IC allows that.
And that was not on only one sensor. I think they all do that. BME280 stops at 100%

Both SI's still had offset, that wasn't corrected, but library/ registers allow for values higher than 100%

Felix

Luka,
Thanks for the effort to report and document this problem.
I am sure how to deal with this though. I only have a few Si7021 and they are indoors, no issues but they seem off in general compared to my other BME280 sensors (because of their age?).
So they are planned for replacement at the earliest opportunity. Having said that, and that I do not offer that sensor in any products, my SF Si7021 library fork is no longer maintained and I no longer put active time into it for those reasons, but I can merge fixes if people submit PRs.
https://github.com/LowPowerLab/SI7021

LukaQ

Felix, I find this to be a problem only if you use SI outside, indoors or garage might not be that humid to climb over (to 100) 100%. As far as other things, offsets are as they are, but they all track each other very closely

But as you can see, both SI's are going over, bme stops at 100 as expected.
For SI I don't use (your) library, reading register directly

void readSI7021()
{
  unsigned int data[2];
  Wire.beginTransmission(si7021Addr);
  //Send humidity measurement command
  Wire.write(0xF5);
  Wire.endTransmission();
  delay(100);
  // Request 2 bytes of data
  Wire.requestFrom(si7021Addr, 2);
  // Read 2 bytes of data to get humidity
  if (Wire.available() == 2)
  {
    data[0] = Wire.read();
    data[1] = Wire.read();
  }
  // Convert the data
  float humidity  = ((data[0] * 256.0) + data[1]);
  humidity = ((125 * humidity) / 65536.0) - 6;

  Wire.beginTransmission(si7021Addr);
  // Send temperature measurement command
  Wire.write(0xF3);
  Wire.endTransmission();
  delay(100);
  // Request 2 bytes of data
  Wire.requestFrom(si7021Addr, 2);
  // Read 2 bytes of data for temperature
  if (Wire.available() == 2)
  {
    data[0] = Wire.read();
    data[1] = Wire.read();
  }

  // Convert the data
  float temp  = ((data[0] * 256.0) + data[1]);
  float celsTemp = ((175.72 * temp) / 65536.0) - 46.85;

  dewpout_eu = ( celsTemp - ((100.00f - humidity) / 5.00f) );


It is what it is, not a problem, because you can limit the value to 100 with one line of code

gianmarko

the problem is not that it goes over 100%, thats documented and i coded accordingly. but with high RH once temp drops enough, values goes from 128% to other values that depending on what library is used can be a small positive value or negative values.

i thought about letting you folks know, if felix is not maintaining the library thats ok, perhaps this quirk should be documented

i use this sensor for ambient temperatures and rh, but obviously cant be used outdoors in cold and humid climates
also, i use this sensor in an aviation instrument  i build, with the purpose of giving an alarm if high rh and/or temps are present, condition that can cause carburetor icing and an engine failure, which is not really good...

so for this applications this sensor is useless, and i will stop using it.

maybe ill contact the manufacturer