HDC2010 I2C Interfacing Problem

Hi everyone,

I have a problem with my HDC2010 temperature and humidity sensor from TI. I wanted to reach out to TI on their E2E forum, but I had a very hard time even registering, so I'm hoping someone might be able to help me here.

Hardware
I'm using a SAM R34 development board called Penguino Feather. It's inserted into a custom PCB. There are 3 sensors on one power branch controlled by a load switch, all of them are interfaced via I2C, but have unique addresses. One of these sensors is the HDC2010 humidity sensor from TI.

Core
I'm using this Arduino core for the SAM R34 ported to PlatformIO.

Software
I'm using the official Arduino library from TI for interfacing this sensor. The whole codebase for my project is nearly a 1000 lines long, though the code, which I use for interfacing the sensor can be boiled down to the "HDC2010 Demo.ino" which I attached to this post.

What works
I'm able to turn on the VCC1 power branch on my board and power all the sensors. I'm able to get the I2C address of all the sensors with the I2C scanner sketch. I'm able to connect to the sensor with the provided library. I'm able to measure temperature with the sensor.readTemp() method and I'm also able to turn on and off the integrated heater and watch the temperature jumb by around 50°C.

What doesn't work
Reading humidity. The sensor.readHumidity() method always returns zero. I tried changing all the settings the sensor has, it didn't help. The sensor clearly works, because all the other methods work. I tried replacing the sensor with a new one, thinking that it might be some random hardware issue, but I got the same result.

From what I've seen, I think that this is a software issue, rather than a software issue. I don't think I'm able to test the I2C interface very much, because I don't currently have a signal analyzer at my disposal. Does anyone recognize a problem I'm not seeing? Thank you.

HDC2010 Demo.ino (1018 Bytes)

Did you copy those Arduino files into your own project ? So you can do some tests ?
I would like to know the value that Wire.read() returns in the function HDC2010::readRed() when the humidity is requested.

Thank you for using a 3.3V processor with a 3.3V sensor 8)

You call it the "official" Arduino library. Well, there is a "official" bug in it :wink:

Wire.requestFrom() should not be followed by a Wire.endTransmission(). I call that common mistake number 2.
The datasheet shows a repeated start, the code does not have that.

Can you remove the openReg() and replace the readReg() with this:

uint8_t HDC2010::readReg(uint8_t reg)
{
  Wire.beginTransmission(_addr);  // Connect to HDC2010
  Wire.write(reg);                // set the specified register
  Wire.endTransmission(false);    // false for a repeated start

  uint8_t reading = 0;            // default return value is 0, when something is wrong
  auto n = Wire.requestFrom(_addr, 1); // Request 1 byte from register
  if (n == Wire.available())      // received the same amount as requested ?
  {
    reading = (uint8_t) Wire.read();   // Read byte

// #define DEBUG_HDC2010          // optional: show raw read data
#ifdef DEBUG_HDC2010    
    Serial.print( "0x");
    Serial.print( reading, HEX);
    Serial.print( ", ");
#endif
  }

  return reading;
}

I did not check the datasheet whether the humidity requires something special.

Since you don't use a Arduino board and not the Arduino IDE, there might be bug in the libraries that you use that we are not aware of :frowning: Have you tried the Arduino IDE 2.0 beta ?

Thank you for the quick response.

Thank you for using a 3.3V processor with a 3.3V sensor 8)

Thanks, I couldn't afford doing such mistakes on a custom PCB.

I would like to know the value that Wire.read() returns in the function HDC2010::readRed() when the humidity is requested.

So, I ran some tests and I'm getting this:

0x0, 0x1, 0x0,

And this:

0x0, 0x0, 0x0,

Alternating forever when calling the readHumidity() method.

When calling readTemp() I get changing responses, for example:

0x0, 0xDA, 0x66,

You call it the "official" Arduino library. Well, there is a "official" bug in it ;)

I meant mainly that it wasn't ported by a maker but it was from the manufacturer.

Since you don't use a Arduino board and not the Arduino IDE, there might be bug in the libraries that you use that we are not aware of :( Have you tried the Arduino IDE 2.0 beta ?

Since it's a new processor it's hard to find good cores for it. I tried ASF, MBED OS, 2 different Arduino cores and this ported core. The Arduino cores could only work with the UF2 bootloader and didn't support debugging, while the one I use now supports Jlink and other programmers. I also find it easier to edit libraries in Platformio than in the classic Arduino IDE.

I tried the Arduino Pro IDE beta, not the Arduino IDE 2.0 beta, they seem similar but I will try it too.

There are things that I don't understand. For example bit 3 in the Configuration Measurement Register is set. But that bit is reserved.

Can you try to use 'HUMID_ONLY' instead of 'TEMP_AND_HUMID'.

Here is an interesting note: GitHub - lime-labs/HDC2080-Arduino: This is the Arduino library for the Texas Instruments HDC2080 temperature & humidity sensor.
The code was adapted for the HDC2080, but also updated.
I run a text compare on both files. The newer HDC2080 code handles the variables and shifting better, but I can not find a serious change of the code.

Perhaps your sketch does not the same initialization as the example from the library.
If your sketch is okay, then I'm out of ideas.
Is there an other working library for the Arduino ?

