Arduino-Projekte: Anschließen des BME688-Sensors

Lesezeit 8 min.

Messungen von Parametern wie Temperatur, Luftfeuchtigkeit und Druck sind häufig die Grundlage für elektronische Konstruktionen. Allerdings verfügt nicht jeder über das Wissen und die Fähigkeiten, eine Hardwareplattform zu entwickeln, die solche Funktionen selbst ausführt. Aus diesem Grund fällt die Wahl auf gängige Lösungen von der Stange, sowohl was die dem System zugrunde liegende Plattform als auch die Sensoren betrifft, die in einsatzbereiten Modulen erworben werden können. Heute werden Sie sehen, wie Sie den BME688-Sensor an den Arduino anschließen. Benutzung auf eigene Gefahr!

BME688-Sensor

Der BME688 ist ein Gassensor mit künstlicher Intelligenz (AI) und integrierten Feuchtigkeits- und Temperatursensoren mit hoher Linearität und Genauigkeit. Der Gassensor ist in der Lage, flüchtige organische Verbindungen (VOCs), flüchtige Schwefelverbindungen (VSCs) und andere Gase wie Kohlenmonoxid (CO) und Wasserstoff im ppb-Bereich (parts per billion) zu erkennen.

Der Sensor BME 688 ist abwärtskompatibel mit dem BME680. Zusätzlich zu allen Eigenschaften des BME680-Sensors verfügt der BME688 über eine Gasmessfunktion. In einer Standardkonfiguration kann das Vorhandensein von flüchtigen Schwefelverbindungen beispielsweise als Indikator für das Wachstum von Bakterienkolonien interpretiert werden. Der Sensor kann in Bezug auf Empfindlichkeit, Selektivität, Datenrate und Stromverbrauch individuell angepasst werden. Ein Tool namens BME AI-Studio ermöglicht es den Nutzern, die Einstellungen des BME688-Gassensors für bestimmte Anwendungen zu ändern, z. B. in Haushaltsgeräten, IoT-Produkten oder intelligenten Gebäuden.

Die wichtigsten Merkmale des BME688-Sensors:

  • Temperaturmessbereich: -40°C bis 85°C
  • Messbereich Luftfeuchtigkeit: 0% bis 100%
  • Druckmessbereich: 300 hPa bis 1100 hPa
  • Hauptausgänge des Gassensors (über BSEC): IAQ, bVOC und Kohlendioxid-Äquivalent (CO2e) (ppm), Gas-Scan Ergebnis (%) und Intensitätsniveau
  • IAQ-Abweichung (Sensor to Sensor): +/- 15% / +/- 15 IAQ
  • Relative Genauigkeit der Toleranz / Feuchtigkeitshysterese: +/- 3% / ≤ 1,5%
  • Genauigkeit der absoluten Temperatur: +/- 0,5°C (bei +25°C)
  • Fehler bei der Druckmessung: +/- 0,25%

Wie wird der BME688 an den Arduino angeschlossen?

Beim Anschluss des BME688-Sensors an den Arduino ist die Spannung der Hardware-Plattform wichtig. Daher ist es wichtig, sich zu vergewissern, welchen Wert der Versorgungsspannung das Modell, das Sie für Ihr Projekt verwenden möchten, annimmt. Der Sensor akzeptiert Spannungswerte von 3,3V und 5V.

In der folgenden Tabelle finden Sie Informationen darüber, welche Pins Sie anschließen müssen, um den korrekten Betrieb der Haupt-Sensorplatine zu gewährleisten. Sowohl auf der Oberfläche des BME688-Sensors als auch auf der Arduino-Platine finden Sie Markierungen an den Lötfeldern oder Vias/Pins.

BME688 5V Arduino (z.B. UNO) 3,3V Arduino (z.B. Zero)
Vin 5V 3.3V
Vdd (3V3) nicht anschließen nicht anschließen
SDA SDA SDA
SCL SCL SCL
GND GND GND

Anschlussanleitung für einige Arduino-Boards:

  • SDA (Serial Data) –> A4 bei Uno/Pro-Mini, Pin 20 bei Mega2560/Due, Pin 2 Leonardo/Pro-Micro
  • SCK (Serial Clock) –> A5 in Uno/Pro-Mini, Pin 21 in Mega2560/Due, Pin 3 Leonardo/Pro-Micro.

Unten sehen Sie ein grafisches Beispiel für die Erstellung von Verbindungen mit einem Arduino UNO:

Anschlussplan für Adruino UNO mit dem BME688 Sensor

Programmteil. Wie lese ich die Sensordaten aus?

