I have HH100D humidity sensor. It outputs a frequency signal, which I know how to handle. However, it also has a small EEPROM with calibration values that is available via I2C. Those values are necessary to get the actual humidity.
The problem is, that I'm very new to I2c. I cannot figure out how to read out those bytes. I've googled for half a day and still got no solution.
For the sensitivity you need to request 2 bytes from address 10 - byte 10 and 11
For the offset you need to request 2 bytes from address 12 - byte 12 and 13
The code for this is something like (as I have no such sensor I can't try it out
int readSensitivity( int deviceaddress ) // deviceaddress is 1 according to datasheet
{
// SET ADDRESS
Wire.beginTransmission(deviceaddress);
Wire.send(10); // address for sensitivity
Wire.endTransmission();
// REQUEST RETURN VALUE
Wire.requestFrom(deviceaddress, 2);
// COLLECT RETURN VALUE
int rv = 0;
for (int c = 0; c < 2; c++ )
if (Wire.available()) rv = rv * 256 + Wire.receive();
return rv;
}
void updateHumidity(boolean force){
FreqCounter::f_comp= 8; // Set compensation to 12
FreqCounter::start(1000); // Start counting with gatetime of 1000ms
while (FreqCounter::f_ready == 0) // wait until counter ready
freq=FreqCounter::f_freq; // read result
int sens = readSensitivity(81);
int offset = readOffset(81);
int RH = (offset-freq)*sens/4096;
lcd.setCursor(0,1);lcd.print(RH);
}
your functions
The only difference is that device address is 81. I first tried 1, as specified in HH100D datasheet, and it did not work. Then I looked through M24C02 datasheet, and found that in my case it should be b1010 001 = d81.
For my sensor, offset = 7746 and sensitivity = 370.
By the way, the sensor works fine without any logic-level converter(sensor is 3.3v and arduino is 5v). I added 4k7 pullup resistors from +3.3v.
OK, question arises if you need to read the Sensitivity and Offset every time? If not keeping those two numbers in memory makes the code a bit simpler. You just request them once in setup().
Furthermore it is not clear from the spec if Sensitivity and Offset are signed or unsigned integers. Looking at the values it seems not relevant but when multiplying all those ints one may get an overflow which causes errors. Better make the vars unsigned long to prevent this.
Could you post the whole code for the people who find this thread later?
Sure I will - or even I will create a library for HH100D.
However, I'm still rewriting the code... (there's another problem, but I almost solved it - Arduino Forum). As soon as I finalize it, I will publish the code.
As for reading calibration values, I did that only once. Then I use them hard-coded in my project (because I'm not going to change the sensor), like:
RH = (7746-freq)*370/4096;
I've even disconnected the sensor from I2C.
As I understand, neither offset nor sensitivity will exceed the range of [0;10000].
But be aware that integer or long division is faster than float multiplication
If you don't need (and use) float in your sketch the footprint will be smaller too. Precission can be reached by multiplying all number with 10 to emulate one decimal digit.
Hello I am using the sensor HH10D, I have not put pull-up resistors to 3.3 V is needed? the value received by the serial port of RH is 6.00% as the humidity?