Bias in the first temperature reading

I edited the compensated-temperature.py example to calculate the correction factor. User inputs the actual temperature, take 20 readings each of BME and CPU temps and calculate the factor. I have noted before that the first reading off the BME is skewed, then stabilizes. Here, though, each and every reading is skewed AND EXACTLY THE SAME TO 17 SIG FIGS! Put in an error trap so that if raw<actual, set the factor=100, i.e., make the correction trivial. Is the temp sensor defective?

(pimoroni) hostname@user:~/Pimoroni/enviroplus-python/examples $ python comp-temp-input.py
Enter actual temp in °C: 24.5
2025-08-27 13:27:44.596 INFO comp-temp-input.py - Use the CPU temperature and user input
to compensate temperature readings from the BME280 sensor.

Press Ctrl+C to exit!

2025-08-27 13:27:44.716 INFO RAW: [21.551522436831146, 21.551522436831146, 21.551522436831146, 21.551522436831146, 21.551522436831146, 21.551522436831146, 21.551522436831146, 21.551522436831146, 21.551522436831146, 21.551522436831146, 21.551522436831146, 21.551522436831146, 21.551522436831146, 21.551522436831146, 21.551522436831146, 21.551522436831146, 21.551522436831146, 21.551522436831146, 21.551522436831146, 21.551522436831146]
CPU: [42.932, 42.932, 42.932, 42.932, 42.932, 42.932, 42.932, 42.932, 42.932, 42.932, 42.932, 42.932, 42.932, 42.932, 42.932, 42.932, 42.932, 42.932, 42.932, 42.932]
2025-08-27 13:27:44.716 INFO Actual as entered: 24.50 Calculated Factor: 100.00
2025-08-27 13:27:44.718 INFO Compensated temperature: 21.34 °C
2025-08-27 13:27:45.721 INFO Compensated temperature: 29.82 °C
2025-08-27 13:27:46.724 INFO Compensated temperature: 29.80 °C
2025-08-27 13:27:47.727 INFO Compensated temperature: 29.79 °C
2025-08-27 13:27:48.730 INFO Compensated temperature: 29.79 °C
2025-08-27 13:27:49.733 INFO Compensated temperature: 29.79 °C
2025-08-27 13:27:50.736 INFO Compensated temperature: 29.78 °C
2025-08-27 13:27:51.739 INFO Compensated temperature: 29.78 °C
2025-08-27 13:27:52.742 INFO Compensated temperature: 29.78 °C
2025-08-27 13:27:53.745 INFO Compensated temperature: 29.78 °C
2025-08-27 13:27:54.748 INFO Compensated temperature: 29.78 °C
2025-08-27 13:27:55.751 INFO Compensated temperature: 29.78 °C
2025-08-27 13:27:56.754 INFO Compensated temperature: 29.78 °C
2025-08-27 13:27:57.757 INFO Compensated temperature: 29.78 °C
2025-08-27 13:27:58.759 INFO Compensated temperature: 29.78 °C
2025-08-27 13:27:59.762 INFO Compensated temperature: 29.78 °C
2025-08-27 13:28:00.765 INFO Compensated temperature: 29.79 °C

Errors in BME280 temperature reading are always due to a wrong setup and/or software configuration. You have to configure the sensor in “forced mode” and you have to operate the system in an on/off scheme. Search the forums for details about all of this, I posted the details many times.

With correct operation, no temperature compensation is necessary.

Workaround. Originally i used: raw_temps = [bme280.get_temperature()] * 20. Then created a subroutine:

def get_raw_temp():
temp=bme280.get_temperature() # throwaway reading
time.sleep(1.0)
temp=bme280.get_temperature() # keep this one
return temp

And i call it with raw_temps = [get_raw_temp()] * 10

(pimoroni) hostname@user:~/Pimoroni/enviroplus-python/examples $ python comp-temp-input.py
Enter actual temp in °C:  26
2025-08-28 17:04:44.554 INFO     comp-temp-input.py - Use the CPU temperature and user input
to compensate temperature readings from the BME280 sensor.

Press Ctrl+C to exit!

2025-08-28 17:04:45.682 INFO     RAW: [30.332810114150583, 30.332810114150583, 30.332810114150583, 30.332810114150583, 30.332810114150583, 30.332810114150583, 30.332810114150583, 30.332810114150583, 30.332810114150583, 30.332810114150583]  CPU: [42.932, 42.932, 42.932, 42.932, 42.932, 42.932, 42.932, 42.932, 42.932, 42.932]
2025-08-28 17:04:45.682 INFO     Temp as entered: 26.0°C  Factor as calc: 02.91
2025-08-28 17:04:45.685 INFO     Compensated temperature: 26.02 °C
2025-08-28 17:04:46.688 INFO     Compensated temperature: 26.02 °C
2025-08-28 17:04:47.691 INFO     Compensated temperature: 26.03 °C
2025-08-28 17:04:48.694 INFO     Compensated temperature: 26.03 °C
2025-08-28 17:04:49.697 INFO     Compensated temperature: 26.03 °C
2025-08-28 17:04:50.700 INFO     Compensated temperature: 26.03 °C
2025-08-28 17:04:51.703 INFO     Compensated temperature: 26.02 °C
2025-08-28 17:04:52.706 INFO     Compensated temperature: 26.02 °C
2025-08-28 17:04:53.709 INFO     Compensated temperature: 26.01 °C
2025-08-28 17:04:54.712 INFO     Compensated temperature: 26.00 °C
2025-08-28 17:04:55.714 INFO     Compensated temperature: 25.97 °C

@bablockb, searched for your name, for overclock, for bme280. Only fix i found was for a breakout board. And of course, even if the driver issue is fixed, heat from the nearby CPU will still need correction as you acknowledged in 2023.

I usually take one or two, throw away, readings above the while True. Take a reading, wait a second, take another reading. That usually gets me a valid reading to actually display in my while true loop.
On my Raspberry Pi setups I try to mount the breakout away from any CPU heat etc. Most of my current setups are Enviro Clones. BME Breakout, LCD Display Pack, etc. The QWICC cables and connectors make it pretty easy these days.

I am always a bit baffled that people insist in doing things wrong and then correcting it with some voodoo. Doing it right in the first place is so much simpler. I never need to throw away any BME280 readings and I don’t need temperature compensation. If that would really be necessary, it would be documented in the datasheet.

Could you please post your code / setup for “forced mode”.
Or what you prefer to use for your setup.
The Python code anyway, not sure if it’s doable in Micro Python?
I’d like to try it and post back, it wouldn’t be the first time I was “doing it wrong” ;)

1 Like

I am not using the Pimoroni software, but you can find the setup() method here: https://github.com/pimoroni/bme280-python/blob/fff91c86c958f666202c7c8713b6aa7d7d9bb955/bme280/\__init_\_.py#L203

and an example here: bme280-python/examples/temperature-forced-mode.py at main · pimoroni/bme280-python · GitHub

Note that this example does use forced-mode, but it still uses all that oversampling that you should not use (for weather monitoring, oversampling is ok for barometric altitude meters). You have to provide all the parameters for setup() since the defaults are unsuitable.

MicroPython uses the same API, so it should work there too.

First link is bad. Looks like it should be:

Correct. This seems to be a problem of this forum-software. When I inserted it, it did some “interpretation” of the underscores as markdown. Glad you found the correct link though.