/SI7021

My personal fork of SI7021 library by @jayjayuk (no license specified, public domain assumed)

Primary LanguageC++

How to Use

After adding to an Arduino compatible IDE of your choice,

#include <Si7021.h>
SI7021 si7021;
void setup()
{
    Serial.begin(9600);
    si7021.begin();
    si7021.setHumidityRes(12);
}
void loop
{
  Serial.print("Humidity : ");
  Serial.println(si7021.readHumidity()) // Print the relative humidity (measured in %)
  Serial.print("Temperature : ");
  Serial.println(si7021.readTemp()); // Prints the temperature (measured in Celsius)
  delay(500);
}

Only readTemp(),readHumidity and the heater functions are tested on an Ardunio Uno/Mega. For more comprehensive examples, take a look at the provided examples in the examples folder or the Arduino IDE (File -> Examples -> Si7021) ###Sensor Resolution Use either setHumidityRes or setTempRes to set the resolution of the sensor, because the sensor register uses two bits to set the resolution for both humidity and temperature so when changing one the other must also change. They are mapped to each other like this :

Temperature bits Humidity bits
14 12
13 10
12 8
11 11
###Heater
The internal heater can be used to test the sensor, to drive off condensation, or to implement dew-point measurement when the Si7021 is used in conjunction with a separate temperature sensor such as another Si7021 (the heater will raise the temperature of the internal temperature sensor).The library currently supports these functions to control the heater :
Function name Use
setHeater Use 1 as parameter for ON, 0 for OFF.
getHeater returns 1 for ON, 0 for OFF.
NOTE: The heater draws an additional 3.09mA(assuming VDD = 3.3V) when turned ON. Although the sensor can support upto 94.2mA, this library does not support setting the heater power due to register access problems.The HTRE bit in the user register is what turns the heater on and off. This register is stored on non-volatile memory to keep its state when power is removed. If the heater is enabled and power is removed before the program had chance to turn it off then the heater will remain enabled the next time it is powered on. The heater has to be explicitly turned off. In the begin() function for this library, a reset procedure will take place and reset the user register to default, so the heater will be turned off and the resolution will also be set to default, 14-bit temperature and 12-bit humidity.
Keep this in mind if testing and swapping sensors/libraries.
###Temperature conversion
Use the library function CtoF or FtoC to convert temperatures from either units. The default readTemp() function always returns measurement in Celsius.
###Float conversion
The library uses floats for humidity and temperature reading, use the library functions floatToInt or intToFloat to convert between them.
###Device information
Function name Use
------------- ----------
getFirmwareVer() returns either 2(for v2), 1(for v1) or 0(Unknown).
getDeviceID() returns either 7021 (for Si7021),7020,7013 or 255(engineering sample).

All rights belong to @jayjayuk.