Wenn die einzelnen Signalleitungen richtig angeschlossen sind, können wir mit der Programmierung fortfahren. Lassen Sie uns Schritt für Schritt mit dem Prozess beginnen:

  1. Laden Sie die BME68x Bibliothek für Ihren Arduino herunter. Sie können dies tun, indem Sie HIER klicken.
  2. Entpacken Sie die Bibliothek und installieren Sie sie in den Arduino-Bibliotheksordner. Starten Sie den Arduino neu.
  3. Erstellen Sie einen Ordner mit dem Namen “ssense_BME688_example”.

Kopieren Sie den nachstehenden Code, fügen Sie ihn in eine neue Datei ein und speichern Sie die Datei unter dem Namen “ssense_BME688_example.ino” in dem Ordner, den Sie zuvor erstellt haben, oder laden Sie ihn von hier herunter (verwenden Sie den Befehl “Speichern unter”): BME688 – Sensordaten lesen (Arduino-Code)

				
					/* s-Sense BME68x I2C sensor breakout example - v1.01/20210520. 
 * 
 * Compatible with:
 *    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, 
 *    info https://itbrainpower.net/sensors/BME688
 *    s-Sense BME680 I2C sensor breakout - temperature, humidity, pressure and gas - [PN: SS-BME680#I2C, SKU: ITBP-6003], 
 *    info https://itbrainpower.net/sensors/BME680 
 *
 * This code shows how to use predefined recommended settings for the BME680 air quality sensor. Read temperature,  
 * humidity, pressure and gas sensor data (pulling at 1sec) - code based on based on Zanshin_BME680 library version 
 * 1.0.2 / 2019-01-26 - https://github.com/SV-Zanshin . Good job Zanshin!
 *  
 * Include three functions for altitude calculation (one provided by Zanshin, one ported from BME280/BMP280 library [NOAA equation] and the
 * last one [based on CASIO equation and implementing temperature compensated algorithm] that was written by us.
 *  
 * We've just select the relevant functions, fixed some 328p compiling issues found in original library, add some variables, functions and fuctionalities.
 * 
 * 
 * Mandatory wiring:
 *    Common for 3.3V and 5V Arduino boards:
 *        sensor I2C SDA  <------> Arduino I2C SDA
 *        sensor I2C SCL  <------> Arduino I2C SCL
 *        sensor GND      <------> Arduino GND
 *    For Arduino 3.3V compatible:
 *        sensor Vin      <------> Arduino 3.3V
 *    For Arduino 5V compatible:
 *        sensor Vin      <------> Arduino 5V
 * 
 * Leave other sensor PADS not connected.
 * 
 * SPECIAL note 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
 * 
 * WIRING WARNING: wrong wiring may damage your Arduino board MCU or your sensor! Double check what you've done.
 * 
 * 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.  
 * 
 * READ BME688 documentation! https://itbrainpower.net/sensors/BME688
 * READ BME680 documentation! https://itbrainpower.net/sensors/BME680
 * 
 * We ask you to use this SOFTWARE only in conjunction with s-Sense BME688 or s-Sense BME680 sensor(s) breakout usage. Modifications, derivates 
 * and redistribution of this SOFTWARE must include unmodified this notice. You can redistribute this SOFTWARE and/or modify it under the 
 * terms of this notice. 
 * 
 * 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 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *  
 * itbrainpower.net invests significant time and resources providing those how to and in design phase of our IoT products.
 * Support us by purchasing our environmental and air quality sensors from https://itbrainpower.net/order#s-Sense
 *
 *
 * Dragos Iosub, Bucharest 2021.
 * https://itbrainpower.net
 */

 /*! @file I2CDemo.ino


@section I2CDemo_intro_section Description

Example program for using the Bosch BME680 sensor. The sensor measures temperature, pressure and humidity and  is
described at https://www.bosch-sensortec.com/bst/products/all_products/BME680. The datasheet is available from Bosch
at https://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BME680_DS001-11.pdf \n\n

The most recent version of the BME680 library is available at https://github.com/SV-Zanshin/BME680 and the 
documentation of the library as well as example programs are described in the project's wiki pages located at 
https://github.com/SV-Zanshin/BME680/wiki. \n\n

The BME680 is a very small package so it is unlikely for an Arduino hobbyist to play around with directly, the 
hardware used to develop this library is a breakout board from AdaFruit which is well-documented at
https://learn.adafruit.com/adafruit-BME680-humidity-barometric-pressure-temperature-sensor-breakout \n\n

This example program initializes the BME680 to use I2C for communications. The library does not using floating
point mathematics to save on computation space and time, the values for Temperature, Pressure and Humidity are
returned in deci-units, e.g. a Temperature reading of "2731" means "27.31" degrees Celsius. The display in the 
example program uses floating point for demonstration purposes only.  Note that the temperature reading is 
generally higher than the ambient temperature due to die and PCB temperature and self-heating of the element.\n\n

The pressure reading needs to be adjusted for altitude to get the adjusted pressure reading. There are numerous
sources on the internet for formula converting from standard sea-level pressure to altitude, see the data sheet
for the BME180 on page 16 of http://www.adafruit.com/datasheets/BST-BMP180-DS000-09.pdf. Rather than put a
floating-point function in the library which may not be used but which would use space, an example altitude
computation function has been added to this example program to show how it might be done.

@section I2CDemolicense License

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General
Public License as published by the Free Software Foundation, either version 3 of the License, or (at your
option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details. You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

@section I2CDemoauthor Author

Written by Arnd\@SV-Zanshin

@section I2CDemoversions Changelog

Version | Date       | Developer           | Comments
------- | ---------- | ------------------- | --------
1.0.1   | 2019-01-26 | https://github.com/SV-Zanshin | Issue #3 - convert documentation to Doxygen
1.0.0b  | 2018-06-30 | https://github.com/SV-Zanshin | Cloned from original BME280 program

*/

