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
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
else:
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
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
value.
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?