/** * Reads current temperature-corrected relative humidity */ float SHT1x::readHumidity() { int _val; // Raw humidity value returned from sensor float _linearHumidity; // Humidity with linear correction applied float _correctedHumidity; // Temperature-corrected humidity float _temperature; // Raw temperature value // Conversion coefficients from SHT15 datasheet const float C1 = -4.0; // for 12 Bit const float C2 = 0.0405; // for 12 Bit const float C3 = -0.0000028; // for 12 Bit const float T1 = 0.01; // for 14 Bit @ 5V const float T2 = 0.00008; // for 14 Bit @ 5V // Command to send to the SHT1x to request humidity int _gHumidCmd = 0b00000101; // Fetch the value from the sensor sendCommandSHT(_gHumidCmd, _dataPin, _clockPin); waitForResultSHT(_dataPin); _val = getData16SHT(_dataPin, _clockPin); skipCrcSHT(_dataPin, _clockPin); // Apply linear conversion to raw value _linearHumidity = C1 + C2 * _val + C3 * _val * _val; // Get current temperature for humidity correction _temperature = readTemperatureC(); // Correct humidity value for current temperature _correctedHumidity = _temperature * (T1 + T2 * _val) + _linearHumidity; return (_correctedHumidity); }
float SHT1x::readInHumidity(){ int val; // Raw humidity value returned from sensor waitForResultSHT(_dataPin); val = getData16SHT(_dataPin, _clockPin); skipCrcSHT(_dataPin, _clockPin); return val; }
/** * Read-in Temperature */ int SHT1x::readInTemperature() { waitForResultSHT(_dataPin); _temperatureRaw= getData16SHT(_dataPin, _clockPin); //store in variable for humidity skipCrcSHT(_dataPin, _clockPin); return _temperatureRaw; }
/** * Reads the current raw temperature value */ float SHT1x::readTemperatureRaw() { int _val; // Command to send to the SHT1x to request Temperature int _gTempCmd = 0b00000011; sendCommandSHT(_gTempCmd, _dataPin, _clockPin); waitForResultSHT(_dataPin); _val = getData16SHT(_dataPin, _clockPin); skipCrcSHT(_dataPin, _clockPin); return (_val); }