Skip to main content
Visitor II
October 21, 2019
Question

I am getting erroneous readings for Pressure(hPa) and Relative Humidity (%) using the LPS25H and the HTS221 Sensors respectively.

  • October 21, 2019
  • 2 replies
  • 941 views

I have been using both these sensors on my Raspberry Pi, with Python cording.

Here is a copy of my init() routine for both sensors:

def init():
 #Initialise the LPS25H sensor for continous reading
 #---------------------------------------------------
 i2c_bus.write_byte_data(LPS25H_address,0x21,0x04) #Software Reset and Boot
 time.sleep(0.4) #Wait for reset
 i2c_bus.write_byte_data(LPS25H_address,0x20,0x00) #Reseting the sensor
 i2c_bus.write_byte_data(LPS25H_address,0x21,0x40) #FIFO Enable=40
 i2c_bus.write_byte_data(LPS25H_address,0x2E,0xDF) #FIFO Mean,Stream:Newest Members, 16 sample moving avg
 #Only powerup device after setting registers.
 i2c_bus.write_byte_data(LPS25H_address,0x10,0x0C) #RES_CONF: Temp and Press Avg. 8 samples
 i2c_bus.write_byte_data(LPS25H_address,0x20,0xC4) #PowerUp,BDU,25Hz
 
 
 #Initialise the HTS221 Sensor for continous reading
 #----------------------------------------------------
 i2c_bus.write_byte_data(HTS221_address,0x21,0x80) #Boot
 time.sleep(0.4) #Wait for Boot and Reset
 i2c_bus.write_byte_data(HTS221_address,0x20,0x00) #Reset the sensor
 i2c_bus.write_byte_data(HTS221_address,0x10,0x3F) #AVGT:256 and AVGH:512
 i2c_bus.write_byte_data(HTS221_address,0x21,0x02) #Enable Heater
 #time.sleep(120) #Sleep for 20ms whilst sensor gets heated
 #i2c_bus.write_byte_data(HTS221_address,0x21,0x00) #Disable Heater
 #Only powerup device after setting registers.
 i2c_bus.write_byte_data(HTS221_address,0x20,0x87) #PU,BDU and 12.5Hz

This is the code for my Read_Pressure_HPa() function:

def Read_Pressure_HPa():
 while True:
 if (IsDataReady(LPS25H_address,False)):
 break
 #Read press_xl,press_l and press_h registers
 press_xl=i2c_bus.read_byte_data(LPS25H_address,0x28)
 press_l=i2c_bus.read_byte_data(LPS25H_address,0x29)
 press_h=i2c_bus.read_byte_data(LPS25H_address,0x2A)
 #Concatonating 
 press=bytearray([press_xl,press_l,press_h,0x00])
 #Converting to int32
 press_i=(struct.unpack('<i',press)[0])
 #Scaling
 pressure= int(press_i/4096)
 return pressure

Here is the code for the Read_Humidity_Perc() function:

def Read_Humidity_Perc():
 while True:
 if (IsDataReady(HTS221_address,False)):
 break
 #Read h0 and h1 registers 
 h0=i2c_bus.read_byte_data(HTS221_address,0x30)
 h1=i2c_bus.read_byte_data(HTS221_address,0x31)
 #Read h0t0 registers
 h0t0_l=i2c_bus.read_byte_data(HTS221_address,0x36)
 h0t0_h=i2c_bus.read_byte_data(HTS221_address,0x37)
 #Read t1 registers
 h1t0_l=i2c_bus.read_byte_data(HTS221_address,0x3A)
 h1t0_h=i2c_bus.read_byte_data(HTS221_address,0x3B)
 #Read raw_humidity registers
 rawHum_l=i2c_bus.read_byte_data(HTS221_address,0x28)
 rawHum_h=i2c_bus.read_byte_data(HTS221_address,0x29)
 
 #Converting h0 and h1 to short
 h0_us=(int.from_bytes(bytearray([0x00,h0]),signed=False,byteorder='big')/2)
 h1_us=(int.from_bytes(bytearray([0x00,h1]),signed=False,byteorder='big')/2)
 
 #Converting h0t0 to short
 h0t0=bytearray([h0t0_h,h0t0_l])
 h0t0_s=int.from_bytes(h0t0,signed=True,byteorder='big')
 #Converting t0 to short
 h1t0=bytearray([h1t0_h,h1t0_l])
 h1t0_s=int.from_bytes(h1t0,signed=True,byteorder='big')
 #Converting raw_hum to short
 rawHum=bytearray([rawHum_h,rawHum_l])
 rawHum_s=int.from_bytes(rawHum,signed=True,byteorder='big')
 
 #Scaling
 humidity=(h1_us-h0_us)*(rawHum_s-h0t0_s)/(h1t0_s-h0t0_s)
 humidity=humidity+h0_us
 
 return round(humidity,2)

Here are the readings that I got, when the heater on the HTS221 was turned off:

0690X00000AqaOIQAZ.jpg

0690X00000AqaNeQAJ.jpg

Here are the readings that I got, when the heater on the HTS221 was turned on:

0690X00000AqaNtQAJ.jpg

I would be really great-full, if anyone can shed some light on the issue and let me know what's wrong.

    This topic has been closed for replies.

    2 replies

    ST Employee
    October 21, 2019

    Hi @Faizan Cassim​ , but does the second picture (heater ON) refers to data after the activation or during the heater on? Please note that the datasheet says that:

    "valid data can be read out once the heater has been turned off, after the completion of the heating cycle", so you have to read the data after

    Not clear also the reference pressure at 100hPa... are you in a low pressure ambient?

    About the humidity value: the humidity formula seems ok, but the value is stuck... can you share the regmap dump and the rawHum register values?

    Regards

    Visitor II
    October 21, 2019

    Humidity Issue

    • Quiet rightly so, the second terminal screen shot refers to the output humidity; whilst the heater is turned on.
    • How long should 1 heating cycle of the HTS221 take (in seconds or minutes)?
    • Currently the humidity in my area varies from about 89% to 95%.

    Pressure Issue

    • The reference pressure is set as zero and the RPDS is at its default value.
    • The pressure in my area, these few days should be around the ballpark of 1006-1010hPa. (As measured on my iPhone)

    Register Dump for LPS25H

    0690X00000AqeIYQAZ.jpg

    Register Dump for HTS221

    0690X00000AqeIiQAJ.jpg