BSEC library for BME68x on pico enviro+

Has anybody integrated Bosch’s “AI” BSEC library on a pico?

This library supposedly converts the raw gas resistance and temp/humidity from the BME688 into more meaningful air quality index, CO2 and VOC readings. It’s closed source, see here: https://www.bosch-sensortec.com/software-tools/software/bsec/

I’m working on a C++ proof of concept which produces sensible values from the BSEC library but from what I’ve read it needs a 4-day run-in period to calibrate properly, and I haven’t left it this long.

Ideally I want to implement this in micropython, but I’m finding building the custom micropython to be tricky (e.g. v. sensitive to compiler version) and not sure how I go about making an independent custom C++ module that is itself dependent on other (pimoroni-pico) custom C++ modules, so progress is rather slow.

Happy to share this when it’s in a reasonable state (as much as I can given the closed source component) but wondered if I’m going to a lot of effort reinventing a wheel?

Have a look at Integrating the BSEC in CircuitPython (A work in progress) - pi3g.com This is not MicroPython, but CircuitPython is similar regarding linking own modules (it is a fork afterall).

I did a lot of testing with the BME688 and have a number of repos for integration of the open-source drivers into pico C++ code.

My overall verdict is very negative, I don’t think this sensor is useful for anything but detecting VOC (e.g. decaying fruits or smelling cheese). So if this is your target, that is fine. But for anything else like “air quality” this is a waste of time. And the closed source software might have some internal magic that spits out numbers, but I don’t believe this is anything near what other sensors give you.

Some examples: the temp-sensor is severely biased by the internal heat-plate used for VOC detection. That again is highly correlated with ambient temperature. I put the sensor next to my 3D printer that was printing for hours and the sensor did not detect anything (PLA and PETG seem to be no VOC). I spent hours in a closed room to see if the sensor would react to rising CO2 values: negative.

Sorry for this negative input, but I do believe the BME688 is not for us makers at home.

I got the bsec micropython module working and preliminary results look broadly promising. I’ve yet to give it a full calibration run but IAQ, CO2 and bVOC seem to be in the right ballpark. Temperature is bang-on (though I’m setting the bias to 3.9C)

Relative humidity is way off (over 10% too low), although this is also the case for direct readings from the BME68x, even after compensating for temperature bias.

The BSEC library provides different configurations for sample rate, calibration period, and supply voltage to the BME68x. I’m assuming 3.3V for the latter, but 1.8V is the other option. Can anyone confirm what the enviro+ board supplies to it? Not sure what difference this will make TBH.

My code is currently in a fork of pimoroni-pico here GitHub - virgesmith/pimoroni-pico: Libraries and examples to support Pimoroni Pico add-ons in C++ and MicroPython., but it doesn’t really belong here so when I muster the motivation (cmake fills me with apathy) I’ll to move it to a standalone repo at some point. Need to work out how I resolve deps with pimoroni micropython modules from an external repo…

Cheers

How can you call something “bang-on” if you need to set a bias of almost four degrees??

A simple linear adjustment gives agreement to +/- 0.1C over a reasonable temperature range?

I believe that the reason the relative humidity reading is low is that you are adjusting the temperature and not the RH value.

You need to calculate the absolute humidity at the given temperature and then recalculate the RH at the adjusted temperature. You could use the formula below to calculate first the dew point using the August-Roche-Magnus approximation:

Td = 243.04*(math.log(RH/100)+((17.625*T0)/(243.04+T0)))/(17.625-math.log(RH/100)-((17.625*T0)/(243.04+T0)))

Then by using the updated temperature and the dew point you can calculate the updated RH:

RH = 100*math.exp((17.625*Td)/(243.04+Td))/math.exp((17.625*T1)/(243.04+T1)))

Where Td is the dew point, RH is the relative humidity T0 is the original temperature from the sensor and T1 is the corrected temperature.

I’m actually using a simpler (and undoubtedly less accurate) approximation:

        dewpoint = observed_temperature - (100 - observed_humidity) / 5
        corrected_humidity = 100 - 5 * (corrected_temperature - dewpoint)

But I’m using this on both devices, so pretty certain its the raw data. The other device is a Pi Sense hat which uses a different sensor (STMicro HTS221).

Update on the original topic: I ended up giving up on the BSEC library, I got it working (in the sense it ran and produced data) but the readings never seemed trustworthy (esp. CO2) which fluctuated wildly and rarely matched another CO2 sensor which I have good reason to trust.