/*******************************************************************************************************************
**                                                                                                                **
** This program is free software: you can redistribute it and/or modify it under the terms of the GNU General     **
** Public License as published by the Free Software Foundation, either version 3 of the License, or (at your      **
** option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY     **
** WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   **
** GNU General Public License for more details. You should have received a copy of the GNU General Public License **
** along with this program.  If not, see <http://www.gnu.org/licenses/>.                                          **
**                                                                                                                **
** Vers.  Date       Developer                     Comments                                                       **
** ====== ========== ============================= ============================================================== **
** 1.0.0b 2018-06-30 https://github.com/SV-Zanshin Cloned from original BME280 program                            **
**                                                                                                                **
*******************************************************************************************************************/
#include "sSense_BME680.h" // Include the BME680 Sensor library
/*******************************************************************************************************************
** Declare all program constants                                                                                  **
*******************************************************************************************************************/

#define SERIAL_SPEED  19200//; ///< Set the baud rate for Serial I/O
/*******************************************************************************************************************
** Declare global variables and instantiate classes                                                               **
*******************************************************************************************************************/
BME680_Class BME680; ///< Create an instance of the BME680

/*!
* @brief     This converts a pressure measurement into a height in meters
* @details   The corrected sea-level pressure can be passed into the function if it is know, otherwise the standard 
*            atmospheric pressure of 1013.25hPa is used (see https://en.wikipedia.org/wiki/Atmospheric_pressure
* @param[in] seaLevel Sea-Level pressure in millibars
* @return    floating point altitude in meters.
*/
float altitude(const float seaLevel=1013.25) 
{
  /*wikipedia equation - original Zanshin code*/
  static float Altitude;
  int32_t temp, hum, press, gas;
  BME680.getSensorData(temp,hum,press,gas); // Get the most recent values from the device
  Altitude = 44330.0*(1.0-pow(((float)press/100.0)/seaLevel,0.1903)); // Convert into altitude in meters
  return(Altitude);
} // of method altitude()

float calculate_altitude( float pressure, bool metric = true, float seaLevelPressure = 101325)
{
  /*Equations courtesy of NOAA - code ported from BME280*/;
  float altitude = NAN;
  if (!isnan(pressure) && !isnan(seaLevelPressure)){
    altitude = 1000.0 * ( seaLevelPressure - pressure ) / 3386.3752577878;
  }
  return metric ? altitude * 0.3048 : altitude;
}

float temperatureCompensatedAltitude(int32_t pressure, float temp=21.0 /*Celsius*/, float seaLevel=1013.25) 
{
  /*Casio equation - code written by itbrainpower.net*/
  float Altitude;
  Altitude = (pow((seaLevel/((float)pressure/100.0)), (1/5.257))-1)*(temp + 273.15) / 0.0065; // Convert into altitude in meters
  return(Altitude);	//this are metric value
} 


/*!
    @brief    Arduino method called once at startup to initialize the system
    @details  This is an Arduino IDE method which is called first upon boot or restart. It is only called one time
              and then control goes to the main "loop()" method, from which control never returns
    @return   void
*/
void setup()
{
  DebugPort.begin(SERIAL_SPEED); // Start serial port at Baud rate

  while(!DebugPort) {delay(10);} // Wait

  //delay(1000);

  DebugPort.println("s-Sense BME68x I2C sensor.");
  DebugPort.print("- Initializing BME68x sensor\n");
  while (!BME680.begin(I2C_STANDARD_MODE)) // Start BME68x using I2C protocol
  {
    DebugPort.println("-  Unable to find BME68x. Waiting 1 seconds.");
    delay(1000);
  } // of loop until device is located
  DebugPort.println("- Setting 16x oversampling for all sensors");
  BME680.setOversampling(TemperatureSensor,Oversample16); // Use enumerated type values
  BME680.setOversampling(HumiditySensor,   Oversample16);
  BME680.setOversampling(PressureSensor,   Oversample16);
  DebugPort.println("- Setting IIR filter to a value of 4 samples");
  BME680.setIIRFilter(IIR4);
  DebugPort.println("- Setting gas measurement to 320C for 150ms");
  BME680.setGas(320,150); // 320�c for 150 milliseconds
  DebugPort.println();
} // of method setup()

