Browse Source

add BME680

split_files
Hendrik Langer 5 years ago
parent
commit
25887fc70d
  1. 1
      README.md
  2. 2
      platformio.ini
  3. 40
      src/main.cpp

1
README.md

@ -32,3 +32,4 @@ This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md
* [PlatformIO](https://platformio.org) - Cross-platform IDE
* [GxEPD2](https://github.com/ZinggJM/GxEPD2) - E-Paper display library
* [Adafruit BME680](https://github.com/adafruit/Adafruit_BME680) - BME680 Sensor Library

2
platformio.ini

@ -26,6 +26,8 @@ build_flags =
lib_deps =
GxEPD2
Adafruit GFX Library
Adafruit BME680 Library
Adafruit Unified Sensor
; ArduinoJSON
monitor_speed = 115200

40
src/main.cpp

@ -8,12 +8,21 @@
#include <WiFi.h>
#include <WiFiMulti.h>
#include <Wire.h>
#include <SPI.h>
#include <GxEPD2_BW.h>
#include <Fonts/FreeMonoBold9pt7b.h>
#include "bitmaps/Bitmaps128x250.h"
#include <Adafruit_Sensor.h>
#include "Adafruit_BME680.h"
static const char* TAG = "MAIN";
WiFiMulti wifiMulti;
GxEPD2_BW<GxEPD2_213_B72, GxEPD2_213_B72::HEIGHT> display(GxEPD2_213_B72(/*CS=TFT_CS*/ SS, /*DC=*/ TFT_DC, /*RST=*/ TFT_RST, /*BUSY=*/ -1)); // GDEH0213B72
Adafruit_BME680 bme; // I2C (also available: hardware SPI
void helloWorld()
{
@ -50,6 +59,17 @@ void setup()
helloWorld();
display.powerOff();
if (!bme.begin()) {
ESP_LOGE(TAG, "Could not find a valid BME680 sensor, check wiring!");
}
// 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
wifiMulti.addAP(WIFI_SSID, WIFI_PASSWD);
wifiMulti.addAP(WIFI_SSID2, WIFI_PASSWD2);
@ -64,8 +84,28 @@ void setup()
void loop()
{
unsigned long endTime = bme.beginReading();
if (! bme.performReading()) {
ESP_LOGE(TAG, "BME680: Failed to perform reading :(");
return;
}
Serial.print("Temperature = "); Serial.print(bme.temperature); Serial.println(" *C");
display.print("Temperature: "); display.print(bme.temperature); display.println(" *C");
Serial.print("Pressure = "); Serial.print(bme.pressure / 100.0); Serial.println(" hPa");
display.print("Pressure: "); display.print(bme.pressure / 100); display.println(" hPa");
Serial.print("Humidity = "); Serial.print(bme.humidity); Serial.println(" %");
display.print("Humidity: "); display.print(bme.humidity); display.println(" %");
Serial.print("Gas = "); Serial.print(bme.gas_resistance / 1000.0); Serial.println(" KOhms");
display.print("Gas: "); display.print(bme.gas_resistance / 1000.0); display.println(" KOhms");
if(wifiMulti.run() != WL_CONNECTED) {
Serial.println("WiFi not connected!");
delay(1000);
}
delay(1000);
}

Loading…
Cancel
Save