This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

HDC2022: Energia Example code

Genius 12725 points
Part Number: HDC2022
Other Parts Discussed in Thread: HDC1010, ENERGIA, HDC2080, HDC2021, CC3220S, TMP006

Hello Team,

I was not able to read any useful data out of HDC2022, even after reading SNAU250 and SNAA312 (and data sheet ;-).

So I tried to read the Manufacturer ID but also without success:

Wire.beginTransmission(0x41); // transmit to device #41
Wire.write(0xFC); // set pointer to manufact. ID
Wire.endTransmission(); // stop transmitting
delay(5); // wait 5ms

Wire.requestFrom(0x41, 1,; // request 1 byte from slave device 0x41
a = Wire.read(); // receive one byte

I successfully read temperature and humidity from HDC1010 with Energia...

Thanks for  your help and Best Regards,

Hans

  • Dear Hans - 

    In Energia and Ardunio - it has been my experience that you need to convert the hex to decimal value when using Wire.h. 

    for example, for address 0x41, use decimal see snippet of MID read and complete conversion cycle below to leverage for yourself. 

    Wire.beginTransmission(65); // transmit to HDC2 device address 0x41
    Wire.write(252); // pointer to 0xFC
    Wire.endTransmission(); // stop transmitting

    Wire.requestFrom(65, 2, 1); // request 4 bytes from HDC2 device, starting with register 0xFC (MID, low byte)

    while (Wire.available())
    {
    Wire.readBytes(iBuff_HDC2, 2);
    HDC2_MID_MSB = iBuff_HDC2[1] << 8; // shift left
    HDC2_MID = (HDC2_MID_MSB + iBuff_HDC2080[0]);

    Serial.print(", ");
    Serial.println(HDC2_MID); // print out MID to terminal

    }

    // START_CONVERSION
    /*
    0x01 – 14 bit, 0x03 – temp only
    0x51 – 11 bit, 0x53 – temp only
    0xA1 – 9 bit , 0xA3 – temp only
    */
    Wire.beginTransmission(65); // transmit to HDC2 device address 0x41
    Wire.write(15); // pointer to 0x0F
    Wire.write(01); // 14 bit for both T and %RH
    Wire.endTransmission(); // stop transmitting


    delayMicroseconds(1500); // min delay for 14 bit conversion

    Wire.beginTransmission(65); // transmit to HDC2 device address 0x41
    Wire.write(00); // pointer to 0x00
    Wire.endTransmission(); // stop transmitting
    Wire.requestFrom(65, 4, 1); // request 4 bytes from HDC2 device, starting with register 0x00 (temp MSB)

    //get bytes, shift up temp MSB, do math on temp data, print results, shift up hum MSB, do math on hum data, print results
    while (Wire.available())
    {
    Wire.readBytes(iBuff_HDC2, 4);
    HDC2_temp_MSB = (iBuff_HDC2[1] << 8);
    // HDC2_temp_LSB = (iBuff_HDC2[0]);
    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.00; // do math according to the HDC2010, HDC2021 and HDC2022 datasheets
    //HDC2_temp_celcius = ((float)(HDC2_temp_DEC) / 65536) * 165 - 40.62; // do math according to the HDC2080 datasheet
    HDC2_temp_celcius_comp = HDC2_temp_celcius;
    Serial.print(", ");
    Serial.print(HDC2_temp_celcius); // print out T to terminal
    Serial.print(", ");

    HDC2_hum_MSB = (iBuff_HDC2[3] << 8);
    HDC2_hum_LSB = (iBuff_HDC2[2]);
    HDC2_hum_DEC = (HDC2_hum_MSB + HDC2_hum_LSB); // 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_percentage_comp = HDC2_hum_percentage;
    Serial.print(" ");
    Serial.print(HDC2_hum_percentage); // print out %RH to terminal
    Serial.println(",");

    }

  • Hi Josh,

    thanks for the example code! Meanwhile I found out the root cause: I used the CC3220SEVM and connected the HDC2022 with address 0x41 but I just found out that the TMP006 on the CC3220S EVM has the same address...

    Thanks and Best Regards,

    Hans