/*!
    @brief    Arduino method for the main program loop
    @details  This is the main program for the Arduino IDE, it is an infinite loop and keeps on repeating. 
    @return   void
*/
void loop() 
{
  //static uint8_t loopCounter = 0;
  static int32_t temperature, humidity, pressure, gas;     // Variable to store readings
  BME680.getSensorData(temperature,humidity,pressure,gas); // Get most recent readings
  DebugPort.print("\r\nSensor data >>\t\t");                       // Temperature in deci-degrees
  DebugPort.print(temperature/100.0,2);                       // Temperature in deci-degrees
  DebugPort.print("C\t");                          
  DebugPort.print(humidity/1000.0,2);                         // Humidity in milli-percent
  DebugPort.print("%\t");
  DebugPort.print(pressure/100.0,2);                          // Pressure in Pascals
  DebugPort.print("hPa\t");
  //DebugPort.print(pressure);                          // Pressure in Pascals
  //DebugPort.print("Pa ");
  DebugPort.print(gas/100.0,2);
  DebugPort.println("mOhm");

  DebugPort.println("\r\nCalculated altitude");

  DebugPort.print("temp comp [CASIO equation]: ");

  //temperatureCompensatedAltitude(int32_t pressure, float temp =21.0, const float seaLevel=1013.25)
  DebugPort.print(temperatureCompensatedAltitude(pressure, temperature/100.0/*, 1022.0*/),2); 
  DebugPort.print("m\t");


  DebugPort.print("NOAA equation: ");

  //float calculate_altitude( float pressure, bool metric = true, float seaLevelPressure = 101325)
  DebugPort.print(calculate_altitude((long)pressure,true),2); //calculate_altitude
  //DebugPort.print(calculate_altitude((long)pressure,true, (long)102200.0),2); //calculate_altitude
  DebugPort.print("m\t");

  DebugPort.print("WIKI equation: ");
  DebugPort.print(altitude(),2); 
  DebugPort.println("m \r\n");
/*  
Temp: 33.03C            Humidity: 42.03% RH             Pressure: 101058.02 Pa
Altitude: 78.84m        Dew point: 12.43C               Equivalent Sea Level Pressure: 101950.37 Pa

Temp: 33.01C            Humidity: 40.75% RH             Pressure: 101051.84 Pa
Altitude: 80.66m        Dew point: 11.71C               Equivalent Sea Level Pressure: 101964.92 Pa

Temp: 32.98C            Humidity: 40.24% RH             Pressure: 101055.34 Pa
Altitude: 79.63m        Dew point: 11.40C               Equivalent Sea Level Pressure: 101956.80 Pa
 */
  delay(1000);
} // of method loop()
				
			

4. Derselbe Code ist in der Arduino-Sektion “File -> Examples” in der Bibliothek “ssense-BME68x” verfügbar.

5. kompilieren Sie den Code und programmieren Sie Ihren Arduino. Die Sensordaten können auf dem Monitor der seriellen Schnittstelle des Arduino angezeigt werden (eingestellt auf 19200b/s).

Erweiterte Sensordatenanalyse – Höhenberechnung. Drei Optionen wurden in Betracht gezogen:
– grundlegender Algorithmus,
– NOAA-basierter Algorithmus (Funktion aus der Arduino-Bibliothek BME280/BMP280 portiert),
– CASIO Höhenberechnung – die genaueste Höhenberechnung basierend auf einem temperaturkompensierten Algorithmus.

Artikel veröffentlicht mit der Erlaubnis von: itbrainpower.net

Wie hilfreich war dieser Beitrag?

Klicke auf die Sterne um zu bewerten!

Durchschnittliche Bewertung 5 / 5. Stimmenzahl: 5

Bisher keine Bewertungen! Sei der Erste, der diesen Beitrag bewertet.

Teilen:

Picture of Maciej Figiel

Maciej Figiel

Vielseitig, bereit Herausforderungen anzunehmen, weil er überzeugt ist, dass dies der schnellste Weg ist sich zu entwickeln. Er schätzt den Kontakt mit der Natur und die aktive Erholung. Hat eine Leidenschaft für Autos und neue Technologien.

Siehe mehr:

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Aus Sicherheitsgründen ist die Verwendung des reCAPTCHA-Dienstes von Google erforderlich, der den Google-Datenschutzbestimmungen und Nutzungsbedingungen unterliegt..