itbrainpower.net
THE ALPHABET PROJECT - professional Arduino, BeagleBone & Raspberry PI shields

 
COVID19-SARS2 service info ==> we are 100% up and running!

Order s-Sense BME688 breakout - the digital noze - first air quality sensor having artificial intelligence. Order here our IoT product(s) of the week at discounted prices.

Arduino BME688 sensor basic how to

 

About BME688 - gas scanner with AI, air quality sensor, temp., hum. and pres. sensor


BME688 ( manufactured by Bosch Sensortec) is the first gas sensor with Artificial Intelligence (AI) and integrated high-linearity and high-accuracy humidity and temperature sensors. The integrated gas sensor it's able to detect Volatile Organic Compounds (VOCs), Volatile Sulfur Compounds (VSCs) and other gases as carbon monoxide (CO) and hydrogen in the ppb (part per billion) range.

The new BME 688 sensor its backward compatible with BME680. Additionally, to all features of the BME680, the BME688 has a gas scanner function. In standard configuration, the presence of VSCs is detected as indicator for e.g. bacteria growth. The gas scanner can be customized with respect to sensitivity, selectivity, data rate and power consumption as well. The BME AI-Studio tool enables customers to train the BME688 gas scanner on their specific application, like in home appliances, IoT products or Smart Home.

The gas sensor in the BM688 has a broad sensitivity and reacts to most volatile compounds as well as many other gases polluting indoor air. The intensity of the signal typically scales with the chemical reactivity of the gases. In contrast to sensors selective for one specific component, the BME688 is capable of measuring the sum of VOCs/contaminants in the surrounding air. This enables the BME688 to detect e.g. out-gassing from paint, furniture and/or garbage, high VOC levels due to cooking, food consumption, exhaled breath and/or sweating.

Bosch Sensortec BME688 sensor main features:
- ambient range for operation -40 ~ +85C, 0%-100% r.H., 300-1100hPa
- gas sensor major outputs (via BSEC) IAQ, bVOC & CO2 equivalents (ppm), gas scan results (%) & intensity level
- sensor to sensor IAQ deviation +-15% / +-15IAQ
- relative humidity accuracy tolerance / hysteresis +-3% / <= 1.5%
- absolute temperature accuracy +-0.5C (at +25C)
- pressure sensitivity error +-0.25%
- BME688 datasheet

In June 2019 we've realeased the first 6 environmental and air quality sensors from the s-Sense I2C sensor breakout family. In the middle of May 2021, as soon as BME688 sensor become available, we released commercially our s-Sense BME688 breakout.

s-Sense BME688 sensor breakout by itbrainpower.net

BME688 sensor breakout - topBME688 sensor breakout - bottom

PN: SS-BME688#I2C   SKU: ITBP-6007     BME688 I2C sensor breakout more info ,order

Hints:
- at first sensor usage, minimum 48 hours of "burn in" should be made. Later, at each usage, 30 min. of functioning should passed before sensor data may be considered as valid.
- for IAQ (Air quality index), target gas scanner selectivity, VOC, VSC and other BME688 features may be accessed using the Bosch Sensortec "BSEC fusion library".
- in order to avoid contamination, DO NOT touch the metallic casing of the BME688!!!


Next, I will show to you how to make the hardware setup and how to get raw sensor (temperature, humidity, pressure and the MOX gas resistor) values in Arduino - around 10-15 minutes.

 

 

 

Arduino BME688 sensor hardware integration (wiring)


First, identify if your Arduino it's 5V or 3.3V compliant!

The BME688 I2C sensor breakout it's shipped in default auto 3-5V compliant configuration. In a nut shell, wire as bellow:

BME688 breakout Arduino 5V [Eg.: UNO] Arduino 3.3V [Eg.: Zero]
Vin PAD 5V 3.3V
Vdd PAD (3V3) do not connect do not connect
SDA PAD SDA SDA
SCL PAD SCL SCL
GND PAD GND GND
 

