Barametric readings off for LPS25H

When taking barometric readings from the LPS25H it starts out by giving numbers like 994.115, but then it will go down to zero, then eventually going in to the negative numbers.

My question is why does it drop down to zero after giving multiple realistic barometric readings?

Also the 994.115 is off by about 15. Although I am more worried about the readings going to zero


994.115 could well be the pressure at your location, at that time.

Note that local barometric pressure readings published in the newspaper, on TV or online are corrected to sea level.

The drift problem could be due to many factors. Describe how you have wired everything and post the code.

I have the AltIMU-10 v4 wired to my rasperry pi using SCL goes to SCL. SDA goes to SDA, GND goes to GND, and 3v3 power goes to VDD.

The code is fairly large so I am just going to post the parts that have to do with the barometer. Also this is written in python.

b.write_byte_data(LPS, LPS_CTRL_1, 0b11000010) 
b.write_byte_data(LPS, LPS_CTRL_2, 0b00000010) 

pressureTempLoop = twos_comp_combine(b.read_byte_data(LPS, PRESS_H), b.read_byte_data(LPS, PRESS_L))
pressureLoop = twos_comp_combine(pressureTempLoop, b.read_byte_data(LPS, PRESS_XL))
pressureLoop = convert_barometer(pressureLoop)#converts to usable values

It then goes through a loop for 5 seconds taking readings. The first couple readings are around 994 then out of nowhere it drops down to 0 and then goes to something like -.20123102040 where it says around until the program is done.


I am sorry you are having trouble with your barometer. Can you print and post the raw values, and also post the source of the twos_comp_combine and convert_barometer functions?


def twos_comp_combine(msb, lsb): 	#16 bit
twos_comp = 256*msb + lsb
if twos_comp >= 32768:
    return twos_comp - 65536
    return twos_comp

def convert_barometer(x)	#converts raw pressure readings to usable data (hPa)
sensitivity = 1/4096.0
return x*sensitivity

The raw values are
It starts out with 63, 114, 206. That gives a resonable barometric pressure of 999.17
Then it gave zero for all three raw readings. Then gave zeros for 2 of them and 165 for PRESS_XL(0x28) which gives a barometric pressure of .0402 hPa. Basically all of the raw values for PRESS_L and PRESS_H are zero until the pressure starts giving negative numbers at which point the raw values for those two are 255

These are what I used to initialize the barometer
b.write_byte_data(LPS, LPS_CTRL_1, 0b11000010) #enables barometer/altimeter sets data rate to 25HZ and puts on reset AutoZero
b.write_byte_data(LPS, LPS_CTRL_2, 0b00000010) #enables autozero


Hi, Karl.

I don’t think we’ve tried using the autozero function of the LPS25H, but it looks like you’re enabling it, and that might explain the behavior you’re seeing. According to the datasheet:

AUTO_ZERO, when set to ‘1’, the actual pressure output is copied in the REF_P_H &
REF_P_L & REF_P_XL and kept as reference and the PRESS_OUT_H & PRESS_OUT_L
& PRESS_OUT_XL is the difference between this reference and the pressure sensor

So the zero and negative readings you’re getting might represent the relative difference in pressure from the reference value. If you want an absolute pressure in hPa, you should leave the AUTO_ZERO bit in CTRL_REG2 as 0. It also shouldn’t be necessary to set the RESET_AZ bit in CTRL_REG1, though doing so shouldn’t hurt, either (it sounds like it just resets the reference value to 0).

Could you try that change and see if you get the results you expect?


Thank you so much that was the problem. Now it works correctly thank you!