Browse Source

add bme680

ir
Hendrik Langer 5 years ago
parent
commit
1c61a25d2c
  1. 1
      platformio.ini
  2. 111
      src/main.cpp

1
platformio.ini

@ -36,6 +36,7 @@ lib_deps =
; https://github.com/wemos/LOLIN_EPD_Library ; https://github.com/wemos/LOLIN_EPD_Library
Adafruit GFX Library Adafruit GFX Library
Adafruit BME280 Library Adafruit BME280 Library
Adafruit BME680 Library
Adafruit Unified Sensor Adafruit Unified Sensor
Adafruit BusIO Adafruit BusIO
Adafruit VEML6075 Library Adafruit VEML6075 Library

111
src/main.cpp

@ -20,6 +20,7 @@
#include <Adafruit_Sensor.h> #include <Adafruit_Sensor.h>
#include "Adafruit_BME280.h" #include "Adafruit_BME280.h"
#include "Adafruit_BME680.h"
#include "Adafruit_VEML6075.h" #include "Adafruit_VEML6075.h"
@ -39,7 +40,8 @@ static const char* TAG = "MAIN";
WiFiMulti wifiMulti; WiFiMulti wifiMulti;
GxEPD2_BW<GxEPD2_213_B72, GxEPD2_213_B72::HEIGHT> display(GxEPD2_213_B72(/*CS=SS*/ TFT_CS, /*DC=*/ TFT_DC, /*RST=*/ TFT_RST, /*BUSY=*/ -1)); // GDEH0213B72 GxEPD2_BW<GxEPD2_213_B72, GxEPD2_213_B72::HEIGHT> display(GxEPD2_213_B72(/*CS=SS*/ TFT_CS, /*DC=*/ TFT_DC, /*RST=*/ TFT_RST, /*BUSY=*/ -1)); // GDEH0213B72
Adafruit_BME280 bme; // I2C (also available: hardware SPI Adafruit_BME280 bme280; // I2C (also available: hardware SPI
Adafruit_BME680 bme680; // I2C (also available: hardware SPI
//HardwareSerial Serial2(2); //HardwareSerial Serial2(2);
SdsDustSensor sds(Serial2); SdsDustSensor sds(Serial2);
Adafruit_VEML6075 uv = Adafruit_VEML6075(); Adafruit_VEML6075 uv = Adafruit_VEML6075();
@ -48,7 +50,8 @@ XD0OTA ota("esp32-weatherstation");
XD0MQTT mqtt; XD0MQTT mqtt;
uint32_t lastDisplayUpdate = 0; uint32_t lastDisplayUpdate = 0;
bool bme_active = false; bool bme280_active = false;
bool bme680_active = false;
bool uv_active = false; bool uv_active = false;
bool sds_active = false; bool sds_active = false;
@ -102,23 +105,45 @@ void getTime(char* ptr, size_t maxsize, const char* format) {
void printValues() { void printValues() {
if (bme_active) { if (bme280_active) {
#define SEALEVELPRESSURE_HPA (1013.25) #define SEALEVELPRESSURE_HPA (1013.25)
Serial.print("Temperature = "); Serial.print("Temperature = ");
Serial.print(bme.readTemperature()); Serial.print(bme280.readTemperature());
Serial.println(" *C"); Serial.println(" *C");
Serial.print("Pressure = "); Serial.print("Pressure = ");
Serial.print(bme.readPressure() / 100.0F); Serial.print(bme280.readPressure() / 100.0F);
Serial.println(" hPa"); Serial.println(" hPa");
Serial.print("Approx. Altitude = "); Serial.print("Approx. Altitude = ");
Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA)); Serial.print(bme280.readAltitude(SEALEVELPRESSURE_HPA));
Serial.println(" m"); Serial.println(" m");
Serial.print("Humidity = "); Serial.print("Humidity = ");
Serial.print(bme.readHumidity()); Serial.print(bme280.readHumidity());
Serial.println(" %");
Serial.println();
}
if (bme680_active) {
#define SEALEVELPRESSURE_HPA (1013.25)
Serial.print("Temperature = ");
Serial.print(bme680.readTemperature());
Serial.println(" *C");
Serial.print("Pressure = ");
Serial.print(bme680.readPressure() / 100.0F);
Serial.println(" hPa");
Serial.print("Approx. Altitude = ");
Serial.print(bme680.readAltitude(SEALEVELPRESSURE_HPA));
Serial.println(" m");
Serial.print("Humidity = ");
Serial.print(bme680.readHumidity());
Serial.println(" %"); Serial.println(" %");
Serial.println(); Serial.println();
@ -150,16 +175,30 @@ void printValues() {
void sendValues() { void sendValues() {
/* send values MQTT */ /* send values MQTT */
if (bme_active) { if (bme280_active) {
String topic_temperature = String("thomas/sensor/") + ota.getMAC() + String("/temperature");
String topic_humidity = String("thomas/sensor/") + ota.getMAC() + String("/humidity");
String topic_pressure = String("thomas/sensor/") + ota.getMAC() + String("/pressure");
char temperature[8]; sprintf(temperature, "%.2f", bme280.readTemperature());
char humidity[7]; sprintf(humidity, "%.2f", bme280.readHumidity());
char pressure[8]; sprintf(pressure, "%.2f", bme280.readPressure() / 100.0F);
mqtt.publish(topic_temperature.c_str(), temperature, strlen(temperature));
mqtt.publish(topic_humidity.c_str(), humidity, strlen(humidity));
mqtt.publish(topic_pressure.c_str(), pressure, strlen(pressure));
} else if (bme680_active) {
bme680.performReading();
String topic_temperature = String("thomas/sensor/") + ota.getMAC() + String("/temperature"); String topic_temperature = String("thomas/sensor/") + ota.getMAC() + String("/temperature");
String topic_humidity = String("thomas/sensor/") + ota.getMAC() + String("/humidity"); String topic_humidity = String("thomas/sensor/") + ota.getMAC() + String("/humidity");
String topic_pressure = String("thomas/sensor/") + ota.getMAC() + String("/pressure"); String topic_pressure = String("thomas/sensor/") + ota.getMAC() + String("/pressure");
char temperature[8]; sprintf(temperature, "%.2f", bme.readTemperature()); String topic_voc = String("thomas/sensor/") + ota.getMAC() + String("/voc");
char humidity[7]; sprintf(humidity, "%.2f", bme.readHumidity()); char temperature[8]; sprintf(temperature, "%.2f", bme680.readTemperature());
char pressure[8]; sprintf(pressure, "%.2f", bme.readPressure() / 100.0F); char humidity[7]; sprintf(humidity, "%.2f", bme680.readHumidity());
char pressure[8]; sprintf(pressure, "%.2f", bme680.readPressure() / 100.0F);
char voc[12]; sprintf(voc, "%.2f", bme680.gas_resistance / 1000.0F);
mqtt.publish(topic_temperature.c_str(), temperature, strlen(temperature)); mqtt.publish(topic_temperature.c_str(), temperature, strlen(temperature));
mqtt.publish(topic_humidity.c_str(), humidity, strlen(humidity)); mqtt.publish(topic_humidity.c_str(), humidity, strlen(humidity));
mqtt.publish(topic_pressure.c_str(), pressure, strlen(pressure)); mqtt.publish(topic_pressure.c_str(), pressure, strlen(pressure));
mqtt.publish(topic_voc.c_str(), voc, strlen(voc));
} else { } else {
String topic_temperature = String("thomas/sensor/") + ota.getMAC() + String("/temperature"); String topic_temperature = String("thomas/sensor/") + ota.getMAC() + String("/temperature");
float esp32_temperature = (temprature_sens_read() - 32) / 1.8; float esp32_temperature = (temprature_sens_read() - 32) / 1.8;
@ -220,19 +259,25 @@ void setup()
#define BME_SDA 21 #define BME_SDA 21
#define BME_SCL 22 #define BME_SCL 22
Wire.begin(BME_SDA, BME_SCL); Wire.begin(BME_SDA, BME_SCL);
if (bme.begin()) { if (bme280.begin()) {
bme_active = true; bme280_active = true;
} else { } else {
ESP_LOGE(TAG, "Could not find a valid BME280 sensor, check wiring!"); ESP_LOGE(TAG, "Could not find a valid BME280 sensor, check wiring!");
} }
/* if (bme680.begin()) {
bme680_active = true;
} else {
ESP_LOGE(TAG, "Could not find a valid BME680 sensor, check wiring!");
}
if (bme680_active) {
// Set up oversampling and filter initialization // Set up oversampling and filter initialization
bme.setTemperatureOversampling(BME680_OS_8X); bme680.setTemperatureOversampling(BME680_OS_8X);
bme.setHumidityOversampling(BME680_OS_2X); bme680.setHumidityOversampling(BME680_OS_2X);
bme.setPressureOversampling(BME680_OS_4X); bme680.setPressureOversampling(BME680_OS_4X);
bme.setIIRFilterSize(BME680_FILTER_SIZE_3); bme680.setIIRFilterSize(BME680_FILTER_SIZE_3);
bme.setGasHeater(320, 150); // 320*C for 150 ms bme680.setGasHeater(320, 150); // 320*C for 150 ms
*/ }
if (uv.begin()) { if (uv.begin()) {
uv_active = true; uv_active = true;
@ -307,22 +352,38 @@ void loop()
{ {
display.fillScreen(GxEPD_WHITE); display.fillScreen(GxEPD_WHITE);
display.setTextColor(GxEPD_BLACK); display.setTextColor(GxEPD_BLACK);
display.setFont(&FreeSans9pt7b);
display.setTextWrap(false); display.setTextWrap(false);
display.setCursor(0, 11); display.setCursor(0, 11);
display.setFont(&FreeSans9pt7b);
display.println("ESP32-Wetterstation"); display.println("ESP32-Wetterstation");
display.drawFastHLine(0, 14, display.width(), GxEPD_BLACK); display.drawFastHLine(0, 14, display.width(), GxEPD_BLACK);
display.setCursor(0, 32); display.setCursor(0, 32);
if (bme_active) { if (bme280_active) {
display.print("Temperatur: ");
display.print(bme280.readTemperature());
display.println(" *C");
display.print("Luftfeuchte: ");
display.print(bme280.readHumidity());
display.println(" %");
display.print("Luftdruck:");
display.print(bme280.readPressure() / 100.0F);
display.println(" hPa");
} else if (bme680_active) {
if (! bme680.performReading()) {
Serial.println("Failed to perform reading :(");
}
display.print("Temperatur: "); display.print("Temperatur: ");
display.print(bme.readTemperature()); display.print(bme680.readTemperature());
display.println(" *C"); display.println(" *C");
display.print("Luftfeuchte: "); display.print("Luftfeuchte: ");
display.print(bme.readHumidity()); display.print(bme680.readHumidity());
display.println(" %"); display.println(" %");
display.print("Luftdruck: "); display.print("Luftdruck: ");
display.print(bme.readPressure() / 100.0F); display.print(bme680.readPressure() / 100.0F);
display.println(" hPa"); display.println(" hPa");
display.print("Gas: ");
display.print(bme680.gas_resistance / 1000.0);
display.println(" KOhms");
} else { } else {
display.print("Temperatur: "); display.print("Temperatur: ");
float esp32_temperature = (temprature_sens_read() - 32) / 1.8; float esp32_temperature = (temprature_sens_read() - 32) / 1.8;

Loading…
Cancel
Save