pimoroni / bmp280-python

Python library for the BMP280 temperature, pressure, and altitude sensor.
MIT License
55 stars 19 forks source link

Measured temperature too high #2

Open SamusAranX opened 5 years ago

SamusAranX commented 5 years ago

So I bought one of these nifty little breakouts and am currently using it in the office.

My problem now is that the temperature always comes back as something above 26°C, even when the windows are open and it's very much not above 26°C. When googling for a solution, I found this: https://github.com/letscontrolit/ESPEasy/issues/164, which sounds like it might be the issue here.

Would it be possible to implement different sampling scenarios? I'd try to do it myself, but working with hardware stuff in Python is not my forte.

Gadgetoid commented 5 years ago

Bear in mind your sensor might also be thermally coupled to the Pi, which can also cause erroneous temperature readings and - in my experience - has more of an impact than the temperature of the sensor itself.

However you can tweak the sampling modes in code using something like:

from bmp280 import BMP280
bmp280 = BMP280()

with bmp280._bmp280.CTRL_MEAS as CTRL_MEAS:
    CTRL_MEAS.set_osrs_t(16)   # Temperature oversampling: 1, 2, 4, 8 , 16
    CTRL_MEAS.set_osrs_p(16)   # Pressure oversampling: 1, 2, 4, 8, 16
    CTRL_MEAS.write()

Let me know if this works for you, and I'll make this a public method.

An alternate approach might be to switch the sensor into "Forced Mode" which performs a single measurement and then returns it into sleep mode. This way you can couple the sensor measurement frequency directly to the speed at which your code runs by requesting a conversion on-demand rather than letting the sensor run continuously. This would- if device overheating is indeed an issue- have the most impact upon temperature readings:

from bmp280 import BMP280
bmp280 = BMP280()

bmp280._bmp280.CTRL_MEAS.set_mode("forced")
while bmp280._bmp280.STATUS.get_measuring():
    time.sleep(0.001)

temperature = bmp280.get_temperature()
Gadgetoid commented 5 years ago

I've raised PR #3 to add these as first-party features.

I'm running some tests with two sensors side-by-side to see what factors most affect accuracy.

From a test with one sensor on our breakout garden extender, and one plugged directly in, I'm seeing a 2 degree difference that's rapidly growing to 3 degrees after I cooled both sensors with compressed air to form a baseline.

IE: The sensor plugged directly into Breakout Garden and thermally coupled to the Pi (Model A) is running 3+ degrees warmer than one attached via around 20cm of wire. This is unsurprising!

I will attempt to test Forced vs Normal mode, too.

Edit: Well, uh, initial test showed Force at 0.3 degrees warmer than Normal. Swapping the sensors around to see if the same results emerge.

Long story short- the difference between Forced and Normal mode is so minute as to be impossible to distinguish from the standard margin for error of the sensor which is - at best - 0.5C and - at worst - 1C variation +-. IE: It's entirely possible for two sensors to differ by 2 degrees C and be operating within spec so any difference less than 2 degrees can't be accurately attributed to ambient sensor temperature.

For specifically the BMP280 I can't find anything in the datasheet that suggests that heat generated by the IC itself is of concern. Perhaps this is accounted for in the stated accuracy ranges. I can't see any reason why you wouldn't want to always run at 16x oversampling for accuracy/stability on a Pi- since power consumption is broadly not a concern.

In summary I think the stuff you link is conflating "low power" with "low thermal interference" since they "Weather monitoring" use-case detailed in the BME280 datasheet suggests using 1x sampling only because it uses less power, and not because it avoids overheating the sensor IC itself. This is because weather monitoring devices are usually deployed in the field with batteries and designed to run on extremely low currents to prolong their life.

Additionally the BME280 is also only accurate to +-0.5 to 1.0 degrees, so the 1 degree variation mentioned is not sufficient to categorise any difference in performance.

TLDR: linked issue is nonsense, just make sure your sensor is not thermally coupled to, or in proximity to any sources of heat.