예제 #1
0
파일: SHT1x.cpp 프로젝트: krhoyt/Adobe
/**
 * 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);
}
예제 #2
0
파일: SHT1x.cpp 프로젝트: lthiery/SHT1x
float SHT1x::readInHumidity(){
  int val;                    // Raw humidity value returned from sensor
  waitForResultSHT(_dataPin);
  val = getData16SHT(_dataPin, _clockPin);
  skipCrcSHT(_dataPin, _clockPin);
  return val;
}
예제 #3
0
/**
 * Reads the current raw temperature value
 */
uint16_t sensirion::readTemperatureRaw()
{
  uint16_t _val;

  // Command to send to the SHT1x to request Temperature
  const uint8_t _gTempCmd  = 0b00000011;

  if (millis() - _lastTempMillis < SHT_CACHE_MILLIS ){
	  return _lastTempRaw;
  } else {
	  if ( sendCommandSHT(_gTempCmd, _dataPin, _clockPin) == SHT_SUCCESS ){
		  waitForResultSHT(_dataPin);
		  _val = getData16SHT(_dataPin, _clockPin);
		  uint8_t rxcrc = rev8bits( readCRC(_dataPin, _clockPin ) );
		  uint8_t mycrc = crc8add( 0, _gTempCmd );
		  mycrc = crc8add( mycrc, _val );
		  if (mycrc != rxcrc){
			Serial.println("SHT: crc error");
			Serial.print(" Got:      0x"); Serial.println(rxcrc, HEX);
			Serial.print(" Expected: 0x"); Serial.println(mycrc, HEX);
			return 0;
		  }
		  // cache
		  _lastTempMillis = millis();
		  _lastTempRaw = _val;
		  return (_val);
	  }
  }
  return 0; // error
}
예제 #4
0
파일: SHT1x.cpp 프로젝트: lthiery/SHT1x
/**
 * Read-in Temperature
 */
int SHT1x::readInTemperature()
{
  waitForResultSHT(_dataPin);

  _temperatureRaw= getData16SHT(_dataPin, _clockPin); //store in variable for humidity 
  skipCrcSHT(_dataPin, _clockPin);
  return _temperatureRaw;
}
예제 #5
0
/**
 * Reads current temperature-corrected relative humidity
 */
float sensirion::readHumidity()
{
  uint16_t _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
  const uint8_t _gHumidCmd = 0b00000101;

  // check cache
  if ( millis() - _lastHumMillis < SHT_CACHE_MILLIS){
	  return _lastHumVal;

  } else{
	  // Fetch the value from the sensor
	  if ( sendCommandSHT(_gHumidCmd, _dataPin, _clockPin) == SHT_SUCCESS ){
		  waitForResultSHT(_dataPin);
		  _val = getData16SHT(_dataPin, _clockPin);

		  uint8_t rxcrc = rev8bits( readCRC(_dataPin, _clockPin ) );
		  uint8_t mycrc = crc8add( 0, _gHumidCmd );
		  mycrc = crc8add( mycrc, _val );
		  if (mycrc != rxcrc){
			Serial.println("SHT: crc error");
			Serial.print(" Got:      0x"); Serial.println(rxcrc, HEX);
			Serial.print(" Expected: 0x"); Serial.println(mycrc, HEX);
			return NAN;
		  }

		  // 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 - 25.0 ) * (T1 + T2 * _val) + _linearHumidity;

		  // cache
		  _lastHumVal = _correctedHumidity;
		  _lastHumMillis = millis();

		  return (_correctedHumidity);
	  }
  }
  //error
  return NAN;
}
예제 #6
0
파일: SHT1x.cpp 프로젝트: krhoyt/Adobe
/**
 * 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);
}