Exemple #1
0
/**
 * Temperature Request
 */
void SHT1x::requestTemperature()
{
  int _val;
  // Command to send to the SHT1x to request Temperature
  int _gTempCmd  = 0b00000011;
  sendCommandSHT(_gTempCmd, _dataPin, _clockPin);
}
Exemple #2
0
/**
 * 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);
}
Exemple #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
}
Exemple #4
0
void SHT1x::requestHumidity(){

  // Command to send to the SHT1x to request humidity
  int _gHumidCmd = 0b00000101;

  // Fetch the value from the sensor
  sendCommandSHT(_gHumidCmd, _dataPin, _clockPin);
}
Exemple #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;
}
Exemple #6
0
/**
 * 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);
}
Exemple #7
0
uint8_t sensirion::readStatus()
{
  uint16_t _val;

  // Command to send to the SHT1x to request Status
  const uint8_t _gStatCmd  = 0b00000111;

  sendCommandSHT(_gStatCmd, _dataPin, _clockPin);
  // result is immediate with read status.
  //waitForResultSHT(_dataPin);

  shtDelay(1);
  _val = getData16SHT(_dataPin, _clockPin);

  /*
  // Send the required ack
  digitalWrite(_dataPin, LOW);
  pinMode(_dataPin, OUTPUT);
  shtDelay(1);
  digitalWrite(_clockPin, HIGH);
  shtDelay(1);
  digitalWrite(_clockPin, LOW);
  shtDelay(1);
  pinMode(_dataPin, INPUT);
  */

  // end transmission, turn off gpio's
  pinMode(_dataPin, INPUT);
  pinMode(_clockPin, INPUT);

  uint8_t rx_val = _val >> 8;
  uint8_t rx_crc = _val & 0xff;
  uint8_t local_crc = crc8add( 0, _gStatCmd );
  local_crc = crc8add(local_crc, rx_val);

  if (rx_crc != rev8bits(local_crc)){
	Serial.println("SHT: crc error");
	Serial.print(" Got:      0x"); Serial.println(rx_crc, HEX);
	Serial.print(" Expected: 0x"); Serial.println(local_crc, HEX);
  }

  return rx_val;
}