cancel
Showing results for 
Search instead for 
Did you mean: 

How do I verify if my hts221 sensor is giving the correct value and my calculations ?

Anare.1
Associate III

 I am using the hts221 with i2c protocol for doing my calculation based on this reference:Application note for calculating relative humidity.

 

 

hts221.png

 

Observations:

  1. So I tried to read the respective registers and do the calculations as per the datasheet, with assigning s16(H_OUT,H0_TOUT,H1_TOUT) and u16(H0_rH_x2,H1_rH_x2) values and I got a negative value as relative humidity along with -ve values for H_OUT and H0_TOUT(Both of them were defined as s16 type).
  2. But when I switched everything to uint16, which is in contrast to the datasheet, I got a relative humidity of 36% which is ideal and real time value inside a home.

I am wondering why  this strange behavior occurs and is there something, I am doing wrong over here? 

Al l am doing is reading the respective registers and assigning the values like this(eg: here H_OUT):

uint16_t h_out_res=((uint16_t)hum_reading[1]<<8)|(uint16_t)hum_reading[0];

 

 

2 REPLIES 2
Foued_KH
ST Employee

Hello @Anare.1 , 

The HTS221 humidity sensor measures relative humidity and temperature and stores the values as two's complement integers (16-bit words) which can be read over the I2C.

Foued_KH_0-1692889070782.png

I recommend you to refer to the : 
* Figure 3. Reference code for HTS221_Get_Humidity API

** Figure 5. Reference code for HTS221_Get_Temperature API

Foued

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

niccolò
ST Employee

Hi @Anare.1 ,

the answer from Foued is right, check those figure out =)

Anyway, are you sure you are applying the formula correctly?
you can also refer to the drivers to get help =)

If this answers your question, please, mark this as "best answer", by clicking on the "accept as solution" to help the other users of the community

Niccolò