Bosch sensor gas measurement

2024-05-17, by Frank Delporte

Bosch has several sensors which are extremely small to measure temperature, humidity, pressure, and gas. We also have several example implementations documented on the Pi4J website:

You can find easy-to-use boards with such a sensor, for instance, on:

Important Information Regarding Gas Measurements

On the Pi4J GitHub Discussion page, there is an interesting discussion going on about the BME688 gas sensor that I want to share here… crogialli shared the following info:

I’ve been using BME680 in my application for a year, and I am also implementing BME 688. It is entirely possible to read Temp, Pressure, Humidity and gas resistances from plain Java code (I do it, and I can submit my code for that, albeit I have an abstraction layer between the BME68X management and Pi4J so that the code could be not immediately usable). Readings for temp, pressure and humidity from BME68X are astonishingly accurate and quick.

However, I want you to know that it is not possible to get sensible air-quality (gas) estimations in that way. You can get a gas sensor resistance reading, but it is entirely meaningless and random, as a matter of fact. It cannot be reconnected to any air quality measure without the Bosh Sensortec Libraries (see below).

Moreover, I’ve been reading a BME680 gas sensor “manually” every 5 seconds by setting arbitrary heating patterns for a couple of years now. I’m pretty sure I have damaged the BME 680 MEMS gas sensor since current resistance readings are now very low (1..3K), whilst at the beginning, they used to be relatively higher (15K …150K). The sensor has always been in the same protected ambient (a boiler room with some natural ventilation hosting a diesel-fueled burner).

To get a correct gas estimation and preserve the sensor’s life, the only way I know is to integrate BSEC libraries from Bosch, which implement a few adaptive algorithms for sampling the gas estimates with specific (AI-Calibrated) sensor heating patterns and at specific instants, thus providing reliable indexes and safeguarding the MEMS device.

Integrating BSEC libraries poses a few challenges:

  1. The library, written in C, is Bosch proprietary
  2. The source is not available; BSEC is provided as a C binary library, statically linked
  3. It is unclear at the moment if they provide a 64bit binary for Raspberry Pi4 (I want to run on Rasbian 64)
  4. A Python wrapper exists, but not a Java one.

I’m looking into developing a Java (or Groovy) wrapper for integrating BSEC into my app. Should I be unable to wrap it in Java, I will likely implement a call to external C or Python code (disgusting but likely functional, provided that a solution to run on 64-bit Raspbian exists).

BME68X sensors give exceptional results for their price. I advise avoiding messing with air quality if you don’t need it; if you do, you shall find a way to integrate BSEC libraries.

Bosch software