Hello,
I have a little trouble with one of my many Pimoroni BME280.
To make sure the reading a accurate I poll the BME280’s 4 times in a loop and take the last set of readings.
Every now and again the reading respond back with what appears to be default data ie..
Temp C = 21.62
Humidity = 61.18
Pressure = 657.52
These results persist for several hours regardless of reboots etc
I have swapped the Raspberry Pi Zero 2 with another and still happens. Even using the Pimoroni BME280 all-values.py example I get the same results.
I suspect the BME to have a problem, can any one confirm (Not looking for a refund as these were bought 2 years ago)
You should read the section 3.5.1 of the datasheet for how to operate the BME280. Too bad that the defaults of the Pimoroni drivers are far away from these recommendations.
Your oversampling link is for the Pico, anyway I have not setup for oversampling. I just run the following code in a loop 4 times then take the last reading as data. The first request is usually inaccurate, so just 4 times and then take the data
# Initialise the BME280
bus = SMBus(1)
bme280 = BME280(i2c_dev=bus)
while counter < 5:
counter = 1
temperature = bme280.get_temperature()
pressure = bme280.get_pressure()
humidity = bme280.get_humidity()
print(f"{temperature:05.2f}°C {pressure:05.2f}hPa {humidity:05.2f}%")
counter = counter + 1
time.sleep(1)
Sorry for the wrong link, but the normal Python driver is not better.
You are using the defaults, and the defaults use 16x oversampling:
And in addition, you oversample again 4 times in a loop (at least you try to do that - but you don’t, since your counter is initialized within the loop and not outside). So this puts the sensor under real stress, you are effectively reading the sensor (4x) 3x16 times.
So the first thing to do is to manually call bme280.setup(...) directly after you created bme280 and feed in the correct mode (forced) and oversample settings. And reading the sensor once is all you need.