cancel
Showing results for 
Search instead for 
Did you mean: 

HTS221 Temperature sensor

JMerc
Associate

Hello,

I have one Arduino MKR ENV board which has this sensor. The problem is that I'm reading higher temperature values than expected.

The routines that I use are :

For calibration:

 /**
 
 * HTS221_readCalibration
 
 *
 
 * Reads calibration values
 
 * @return char - != 0 if any error happened
 
 */
 
char HTS221::readCalibration(void) {
 
	unsigned char T0_degC_x8_H;
 
	unsigned char T0_degC_x8_L;
 
	unsigned char T1_degC_x8_H;
 
	unsigned char T1_degC_x8_L;
 
	
 
	unsigned char H0_rh_x2;
 
	unsigned char H1_rh_x2;
 
	
 
	int temp;
 
 
 
	DEBUG("HTS221 - Reading Calibration: ");
 
	DEBUG("\n\r");
 
	
 
	/**
 
 * Humidity calibration values
 
 */
 
	if((temp = readReg(HTS221_H0_RH_X2)) < 0) return 1;
 
	H0_rh_x2 = (unsigned char)temp;
 
	H0_rh = H0_rh_x2 / 2.0;
 
	
 
	DEBUG("HTS221 - H0_rh: ");
 
	DEBUGF(H0_rh, 2);
 
	DEBUG("\n\r");
 
	
 
	if((temp = readReg(HTS221_H1_RH_X2)) < 0) return 2;
 
	H1_rh_x2 = (unsigned char)temp;
 
	H1_rh = H1_rh_x2 / 2.0;
 
	
 
	DEBUG("HTS221 - H1_rh: ");
 
	DEBUGF(H1_rh, 2);
 
	DEBUG("\n\r");
 
	
 
	if((temp = readReg(HTS221_H0_T0_OUT_L)) < 0) return 3;
 
	H0_T0_out = (unsigned char)temp;
 
	if((temp = readReg(HTS221_H0_T0_OUT_H)) < 0) return 4;
 
	H0_T0_out |= ((unsigned char)temp << 8);
 
	
 
	DEBUG("HTS221 - H0_T0_out: ");
 
	DEBUGF(H0_T0_out, DEC);
 
	DEBUG("\n\r");
 
	
 
	if((temp = readReg(HTS221_H1_T0_OUT_L)) < 0) return 5;
 
	H1_T0_out = (unsigned char)temp;
 
	if((temp = readReg(HTS221_H1_T0_OUT_H)) < 0) return 6;
 
	H1_T0_out |= ((unsigned char)temp << 8);
 
	
 
	DEBUG("HTS221 - H1_T0_out: ");
 
	DEBUGF(H1_T0_out, DEC);
 
	DEBUG("\n\r");
 
	
 
	
 
	/**
 
 * Temperature calibration values
 
 */
 
	if((temp = readReg(HTS221_T1T0_MSB)) < 0) return 7;
 
	DEBUG("HTS221_T1T0_MSB - 0x35: 0x");
 
	DEBUGF(temp, HEX); DEBUG(" decimal="); DEBUGF(temp, DEC);
 
	DEBUG("\n\r");
 
	T0_degC_x8_H = (unsigned char)(temp & 0x03);
 
	
 
	
 
	if((temp = readReg(HTS221_T0_DEGC_X8)) < 0) return 8;
 
	T0_degC_x8_L = (unsigned char)temp;
 
	DEBUG("HTS221_T0_DEGC_X8 - 0x32: 0x");
 
	DEBUGF(T0_degC_x8_L, HEX); DEBUG(" decimal="); DEBUGF(T0_degC_x8_L, DEC);
 
	DEBUG("\n\r");
 
	
 
	
 
	T0_degC = (((T0_degC_x8_H << 8) | T0_degC_x8_L)) / 8.0;
 
	DEBUG("HTS221 - T0_degC: ");
 
	DEBUGF(T0_degC, 2);
 
	DEBUG("\n\r");
 
	
 
	if((temp = readReg(HTS221_T1T0_MSB)) < 0) return 9;
 
	T1_degC_x8_H = (unsigned char)((temp & 0x0C) >> 2);
 
	
 
	if((temp = readReg(HTS221_T1_DEGC_X8)) < 0) return 10;
 
	T1_degC_x8_L = (unsigned char)temp;
 
	DEBUG("HTS221_T1_DEGC_X8 - 0x33: 0x");
 
	DEBUGF(T1_degC_x8_L, HEX); DEBUG(" decimal="); DEBUGF(T1_degC_x8_L, DEC);
 
	DEBUG("\n\r");
 
	
 
	T1_degC = ((T1_degC_x8_H << 8) | T1_degC_x8_L) / 8.0;
 
	DEBUG("HTS221 - T1_degC: ");
 
	DEBUGF(T1_degC, 2);
 
	DEBUG("\n\r");
 
	
 
	
 
	if((temp = readReg(HTS221_T0_OUT_L)) < 0) return 11;
 
	T0_out = (unsigned char)temp;
 
	DEBUG("HTS221_T0_OUT_L - 0x3C: 0x");
 
	DEBUGF(T0_out, HEX); DEBUG(" decimal="); DEBUGF(T0_out, DEC);
 
	DEBUG("\n\r");
 
	
 
	if((temp = readReg(HTS221_T0_OUT_H)) < 0) return 12;
 
	DEBUG("HTS221_T0_OUT_H - 0x3D: 0x");
 
	DEBUGF(temp, HEX); DEBUG(" decimal="); DEBUGF(temp, DEC);
 
	DEBUG("\n\r");
 
	
 
	T0_out |= ((unsigned char)temp << 8);
 
	DEBUG("HTS221 - T0_out: ");
 
	DEBUGF(T0_out, DEC);
 
	DEBUG("\n\r");
 
	
 
	if((temp = readReg(HTS221_T1_OUT_L)) < 0) return 13;
 
	T1_out = (unsigned char)temp;
 
	DEBUG("HTS221_T1_OUT_L - 0x3E: 0x");
 
	DEBUGF(T1_out, HEX); DEBUG(" decimal="); DEBUGF(T1_out, DEC);
 
	DEBUG("\n\r");
 
	
 
	if((temp = readReg(HTS221_T1_OUT_H)) < 0) return 14;
 
	DEBUG("HTS221_T1_OUT_H - 0x3F: 0x");
 
	DEBUGF(temp, HEX); DEBUG(" decimal="); DEBUGF(temp, DEC);
 
	DEBUG("\n\r");
 
	
 
	T1_out |= ((unsigned char)temp << 8);
 
	DEBUG("HTS221 - T1_out: ");
 
	DEBUGF(T1_out, DEC);
 
	DEBUG("\n\r");
 
	
 
	return 0;
 
}