HINT, for some ARDUINO boards:
*         SDA (Serial Data)      --> A4 on Uno/Pro-Mini, 20 on Mega2560/Due, 2 Leonardo/Pro-Micro
*         SCK (Serial Clock)     --> A5 on Uno/Pro-Mini, 21 on Mega2560/Due, 3 Leonardo/Pro-Micro

Bellow, sensor wiring example with xyz-mIoT shield [AT SAMD21G, 3.3V compliant, with or without modems]:
BME688 sensor breakout Arduino shield wiring


Bellow, sensor wiring example with Arduino UNO shield [328p, 5 compliant]:

BME688 sensor breakout wiring with Arduino UNO shield


Arduino BME688 sensor software - read raw sensor data


a. download BME68x Arduino library from: here.

b. unzip the library and install in Arduino libraries folder. Restart Arduino.

c. Make a folder named "ssense_BME688_example".
Copy the code bellow, paste it one new file and save the file as "ssense_BME688_example.ino" in the folder created in previously or, you may download it from here (right click & save as): BME688 - read sensor data Arduino code

1/* s-Sense BME68x I2C sensor breakout example - v1.01/20210520. 
2 * 
3 * Compatible with:
4 *    s-Sense BME688 I2C sensor breakout - gas scanner with AI, air quality sensor, temperature, humidity and pressure sensor - [PN: SS-BME688#I2C, SKU: ITBP-6007, 
5 *    info https://itbrainpower.net/sensors/BME688
6 *    s-Sense BME680 I2C sensor breakout - temperature, humidity, pressure and gas - [PN: SS-BME680#I2C, SKU: ITBP-6003], 
7 *    info https://itbrainpower.net/sensors/BME680 
8 *
9 * This code shows how to use predefined recommended settings for the BME680 air quality sensor. Read temperature,  
10 * humidity, pressure and gas sensor data (pulling at 1sec) - code based on based on Zanshin_BME680 library version 
11 * 1.0.2 / 2019-01-26 - https://github.com/SV-Zanshin . Good job Zanshin!
12 *  
13 * Include three functions for altitude calculation (one provided by Zanshin, one ported from BME280/BMP280 library [NOAA equation] and the
14 * last one [based on CASIO equation and implementing temperature compensated algorithm] that was written by us.
15 *  
16 * We've just select the relevant functions, fixed some 328p compiling issues found in original library, add some variables, functions and fuctionalities.
17 * 
18 * 
19 * Mandatory wiring:
20 *    Common for 3.3V and 5V Arduino boards:
21 *        sensor I2C SDA  <------> Arduino I2C SDA
22 *        sensor I2C SCL  <------> Arduino I2C SCL
23 *        sensor GND      <------> Arduino GND
24 *    For Arduino 3.3V compatible:
25 *        sensor Vin      <------> Arduino 3.3V
26 *    For Arduino 5V compatible:
27 *        sensor Vin      <------> Arduino 5V
28 * 
29 * Leave other sensor PADS not connected.
30 * 
31 * SPECIAL note for some ARDUINO boards:
32 *        SDA (Serial Data)   ->  A4 on Uno/Pro-Mini, 20 on Mega2560/Due, 2 Leonardo/Pro-Micro
33 *        SCK (Serial Clock)  ->  A5 on Uno/Pro-Mini, 21 on Mega2560/Due, 3 Leonardo/Pro-Micro
34 * 
35 * WIRING WARNING: wrong wiring may damage your Arduino board MCU or your sensor! Double check what you've done.
36 * 
37 * New BME688/680 sensors requires burn in (48h). Once burned in a sensor requires at least 5 minutes of run in before gas resistance readings are considered good.  
38 * 
39 * READ BME688 documentation! https://itbrainpower.net/sensors/BME688
40 * READ BME680 documentation! https://itbrainpower.net/sensors/BME680
41 * 
42 * We ask you to use this SOFTWARE only in conjunction with s-Sense BME688 or s-Sense BME680 sensor(s) breakout usage. Modifications, derivates 
43 * and redistribution of this SOFTWARE must include unmodified this notice. You can redistribute this SOFTWARE and/or modify it under the 
44 * terms of this notice. 
45 * 
46 * This SOFTWARE is distributed is provide "AS IS" in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 
47 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
48 *  
49 * itbrainpower.net invests significant time and resources providing those how to and in design phase of our IoT products.
50 * Support us by purchasing our environmental and air quality sensors from https://itbrainpower.net/order#s-Sense
51 *
52 *
53 * Dragos Iosub, Bucharest 2021.
54 * https://itbrainpower.net
55 */
56
57 /*! @file I2CDemo.ino
58
59
60@section I2CDemo_intro_section Description
61
62Example program for using the Bosch BME680 sensor. The sensor measures temperature, pressure and humidity and  is
63described at https://www.bosch-sensortec.com/bst/products/all_products/BME680. The datasheet is available from Bosch
64at https://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BME680_DS001-11.pdf \n\n
65
66The most recent version of the BME680 library is available at https://github.com/SV-Zanshin/BME680 and the 
67documentation of the library as well as example programs are described in the project's wiki pages located at 
68https://github.com/SV-Zanshin/BME680/wiki. \n\n
69
70The BME680 is a very small package so it is unlikely for an Arduino hobbyist to play around with directly, the 
71hardware used to develop this library is a breakout board from AdaFruit which is well-documented at
72https://learn.adafruit.com/adafruit-BME680-humidity-barometric-pressure-temperature-sensor-breakout \n\n
73
74This example program initializes the BME680 to use I2C for communications. The library does not using floating
75point mathematics to save on computation space and time, the values for Temperature, Pressure and Humidity are
76returned in deci-units, e.g. a Temperature reading of "2731" means "27.31" degrees Celsius. The display in the 
77example program uses floating point for demonstration purposes only.  Note that the temperature reading is 
78generally higher than the ambient temperature due to die and PCB temperature and self-heating of the element.\n\n
79
80The pressure reading needs to be adjusted for altitude to get the adjusted pressure reading. There are numerous
81sources on the internet for formula converting from standard sea-level pressure to altitude, see the data sheet
82for the BME180 on page 16 of http://www.adafruit.com/datasheets/BST-BMP180-DS000-09.pdf. Rather than put a
83floating-point function in the library which may not be used but which would use space, an example altitude
84computation function has been added to this example program to show how it might be done.
85
86@section I2CDemolicense License
87
88This program is free software: you can redistribute it and/or modify it under the terms of the GNU General
89Public License as published by the Free Software Foundation, either version 3 of the License, or (at your
90option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY
91WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
92GNU General Public License for more details. You should have received a copy of the GNU General Public License
93along with this program.  If not, see <http://www.gnu.org/licenses/>.
94
95@section I2CDemoauthor Author
96
97Written by Arnd\@SV-Zanshin
98
99@section I2CDemoversions Changelog
100
101Version | Date       | Developer           | Comments
102------- | ---------- | ------------------- | --------
1031.0.1   | 2019-01-26 | https://github.com/SV-Zanshin | Issue #3 - convert documentation to Doxygen
1041.0.0b  | 2018-06-30 | https://github.com/SV-Zanshin | Cloned from original BME280 program
105
106*/
107
108/*******************************************************************************************************************
109**                                                                                                                **
110** This program is free software: you can redistribute it and/or modify it under the terms of the GNU General     **
111** Public License as published by the Free Software Foundation, either version 3 of the License, or (at your      **
112** option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY     **
113** WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   **
114** GNU General Public License for more details. You should have received a copy of the GNU General Public License **
115** along with this program.  If not, see <http://www.gnu.org/licenses/>.                                          **
116**                                                                                                                **
117** Vers.  Date       Developer                     Comments                                                       **
118** ====== ========== ============================= ============================================================== **
119** 1.0.0b 2018-06-30 https://github.com/SV-Zanshin Cloned from original BME280 program                            **
120**                                                                                                                **
121*******************************************************************************************************************/
122#include "sSense_BME680.h" // Include the BME680 Sensor library
123/*******************************************************************************************************************
124** Declare all program constants                                                                                  **
125*******************************************************************************************************************/
126
127#define SERIAL_SPEED  19200//; ///< Set the baud rate for Serial I/O
128/*******************************************************************************************************************
129** Declare global variables and instantiate classes                                                               **
130*******************************************************************************************************************/
131BME680_Class BME680; ///< Create an instance of the BME680
132
133/*!
134* @brief     This converts a pressure measurement into a height in meters
135* @details   The corrected sea-level pressure can be passed into the function if it is know, otherwise the standard 
136*            atmospheric pressure of 1013.25hPa is used (see https://en.wikipedia.org/wiki/Atmospheric_pressure
137* @param[in] seaLevel Sea-Level pressure in millibars
138* @return    floating point altitude in meters.
139*/
140float altitude(const float seaLevel=1013.25) 
141{
142  /*wikipedia equation - original Zanshin code*/
143  static float Altitude;
144  int32_t temp, hum, press, gas;
145  BME680.getSensorData(temp,hum,press,gas); // Get the most recent values from the device
146  Altitude = 44330.0*(1.0-pow(((float)press/100.0)/seaLevel,0.1903)); // Convert into altitude in meters
147  return(Altitude);
148} // of method altitude()
149
150float calculate_altitude( float pressure, bool metric = true, float seaLevelPressure = 101325)
151{
152  /*Equations courtesy of NOAA - code ported from BME280*/;
153  float altitude = NAN;
154  if (!isnan(pressure) && !isnan(seaLevelPressure)){
155    altitude = 1000.0 * ( seaLevelPressure - pressure ) / 3386.3752577878;
156  }
157  return metric ? altitude * 0.3048 : altitude;
158}
159
160float temperatureCompensatedAltitude(int32_t pressure, float temp=21.0 /*Celsius*/, float seaLevel=1013.25) 
161{
162  /*Casio equation - code written by itbrainpower.net*/
163  float Altitude;
164  Altitude = (pow((seaLevel/((float)pressure/100.0)), (1/5.257))-1)*(temp + 273.15) / 0.0065; // Convert into altitude in meters
165  return(Altitude); //this are metric value
166
167
168
169/*!
170    @brief    Arduino method called once at startup to initialize the system
171    @details  This is an Arduino IDE method which is called first upon boot or restart. It is only called one time
172              and then control goes to the main "loop()" method, from which control never returns
173    @return   void
174*/
175void setup()
176{
177  DebugPort.begin(SERIAL_SPEED); // Start serial port at Baud rate
178
179  while(!DebugPort) {delay(10);} // Wait
180
181  //delay(1000);
182
183  DebugPort.println("s-Sense BME68x I2C sensor.");
184  DebugPort.print("- Initializing BME68x sensor\n");
185  while (!BME680.begin(I2C_STANDARD_MODE)) // Start BME68x using I2C protocol
186  {
187    DebugPort.println("-  Unable to find BME68x. Waiting 1 seconds.");
188    delay(1000);
189  } // of loop until device is located
190  DebugPort.println("- Setting 16x oversampling for all sensors");
191  BME680.setOversampling(TemperatureSensor,Oversample16); // Use enumerated type values
192  BME680.setOversampling(HumiditySensor,   Oversample16);
193  BME680.setOversampling(PressureSensor,   Oversample16);
194  DebugPort.println("- Setting IIR filter to a value of 4 samples");
195  BME680.setIIRFilter(IIR4);
196  DebugPort.println("- Setting gas measurement to 320C for 150ms");
197  BME680.setGas(320,150); // 320�c for 150 milliseconds
198  DebugPort.println();
199} // of method setup()
200
201/*!
202    @brief    Arduino method for the main program loop
203    @details  This is the main program for the Arduino IDE, it is an infinite loop and keeps on repeating. 
204    @return   void
205*/
206void loop() 
207{
208  //static uint8_t loopCounter = 0;
209  static int32_t temperature, humidity, pressure, gas;     // Variable to store readings
210  BME680.getSensorData(temperature,humidity,pressure,gas); // Get most recent readings
211  DebugPort.print("\r\nSensor data >>\t\t");                       // Temperature in deci-degrees
212  DebugPort.print(temperature/100.0,2);                       // Temperature in deci-degrees
213  DebugPort.print("C\t");                          
214  DebugPort.print(humidity/1000.0,2);                         // Humidity in milli-percent
215  DebugPort.print("%\t");
216  DebugPort.print(pressure/100.0,2);                          // Pressure in Pascals
217  DebugPort.print("hPa\t");
218  //DebugPort.print(pressure);                          // Pressure in Pascals
219  //DebugPort.print("Pa ");
220  DebugPort.print(gas/100.0,2);
221  DebugPort.println("mOhm");
222
223  DebugPort.println("\r\nCalculated altitude");
224
225  DebugPort.print("temp comp [CASIO equation]: ");
226
227  //temperatureCompensatedAltitude(int32_t pressure, float temp =21.0, const float seaLevel=1013.25)
228  DebugPort.print(temperatureCompensatedAltitude(pressure, temperature/100.0/*, 1022.0*/),2); 
229  DebugPort.print("m\t");
230
231
232  DebugPort.print("NOAA equation: ");
233
234  //float calculate_altitude( float pressure, bool metric = true, float seaLevelPressure = 101325)
235  DebugPort.print(calculate_altitude((long)pressure,true),2); //calculate_altitude
236  //DebugPort.print(calculate_altitude((long)pressure,true, (long)102200.0),2); //calculate_altitude
237  DebugPort.print("m\t");
238
239  DebugPort.print("WIKI equation: ");
240  DebugPort.print(altitude(),2); 
241  DebugPort.println("m \r\n");
242/*  
243Temp: 33.03C            Humidity: 42.03% RH             Pressure: 101058.02 Pa
244Altitude: 78.84m        Dew point: 12.43C               Equivalent Sea Level Pressure: 101950.37 Pa
245
246Temp: 33.01C            Humidity: 40.75% RH             Pressure: 101051.84 Pa
247Altitude: 80.66m        Dew point: 11.71C               Equivalent Sea Level Pressure: 101964.92 Pa
248
249Temp: 32.98C            Humidity: 40.24% RH             Pressure: 101055.34 Pa
250Altitude: 79.63m        Dew point: 11.40C               Equivalent Sea Level Pressure: 101956.80 Pa
251 */
252  delay(1000);
253} // of method loop()
254


c'. The very same code it's available in Arduino "File-> Examples", under "ssense-BME68x" library.

d. Compile and upload the code to your Arduino shield. The sensor data may be seen on Arduino Serial Monitor (set to 19200bps).


Advanced sensor data interpretation - altitude calculation. We've included 3 variants:
- very basic algorithm,
- NOAA based algorithm (function ported from BME280/BMP280 Arduino library),
- CASIO altitude calculation implementation - most accurate altitude calculation based on temperature compensated algorithm...


TUTORIAL PROVIDED WITHOUT ANY WARRANTY!!! USE IT AT YOUR OWN RISK!!!!

 

 

 

 

 

 

Original how to written by Dragos Iosub & itbrainpower.net team

 

 

 

 

document version 0.921 / 2021-05-20 © R&D Software Solutions srl