OK, my C is rusty and I don't know the exact behavior of the compiler, but here's a snippet from thermometer.ino (line 27) that is averaging samples from the Si7021 before outputting a result record:
void loop() {
double rh_accumulator = 0;
double c_accumulator = 0;
for(uint8_t i=0; i < oversample; i++) {
rh_accumulator += si7021.getRH();
c_accumulator += si7021.readTemp();
}
float ambient_rh = rh_accumulator / oversample;
float ambient_c = c_accumulator / oversample;
The oversample variable is 7, so it's not accumulating a lot of samples for the averaging, especially for doubles. I'm not sure how much of an issue assigning the division from a double to a float would cause. You lose precision, but it's not repeated.
Note: If I understood correctly, I believe readTemp() is used here instead of getTemp() because the former uses the value that was acquired at the time that getRH() was called, whereas the latter gets a new sample from the temp sensor.
Then, we have this:
char buf[32];
char *ptr = buf;
char t_buf[16];
dtostrf(ambient_c, 1, 3, t_buf);
char rh_buf[16];
dtostrf(ambient_rh, 1, 3, rh_buf);
The dtostrf() function expects a double. I'm not sure if it cares that it's getting a float since it only needs to use three decimal places for creating the string.
And then it puts together the rest of the output for the serial port.
ptr += sprintf(ptr, "%s", t_buf);
ptr += sprintf(ptr, ",%s", rh_buf);
uint16_t crc = crc16(buf, strlen(buf));
ptr = csv_append_hex_crc16(crc, ptr);
Serial.println(buf);
The remainder of the main loop just updates the onboard LCD.