For reading the values

float HTS221::readTemperature(void) {
 
	unsigned char temp;
 
	int value;
 
	float result;
 
	
 
	value = readReg(HTS221_TEMP_OUT_H);
 
	temp = (unsigned char)readReg(HTS221_TEMP_OUT_L);
 
	value = (value << 8) | temp;
 
	
 
	DEBUG("HTS221 - T_OUT: ");
 
	DEBUGF(value, DEC);
 
	DEBUG("\n\r");
 
	
 
	result = (((float)value - T0_out)/(T1_out - T0_out)) * (T1_degC - T0_degC) + T0_degC;
 
	
 
	DEBUG("HTS221 - Temperature value readed: ");
 
	DEBUGF(result, 2);
 
	DEBUG("\n\r");
 
	
 
	return result;
 
}

The registers' values are:

HTS221_T1T0_MSB - 0x35: 0xC4 decimal=196

HTS221_T0_DEGC_X8 - 0x32: 0xA7 decimal=167

HTS221 - T0_degC: 20.87

HTS221_T1_DEGC_X8 - 0x33: 0x14 decimal=20

HTS221 - T1_degC: 34.50

HTS221_T0_OUT_L - 0x3C: 0x3 decimal=3

HTS221_T0_OUT_H - 0x3D: 0x0 decimal=0

HTS221 - T0_out: 3

HTS221_T1_OUT_L - 0x3E: 0xEB decimal=235

HTS221_T1_OUT_H - 0x3F: 0x2 decimal=2

HTS221 - T1_out: 747

HTS221 - T_OUT: 354

HTS221 - Temperature value readed: 27.30

Is it problem of a faulty device?

Thanks in advance

Jordi Mercader

7 REPLIES 7
Eleon BORLINI
ST Employee

Hi @JMerc​ , sorry for the late answer, but it could be a lot-related issue... Basically your issue is that you are reading a temperature value constantly over a certain value, or does the value oscillate between a correct t range and higher temperatures? Do you have the possibility to test another device? Regards

JMerc
Associate

Hi Eleon,

Thanks for your answer.

The reading is always around 3ºC to 5ºC above the real temperature.

I have another MKR ENV board and the readings were similar.

Can you check if the calibration parameters are faulty?

Best regards

Jordi Mercader

​Hi Jordi, please check this thread if can be of your help. No issues about humidity value? Can you share the regmap dup described at that link? Regards

Hello @JMerc​,

I'm facing exactly the same issue on a custom board and on a BLUETILE eval board. Computed temperatures are about 3 degrees greater that the real one.

I'm using SensorDemo project example from ST and I checked that use of calibration data is correct.

Have you found a solution ? Have you tried to re-hydrate the sensor ? By the way @Eleon BORLINI​ why should re-hydratation help ?

Thanks.

Hi @Mathieu Garivet​ , a re-hydratation can of course help the stabilization of the dataout, or the enable of the heater bit in CTRL_REG2 (21h) register, but I would add an offset compensation in post processing (via SW) in case of constant offset and almost null gain. Regards

Thank you for your answer.

I will try re-hydratation and heater bit to see if it solves the 3-4 °C offset. It will not be easy to be sure that no gain degrades the measure. But first of all, why could cause the offset ?

I'm a bit disappointing. Among the whole project I am working on (a bluetooth temperature sensor), the part I was the most confident about is the one that is not working correctly. It's a pity..

Hi Mathieu, the temperature offset cause could be due to a series of factors: different conditions during inline calibrations, post solder offset (often main cause), long exposure of the device to corner range temperature / humidity conditions, etc... Especially to prevent the soldering offset shifts, as reported in the datasheet p. 13:

After soldering, the accuracy specification of the sensor can be guaranteed after re-hydration of the sensor element in a stabilized environment (25 °C / 55% rH) for 3 days or at 70% rH for 12 h. Otherwise the sensor may read an offset that slowly disappears if exposed to ambient conditions.

Btw, to be honest the temperature sensor embedded in the HTS221 is not the top-accuracy temperature sensor in ST portfolio: STTS22H for example is surely more accurate. Regards