//variables to declare uint16_t HDC2_INT_REG; uint16_t HDC2_ALL_REG; uint8_t iBuff_INT_REG2[1]; uint8_t iBuff_ALL_REG[12]; uint16_t HDC2_hum_MSB; uint16_t HDC2_temp_MSB; uint16_t HDC2_hum_DEC; uint16_t HDC2_temp_DEC; float HDC2_hum_percentage; float HDC2_temp_celcius; float HDC2_temp_F; uint8_t iBuff_HDC2[4]; float HDC2_hum_offset = 0; float HDC2_hum_offset_2 = 0; uint8_t iBuff_TMP[2]; float TMP_BYTES; int val2 = 0; //variable for triggering read when data is ready from DRDY/INT pin on HDC2080 uint8_t iBuff_INT_REG[1]; float temp_slope; float hum_slope; float START_TEMP = 0; float AMB_TEMP = 0; float TEMP_RISE = 0; float START_HUM = 0; float START_TEMP_2 = 0; float AMB_TEMP_2 = 0; float TEMP_RISE_2 = 0; float START_HUM_2 = 0; int i = 1; int j = 1; int count1 = 0; int count2 = 0; //LUT example, works on HDC2 with 0.31" PCB and cutout around part float LUT_temp_humidity_HDC2 [9][4] = { //30 25 20 15 {43.50, 43.50, 43.50, 43.50}, //60 -> 65 {43.50, 43.50, 43.50, 43.50}, //55 -> 60 {43.50, 43.50, 43.50, 43.50}, //50 -> 55 {43.50, 43.50, 43.50, 43.50}, //45 -> 50 {44.75, 44.75, 44.75, 44.75}, //40 -> 45 {44.75, 44.75, 44.75, 44.75}, //35 -> 40 {44.75, 44.75, 44.75, 44.75}, //30 -> 35 {44.75, 44.75, 44.75, 44.75}, //25 -> 30 {44.75, 44.75, 44.75, 44.75} //20 -> 25 }; case '1': { float from_LUT = 0; //*** int temp_index = 0; int humidity_index = 0; Serial.println("HDC2 (on LTD BOARD) %RH OFFSET CORRECTION"); digitalWrite(LED, HIGH); // turns red LED on solid (indicating calibration routine is running) digitalWrite(LED2, LOW); // turns off green LED (for heartbeat in normal operation): Wire.beginTransmission(0x41); // transmit to HDC2 device address 0x41 Wire.write(0x0F); // Register 0x0F Wire.write(0x01); // HDC2 start conversion (0x01) 14 bit Wire.endTransmission(); // stop transmitting delayMicroseconds(1500); // delay set for 14 bit conversion time for temp and humidity together - typical should be ~1270uSec Wire.beginTransmission(0x41); // transmit to HDC2 device address 0x41 Wire.write(0x04); // pointer Wire.endTransmission(); // stop transmitting Wire.requestFrom(0x41, 1, 1); // request 1 bytes from HDC2 device, register 0x04 (should be 0x80) Wire.readBytes (iBuff_INT_REG, 1); HDC2_INT_REG = iBuff_INT_REG[0]; if (HDC2_INT_REG == 0x80) { Wire.beginTransmission(0x41); // transmit to HDC2 device address 0x41 Wire.write(0x00); // pointer Wire.endTransmission(); // stop transmitting Wire.requestFrom(0x41, 4, 1); // request 4 bytes from HDC2 device, registers 0x00 through 0x03 while (Wire.available()) { Wire.readBytes(iBuff_HDC2, 4); HDC2_temp_MSB = (iBuff_HDC2[1] << 8); // shift left HDC2_temp_DEC = (HDC2_temp_MSB + iBuff_HDC2[0]); // get value for calculation, made from iBuff index array values 0 and 1 for temp reading. HDC2_temp_celcius = ((float)(HDC2_temp_DEC) / 65536) * 165 - 40.62; // do math according to the HDC2080 datasheet // HDC2_temp_celcius = ((float)(HDC2_temp_DEC) / 65536) * 165 - 40; // do math according to the HDC2010, HDC2021, HDC2022 datasheets, comment in when using those devices, comment out line above START_TEMP_2 = HDC2_temp_celcius; AMB_TEMP_2 = START_TEMP_2; Serial.print(","); Serial.print("AMBIENT TEMP :"); Serial.print(AMB_TEMP_2); // print out start temperature to terminal Serial.println(","); HDC2_hum_MSB = iBuff_HDC2[3] << 8; // shift left HDC2_hum_DEC = (HDC2_hum_MSB + iBuff_HDC2[2]); // get value for calculation, made from iBuff index array values 3 and 2 for humidity reading. HDC2_hum_percentage = ((float)(HDC2_hum_DEC) / 65536) * 100; // do math according to the HDC2 datasheet START_HUM_2 = HDC2_hum_percentage; Serial.print("AMBIENT HUMIDITY :"); Serial.print(START_HUM_2); // print out %RH value to terminal Serial.println(","); //temp col index 15, 21, 25, 30C // get the temp index temp_index = 0; if ((HDC2_temp_celcius > 0) && (HDC2_temp_celcius <= 15)) temp_index = 0; else if ((HDC2_temp_celcius > 15) && (HDC2_temp_celcius <= 21)) temp_index = 1; else if ((HDC2_temp_celcius > 21) && (HDC2_temp_celcius <= 25)) temp_index = 2; else if ((HDC2_temp_celcius > 25) && (HDC2_temp_celcius <= 30)) temp_index = 3; // humidity index - 60,55,50,45,40,35,30,25,20 // find humidy index in LUT. humidity_index = int((HDC2_hum_percentage - 20) / 5); if (humidity_index > 8) humidity_index = 8; if (humidity_index < 0) humidity_index = 0; humidity_index = 8 - humidity_index; //look up the table to set the threshold from_LUT = LUT_temp_humidity_HDC2[humidity_index][temp_index]; Serial.println("Calculated Indexes: "); Serial.print("Humidity Index :"); Serial.println(humidity_index); Serial.print("Temperature Index :"); Serial.println(temp_index); Serial.print("Look up table value (in C) :"); Serial.println(from_LUT); // Serial.println(","); } } // turn heater on Wire.beginTransmission(0x41); // transmit to HDC2 device address 0x41 Wire.write(0x0E); // Register 0x0E Wire.write(0x08); // HDC2 heater bit on Wire.endTransmission(); // stop transmitting do { Wire.beginTransmission(0x41); // transmit to HDC2 device address 0x41 Wire.write(0x0F); // Register 0x0F Wire.write(0x01); // HDC2 start conversion (0x01) 14 bit Wire.endTransmission(); // stop transmitting delayMicroseconds(1500); // delay set for 14 bit conversion time for temp and humidity together - typical should be ~1270uSec Wire.beginTransmission(0x41); // transmit to HDC2 device address 0x41 Wire.write(0x04); // pointer Wire.endTransmission(); // stop transmitting Wire.requestFrom(0x41, 1, 1); // request 1 bytes from HDC2 device, register 0x04 (should be 0x80) Wire.readBytes (iBuff_INT_REG, 1); HDC2_INT_REG = iBuff_INT_REG[0]; if (HDC2_INT_REG == 0x80) { Wire.beginTransmission(0x41); // transmit to HDC2 device address 0x41 Wire.write(0x00); // pointer Wire.endTransmission(); // stop transmitting Wire.requestFrom(0x41, 4, 1); // request 4 bytes from HDC2 device, registers 0x00 through 0x03 while (Wire.available()) { Wire.readBytes(iBuff_HDC2, 4); HDC2_temp_MSB = (iBuff_HDC2[1] << 8); // shift left HDC2_temp_DEC = (HDC2_temp_MSB + iBuff_HDC2[0]); // get value for calculation, made from iBuff index array values 0 and 1 for temp reading. HDC2_temp_celcius = ((float)(HDC2_temp_DEC) / 65536) * 165 - 40.62; // do math according to the HDC2080 datasheet // HDC2_temp_celcius = ((float)(HDC2_temp_DEC) / 65536) * 165 - 40; // do math according to the HDC2010, HDC2021, HDC2022 datasheets, comment in when using those devices, comment out line above // Serial.print(","); Serial.print(HDC2_temp_celcius); // print out temperature to terminal Serial.print(","); TEMP_RISE_2 = HDC2_temp_celcius - AMB_TEMP_2; Serial.print(TEMP_RISE_2); // print out temperature to terminal Serial.print(","); temp_slope = (START_TEMP_2 - HDC2_temp_celcius) / (count1 - i) ; i++; count1++; START_TEMP_2 = HDC2_temp_celcius; HDC2_hum_MSB = iBuff_HDC2[3] << 8; // shift left HDC2_hum_DEC = (HDC2_hum_MSB + iBuff_HDC2[2]); // get value for calculation, made from iBuff index array values 3 and 2 for humidity reading. HDC2_hum_percentage = ((float)(HDC2_hum_DEC) / 65536) * 100; // do math according to the HDC2 datasheet // HDC2_hum_offset = HDC2_hum_percentage; // HDC2_hum_offset = HDC2_hum_percentage / 2; HDC2_hum_offset_2 = HDC2_hum_percentage; hum_slope = (START_HUM - HDC2_hum_percentage) / (count2 - j) ; j++; count2++; START_HUM_2 = HDC2_hum_percentage; Serial.print(HDC2_hum_offset_2); // print out %RH offset to terminal Serial.print(","); hum_slope = 0 - hum_slope; // make hum_slope a positive value Serial.println(temp_slope); Serial.print(","); } } } while (TEMP_RISE_2 <= from_LUT); //HDC2080 on LTD with cutout //Reset variables & counters for next time using the calibration routine i = 1; j = 1; count1 = 0; count2 = 0; START_TEMP_2 = 0; Serial.println("DONE"); // Print humidity board header // turn heater off Wire.beginTransmission(0x41); // transmit to HDC2 device address 0x41 Wire.write(0x0E); // Register 0x0E Wire.write(0x00); // HDC2 heater bit off Wire.endTransmission(); // stop transmitting delay(50); // enable DRDY/INT pin feature Wire.beginTransmission(0x41); // transmit to HDC2 device address 0x41 Wire.write(0x07); // Register 0x07 Wire.write(0x80); // HDC2 DRDY/INT setting Wire.endTransmission(); // stop transmitting delay(2); // config interrupt Wire.beginTransmission(0x41); // transmit to HDC2 device address 0x41 Wire.write(0x0E); // Register 0x0E Wire.write(0x06); // HDC2 config (for one shot) Wire.endTransmission(); digitalWrite(LED, LOW); // turns red LED off (indicating calibration routine is complete) delay(2); break; }