In this project we will create an environmental system with aBME680 and a Wemos Mini and we will then display the readings on an OLED display
First of all the BME680 sensor
BME680 is an integrated environmental sensor developed specifically for mobile applications and wearables where size and low power consumption are key requirements. Expanding Bosch Sensortec’s existing family of environmental sensors, the BME680 integrates for the first time high-linearity and high-accuracy gas, pressure, humidity and temperature sensors. The gas sensor within the BME680 can detect a broad range of gases to measure air quality for personal well being.
Gases that can be detected by the BME680 include Volatile Organic Compounds (VOC) from paints (such as formaldehyde), lacquers, paint strippers, cleaning supplies, furnishings, office equipment, glues, adhesives and alcohol.
Requirements
Lets take a look a the shields and boards that are required for this project
Parts List
I connect the Wemos Mini to the dual base and then put the OLED shield along side this, I then connect the BM680 sensor to the OLED or the spare base
Schematic
We use the I2C connection for the sensor – this shows the sensor connected to the OLED shield
Code
You will need to import the adafruit sensor and bme680 libraries – you can add these using the library manager
My particular sensor used address 0x76, the default is 0x77 so you may have to change this line from if (!bme.begin(0x76)) to if (!bme.begin())
For the oled you need https://github.com/sparkfun/SparkFun_Micro_OLED_Arduino_Library
[codesyntax lang=”cpp”]
#include <Wire.h> #include <SPI.h> #include <Adafruit_Sensor.h> #include "Adafruit_BME680.h" #include <SFE_MicroOLED.h> // Include the SFE_MicroOLED library #define PIN_RESET 255 // #define DC_JUMPER 0 // I2C Addres: 0 - 0x3C, 1 - 0x3D #define SEALEVELPRESSURE_HPA (1013.25) MicroOLED oled(PIN_RESET, DC_JUMPER); // Example I2C declaration Adafruit_BME680 bme; // I2C void setup() { Serial.begin(9600); while (!Serial); Serial.println(F("BME680 test")); if (!bme.begin(0x76)) { Serial.println("Could not find a valid BME680 sensor, check wiring!"); while (1); } // Set up oversampling and filter initialization bme.setTemperatureOversampling(BME680_OS_8X); bme.setHumidityOversampling(BME680_OS_2X); bme.setPressureOversampling(BME680_OS_4X); bme.setIIRFilterSize(BME680_FILTER_SIZE_3); bme.setGasHeater(320, 150); // 320*C for 150 ms //start the OLED oled.begin(); oled.clear(ALL); // Clear the display's memory (gets rid of artifacts) oled.display(); } void loop() { if (! bme.performReading()) { Serial.println("Failed to perform reading :("); return; } oled.clear(PAGE); oled.setFontType(0); // set font type 0, please see declaration in SFE_MicroOLED.cpp oled.setCursor(1, 3); oled.print("Humidity = "); oled.setCursor(1, 12); oled.print(bme.humidity); oled.print(" %"); oled.setCursor(1, 21); oled.print("Temp ="); oled.setCursor(1, 30); oled.print(bme.temperature); oled.print(" *C "); oled.display(); delay(2000); //2nd page of readings oled.clear(PAGE); oled.setFontType(0); // set font type 0, please see declaration in SFE_MicroOLED.cpp oled.setCursor(1, 3); oled.print("Altitude = "); oled.setCursor(1, 12); oled.print(bme.readAltitude(SEALEVELPRESSURE_HPA)); oled.print(" m"); oled.setCursor(1, 21); oled.print("Sea Level="); oled.setCursor(1, 30); oled.print(bme.pressure / 100.0); oled.print(" hPa"); oled.display(); delay(2000); //3rd page of readings oled.clear(PAGE); oled.setFontType(0); // set font type 0, please see declaration in SFE_MicroOLED.cpp oled.setCursor(1, 3); oled.print("Gas = "); oled.setCursor(1, 12); oled.print(bme.gas_resistance / 1000.0); oled.println(" KOhms"); oled.display(); delay(2000); }
[/codesyntax]
Download the example from – ESP8266_OLED_and_BME680