i.e 25C = (25 +25)*512 equals 6400 uint16
howerver the formula in the function is adding a 0.5f as well, this isnt on the spec sheet for the CCS811 and like wise for the humidity calc a 0.5f is added.
I think the formulas should be:
Code: Select all
uint16_t hum_conv = humidity * 512.0f;
uint16_t temp_conv = (temperature + 25.0f) * 512.0f;
Code: Select all
/**************************************************************************/
/*!
@brief set the humidity and temperature compensation for the sensor.
@param humidity the humidity data as a percentage. For 55.5% humidity, pass
in 55.5
@param temperature the temperature in degrees C as a decimal number.
For 25.5 degrees C, pass in 25.5
*/
/**************************************************************************/
void Adafruit_CCS811::setEnvironmentalData(float humidity, float temperature) {
/* Humidity is stored as an unsigned 16 bits in 1/512%RH. The
default value is 50% = 0x64, 0x00. As an example 48.5%
humidity would be 0x61, 0x00.*/
/* Temperature is stored as an unsigned 16 bits integer in 1/512
degrees; there is an offset: 0 maps to -25°C. The default value is
25°C = 0x64, 0x00. As an example 23.5% temperature would be
0x61, 0x00.
The internal algorithm uses these values (or default values if
not set by the application) to compensate for changes in
relative humidity and ambient temperature.*/
uint16_t hum_conv = humidity * 512.0f + 0.5f;
uint16_t temp_conv = (temperature + 25.0f) * 512.0f + 0.5f;
uint8_t buf[] = {
(uint8_t)((hum_conv >> 8) & 0xFF), (uint8_t)(hum_conv & 0xFF),
(uint8_t)((temp_conv >> 8) & 0xFF), (uint8_t)(temp_conv & 0xFF)};
this->write(CCS811_ENV_DATA, buf, 4);
}