robert-hh / BME280

Micropython driver for the BME280 sensor, target platform Pycom devices
Other
103 stars 27 forks source link

Pressure is 250hPa off and not sure why. #10

Closed wildernessfamily closed 1 year ago

wildernessfamily commented 1 year ago

Hi, I've been using a different library for BME280 and happen to find yours. It is very well laid out. Thank you for managing this library.

I have a Raspberry Pi Pico-W with a BME280 connected to pins SDA on pin 20 and SCL on pin 21. The temperature, humidity, & dew point are spot on. On line 94 self.__sealevel = 101325 I changed to my local sea level pressure, 100271 self.__sealevel = 100271 (I live in the mountains in CO). The altitude is pretty darn close. But the pressure is always very close to being 250 hPa off. Ex. It's showing the current pressure as 750.92hPa. OpenWeatherMap shows it to be 998 hPa and the local METAR says it's 1002hPA. I've been playing around for over a week now and every day it's always about 250hPa off. I did try different BME280 boards, thinking just by the off chance I happen to have a bad one. I tried two from the same order and two from a different order, and they were all almost exactly the same reading as the original. At this point, I thought I'd reach out for some guidance. Any help would be appreciated. Thank you!

robert-hh commented 1 year ago

The pressure value returned from the lib is the raw value, not compensated for the height. Since the altitude the lib returns is correct, it looks as if the pressure value is right. The altitude is calculated from the pressure value. A pressure reading of ~75% of the sealevel value means, that you are at a height of ~2200m or ~7000ft. Is that reasonable? Edit: Weather reports always show the sealevel value, even for places at different heights. And I found the pressure sensor of the BME280 always being pretty precise. I have a local university weather station close by, which reports the raw value. And the difference to their value is actually the 30ft difference in height. The temperature values of the BME280 are good as well. The humidity values are not very precise. The data sheet say 2% error, but in my tests it's more at 5%.

robert-hh commented 1 year ago

You can calculate the sea-level pressure Ps from the actual pressure P and the outside temperature T (°K) and the height H (m) as:

Ps = P / ((1 - (0.0065 / T) * H) ** 5.255)

So for an outside temperature of 10°C, you have 282°K. And H is e.g. 2240 m. Which results for a reading of 760hPa in a sea level pressure of ~1004 hPa. For an outside temperature of -10°C you would get 1026hPa. The precision is limited by the constant 0.0065 only having two significant digits. So it's about 1%.

To get °C from °F, use: Tc = (Tf - 32) / 1.8 To get °K from °C, simply use:

°K = °C + 272.15

wildernessfamily commented 1 year ago

I've been working non-stop for the past couple weeks. Must have been the lack of sleep. I thought it was giving sea-level pressure for p. I had over a dozen browser tabs that all have about the same instructions on how to set up a Pico with the BME280, and they all were showing in their screenshots the Sea Level Pressure. It never dawned on me to look at that. I apologize, I should have seen that. Thank you for taking the time to answer my question and your detailed answer. After I entered the equation, the sea-level pressure was almost spot on to what OpenWeatherMap was showing. Thank you again :)