pi3g / bme68x-python-library

Python 3 Library for BME688 and BME680 (Bosch Sensortec sensors), supports Bosch BSEC
MIT License
47 stars 19 forks source link

Temperature and Humidity readings from get_bsec_data() and get_digital_nose_data() are really off vs. "reality" #26

Open hub187 opened 6 months ago

hub187 commented 6 months ago

I started tinkering with the bsec python library and the pi3g breakout board (bme688 sensor). Loved the coding part but my readings are really off vs. a control DHT22 which I have running on the same desk (10cm apart). I plotted this in grafana to see what was going on. The DHT22 values are also very similar to a dehumidifier which shows relative humidity levels as well (hence why I take this as "source of truth").

Did anyone experience something similar? Can anyone suggest what could be happening?

image (the spike in bsec data at 2200 is due to a reboot of my script. I found first values from the sensor to be off and then stabilise)

Details:

Sample of my code (indentation might be off i had to edit it below so it shows on github as code)

`

while True:
   message_time = str(datetime.datetime.utcnow())
   bsec_data = None
   while bsec_data is None:
       sensor.set_sample_rate(bsec.BSEC_SAMPLE_RATE_LP)
       bsec_data = get_data(sensor)

   sleep(delay_between_measurements / 2)
   message_time_nose_data = str(datetime.datetime.utcnow())
   bsec_nose_data = None

   while bsec_nose_data is None:
       sensor.set_sample_rate(bsec.BSEC_SAMPLE_RATE_HIGH_PERFORMANCE)
       bsec_nose_data = get_nose_data(sensor)

 try:
    extract_variables_and_publish()
except Exception:
    print("There was a problem extracting data and sending data - maybe a sensor failure.")`
hub187 commented 6 months ago

Update (and thanks Keith for the suggestions :).

  1. Changing between sampling mode LP and HIGH_PERFORMANCE regularly (even if 3 or 5 minutes apart) messes up all readings. -> I stick to set_sample_rate(bsec.BSEC_SAMPLE_RATE_LP)
  2. Sticking to LP, and playing with set_conf() parameters can really help smoothing things out and getting good readings, getting rid of the some noise etc.

Readings are much much better now. However, I still end up with a BME688 humidity consistently 6% to 8% higher than my DHT22 or other sensors readings. Anyone has any idea why?

image

Latest conf in the graph above: sensor.set_conf(4, 4, 2, 15, 5)

Conf tried before (annotation lines earlier in the graph):

mcalisterkm commented 6 months ago

There is some discussion on the Community Forum about calibration and accuracy. BoschSensortec think a 15% variation between sensors is OK. The fact that there is a mox sensor with a heater plate built into this sensor, will have an impact, however Bosch say that the sensor burn in calibrates for this. Also any contamination of the sensor throws it way out, just touching it will do it. Personally I compare bme68x values with my local METAR (airport) data, and calibrate a correction factor against that.

How you package the Pi and the sensor can have a big impact, the PI gets hot and if you run that off battery that also gets hot, which can impact the sensor. PI3G put the sensor on an extension that sticks out moving it away from the rest of the module, but the circuit board still heats up.

Some time ago I compared a DHT11, BMP180, and my local METAR for 4 hours, and realised that calibration is not easy and sensors are not accurate out of the box.

Screenshot 2024-05-28 at 10 06 30

Have you tried the averaging (smoothing) of values that the BSEC library supports?

Keith

hub187 commented 6 months ago

15 degrees relative humidity difference?!?! Woh, that's a lot!

Challenge I find is what is I can consider a source of truth for humidity (it can very a lot with a simple tea cuppa on the desk :D).

Overall I am quite happy with the code and the sensor now for humidity and temperature. Definitely a difference but there is strong correlation between both signals.

image

I search for "smooth" in the github search on the bm68x python library project and could not find any method. If you mean the oversampling using the set_conf method, yes I use it - see sample below. I think the noise looks fine from the graph above also.

sensor.set_conf(4, 4, 2, 15, 5)

Form wise, the sensor is not encased.

Question, you mention keeping the sensor clean as it could throw value off otherwise. I have a few more BME688 on their way to compare the values. But have you ever cleaned a sensor before? Looked on the web but did not find any specific instruction for this so not sure if it was ever done / is possible.

mcalisterkm commented 5 months ago

The advice from PI3G is not to touch the sensor as it may contaminate it. - they print it on the board. Bosch Sensortech have handling instructions for the BME680 with quite a lot of detail here

The BME688 has a metal cover with a hole to allow the flow of gas into the sensor, and that gets hot so any contaminant contributes/mixes with the gas going through the hole. Any cleaning needs to be careful - I used a cotton bud moist with rubbing alcohol. However I now realise that rubbing alcohol can have additives and colour that could leave a residue, and I have since read that deionised water is a better choice (from a Honeywell data sheet) again using a moist cotton bud.

And yes I did mean oversampling.