Can you try to use 'HUMID_ONLY' instead of 'TEMP_AND_HUMID'.

When I do this, 0x4 is added to the first bit, so I get: 0x4, 0x0, 0x0 and 0x4, 0x1, 0x0 alternating. I also tried setting to TEMP_ONLY and measuring humidity, I got 0x2, 0x0, 0x0 constantly.

I run a text compare on both files. The newer HDC2080 code handles the variables and shifting better, but I can not find a serious change of the code.

I've already seen this library, I didn't try it but since you wrote this I though I would give it a try. It works, with the very same results as the original library.

Perhaps your sketch does not the same initialization as the example from the library.
If your sketch is okay, then I'm out of ideas.

My whole humidity header file looks like this:
#pragma once

// Project dependencies
#include <Utils.h>

// External dependencies
#include <HDC2010.h>

class Humidity {
public:
// Initialize the sensor
static void begin()
{
hdc2010.begin();
hdc2010.reset();

// Configure Measurements
hdc2010.setMeasurementMode(HUMID_ONLY); // Set measurements to temperature and humidity
hdc2010.setRate(MANUAL); // Set measurement frequency to 1 Hz
hdc2010.setTempRes(FOURTEEN_BIT);
hdc2010.setHumidRes(FOURTEEN_BIT);

fprintln("\n[Humidity] Sensor initialized.");
}

// Read relative humidity in %
static void read_humidity()
{
hdc2010.triggerMeasurement();
fprintln("[Humidity] Sensor readout complete.");

packet.current.humidity = hdc2010.readHumidity();
}

private:
static HDC2010 hdc2010;
};

HDC2010 Humidity::hdc2010(0x40);

Utils just contains function for Serial printing, like fprintln(), packet is just a variable system for recording the data, neither of these should interfere with the sensor. In the main code, I just initialize the USB interface, I turn on the power branch for the sensor, then I call Humidity::begin(); and after that I call Humidity::read_humidity();

I don't think there is anything wrong with this.

Is there an other working library for the Arduino ?

I couldn't find anything, it's a bit exotic sensor.

You should avoid all weird things. Use a test-sketch to test the sensor with the code from the example, not with your class. Use pullup resistors for SDA and SCL, and power the sensor with 3.3V.

You have to return to the most basic situation and make that work. Do you have a Arduino board with a ATSAMD21G processor ? Then you can use the Arduino IDE.
It is possible that the sensor is broken, but since you don't use 5V, let's assume that your sensor is not broken.

Are there pullup resistors to 3.3V before the sensor is turned on ? Can you measure with a multimeter what the voltages of the sensor are before it is turned on ?
After turning the sensor on, wait 1 second.
After calling triggerMeasurement(), wait 1 second.

You have to return to the most basic situation and make that work. Do you have a Arduino board with a ATSAMD21G processor ? Then you can use the Arduino IDE.

I don't have the bare processor.

Are there pullup resistors to 3.3V before the sensor is turned on ? Can you measure with a multimeter what the voltages of the sensor are before it is turned on ?

The sensor and pullups are on the same power branch, enabled by a load switch. I think the resistors are powered a few microseconds sooner, since the sensor needs to charge its caps. The voltage is 3.27V.

Anyway, a weird thing happened. I tried the barebone sketch I sent in the first post, again. Now, it worked. I fiddled with the settings, it continued working. I'm attaching the updated sketch.

Weird thing is that when I remove sensor.readTemp(), the humidity reading is 0, even when the measurement mode is set to HUMID_ONLY. I don't understand why the sensor requires the temperature to be read. Do you see anything in the datasheet, which would suggest this?

The readings are ranging only from 12 to 14% RH, but I think that might be damage of the sensing element, or it's still coated in flux. Since it's a small BGA and the sensing element is on the bottom, it's hard to clean the residual flux. Anyway, I'm just happy that it's not 0 anymore.

NewDemo.ino (903 Bytes)

The example with the library uses a delay, between triggerMeasurement() and readHumidity().
Your code is different from the example, I think it might be the way you use the library, but that is just a guess.

I think we can assume that the timing on the I2C bus is not a problem and neither the Wire library that you use. That leaves the library / code / datasheet.

Okay, I submerged the sensor into isopropyl alcohol and then vaporized it for a few times to get rid of the flux. I'm happy to conclude that the sensor now works very well and responds to the changes in humidity. I don't currently have anything else to calibrate it but the measurements seem fine.

I didn't figure out how to get the humidity measurement without also calling readTemp(), but I don't think it's such a problem. So I would mark this topic as solved, though I'm not completely sure how to do that.

Solution
There was no hardware problem, except that the sensing surface of the sensor was covered in flux, causing worse humidity response.

The main problem was in the code and library interfacing the sensor. I'm attaching the fixed library, the working standalone demo and the humidity class implementation, which I use in my code.

Thanks a lot to @Koepel for helping me fix this issue.

HDC2010 modified.zip (9.27 KB)

Humidity Class.h (1.99 KB)

HDC2010_standalone_example.ino (953 Bytes)

Thanks for telling us! That is something to remember. +1 karma for not giving up and finding the problem :wink:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.