sparkfun / Qwiic_BME280_Py

Python module for the qwiic bme280 sensor
MIT License
11 stars 2 forks source link

Pressure readings inaccurate #1

Closed ChuckBell closed 9 months ago

ChuckBell commented 3 years ago

When using this library with the Sparkfun Qwiic BME280 module on the Raspberry Pi, the values for barometric pressure are not accurate. To validate this claim, I used the same module on the Arduino with the Sparkfun BME280 library then compare it to when used with this library in Python - the results differed. I then used a BME280 library from another vendor to test and got similar results to the Arduino sketch using the Sparkfun library. Thus, this library is not calculating the pressure correctly.

The following are samples when run on the Raspberry Pi with this library and the BME280 Qwiic module (converting to hPa):

Pressure: 1364.32 hPa Pressure: 1364.52 hPa Pressure: 1362.56 hPa

Switching to the Arduino and using the same module and the Sparkfun library, I get values like this:

Pressure: 1019.44 hPa Pressure: 1019.56 hPa Pressure: 1019.47 hPa

To further confirm this observation, I can used a different BME280 library for Python but the same BME280 module andgot values like this:

Pressure: 1019.82 hPa Pressure: 1019.86 hPa Pressure: 1019.81 hPa

Clearly, the calculation for barometric pressure is inaccurate. Some variation is expected given the module was handled and the sensor isn't intended to be scientific-grade accuracy, but the difference in readings is too far off.

And, yes, I did use the correct value for sea level pressure in my area in all tests. I experimented several of the overscan methods, but nothing made a significant difference in the readings.

I can investigate further if you'd like, but there's something wonky in the code.

MisterMartin commented 3 years ago

I’ve had the same experience. The qwic_bme280_py pressure values are simply wrong. Sea level atmospheric pressures of 1300mb are not even possible. 1019mb is very reasonable. Because of this, I have to throw away the pressure measurement. Sparkfun should fix this.

georgePadolsey commented 2 years ago

Have submitted a PR which should hopefully close this issue. In the meantime, you can try cloning the forked repo with the fix.

Code to clone and install ```bash git clone https://github.com/georgePadolsey/Qwiic_BME280_Py.git --branch fix/1#issue-782894620 cd Qwiic_BME280_Py pip install . ```

Hope this helps :)

electronsandstuff commented 2 years ago

@georgePadolsey, thank you! I was pulling my hair out trying to figure out what was wrong with my sensor readings. With your PR mine now lines up with local weather stations.

One other note: while debugging I saw that self.t_fine (which the pressure method uses) is only set from the sensor in get_temperature_celsius. This means that you probably need to read the temperature first and then immediately read the pressure to get an accurate value. On my board I do see a big difference between measuring temp and pressure and just measuring temp (IE not having t_fine set). I opened a separate issue on this (#5).