SBOA631 August 2025 HDC1010 , HDC1080 , HDC2010 , HDC2021 , HDC2022 , HDC2080 , HDC3020 , HDC3020-Q1 , HDC3021 , HDC3021-Q1 , HDC3022 , HDC3022-Q1 , HDC3120 , HDC3120-Q1
This section demonstrates how to configure and read measurements from an HDC302x device using highest resolution settings. All example codes utilize a global variable for the I2C address and can be easily changed based off the user’s device configuration.
Before measurements can be read, the device must first be configured. This is done by sending a specific command sequence to the HDC302x. An illustration of the configuration is shown in Figure 2-6.
Wire.beginTransmission(0x44); // Initiate communication with HDC302x
Wire.write(0x24); // Write Command MSB to device.
Wire.write(0x00); // Write Command LSB to device.
Wire.endTransmission();
delay(25); //wait 25ms before reading
A delay is required to ensure the measurement conversion has completed before initiating a read. For this example, a 15ms delay was used since the measurement configuration is based on the highest resolution and repeatability. Engineers should consult the data sheet prior to setting the appropriate delay, though a minimum delay of 15ms should be implemented.
void loop() {
float humidity;
float temp;
// send device command for highest repeatability
Wire.beginTransmission(0x44);
Wire.write(0x24); //send MSB of command
Wire.write(0x00); //command LSB
Wire.endTransmission();
delay(15); //wait 15ms before reading
Wire.requestFrom(0x44, 6); //request 6 bytes from HDC device
Wire.readBytes(HDC_DATA_BUFF, 6); //move 6 data bytes into buffer
temp = getTemp(HDC_DATA_BUFF);
Serial.print("Temp (C): "); // print final temp value
Serial.println(temp);
delay(1000); // wait 1 second (optional)
humidity = getHum(HDC_DATA_BUFF);
Serial.print("Humidity (RH): "); // print final humidity value
Serial.print(humidity);
Serial.println("%");
delay(1000); // wait 1 second (optional)
}
Data Conversion Functions
Temperature and humidity are calculated using the formulas provided in the HDC302x data sheet:
// function processes raw temperature values and returning final value
float getTemp(uint8_t humBuff[]) {
float tempConv;
float celsius;
TEMP_MSB = humBuff[0] << 8 | humBuff[1]; //shift 8 bits of data in
//first array index to get
//MSB then OR with LSB
tempConv = (float)(TEMP_MSB); // convert uint8_t temp value
celsius = ((tempConv / 65535) * 175) - 45; // calculate celcius
return celsius;
}
// function for processing raw humidity values and returning final value
float getHum(uint8_t humBuff[]) {
float humConv;
float humidity;
HUM_MSB = (humBuff[3] << 8) | humBuff[4]; //shift 8 bits of data in
//first array index to get
//MSB then OR with LSB
humConv = (float)(HUM_MSB); // convert uint8_t humidity value
humidity = (humConv / 65535) * 100; // calculate humidity
return humidity;
}
Note on Buffer Structure
The six-byte buffer HDC_DATA_BUFF contains:
Although this example does not use the CRC bytes, the bytes are included in the buffer for completeness and can be checked for data integrity if needed.
Visit the following link to view the full sample code for the HDC302x in Trigger-On Demand Mode.