diff --git a/include/bmp.h b/include/bmp.h new file mode 100644 index 0000000..06264a4 --- /dev/null +++ b/include/bmp.h @@ -0,0 +1,40 @@ +#include + +namespace Bmp { + + Adafruit_BMP280 bmp; // I2C Interface + + void setup() { + Serial.begin(9600); + Serial.println(F("BMP280 test")); + + if (!bmp.begin(0x76)) { + Serial.println(F("Could not find a valid BMP280 sensor, check wiring!")); + while (1); + } + + /* Default settings from datasheet. */ + bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */ + Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */ + Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */ + Adafruit_BMP280::FILTER_X16, /* Filtering. */ + Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */ + } + + void loop() { + Serial.print(F("Temperature = ")); + Serial.print(bmp.readTemperature()); + Serial.println(" *C"); + + Serial.print(F("Pressure = ")); + Serial.print(bmp.readPressure() / 100); //displaying the Pressure in hPa, you can change the unit + Serial.println(" hPa"); + + Serial.print(F("Approx altitude = ")); + Serial.print(bmp.readAltitude(1019.66)); //The "1019.66" is the pressure(hPa) at sea level in day in your region + Serial.println(" m"); //If you don't know it, modify it until you get your current altitude + + Serial.println(); + delay(2000); + } +} \ No newline at end of file diff --git a/include/display.h b/include/display.h index 4cb5caa..7a266eb 100644 --- a/include/display.h +++ b/include/display.h @@ -80,6 +80,11 @@ namespace Display { colonOn = !colonOn; } + void displayFloat(float value) { + clockDisplay.print(value); + clockDisplay.writeDisplay(); + } + void displayValue(int value) { clockDisplay.print(value, HEX); clockDisplay.writeDisplay(); diff --git a/platformio.ini b/platformio.ini index a2fdefd..9530ec0 100644 --- a/platformio.ini +++ b/platformio.ini @@ -21,6 +21,8 @@ lib_deps = ottowinter/AsyncMqttClient-esphome@^0.8.5 crankyoldgit/IRremoteESP8266@^2.7.18 arkhipenko/TaskScheduler@^3.4.0 + adafruit/Adafruit Unified Sensor @ ^1.1.4 + adafruit/Adafruit BMP280 Library@^2.5.0 build_flags = -D IR=1 [env:laptop_home] diff --git a/src/esp_clock.cpp b/src/esp_clock.cpp index 40bee75..cfc19ce 100644 --- a/src/esp_clock.cpp +++ b/src/esp_clock.cpp @@ -17,8 +17,9 @@ Task tWifiConnected(onWifiConnected, &ts); #include "mqtt.h" #include "ota.h" #include "ir.h" +#include "bmp.h" -#define STAY_CONNECTED_AFTER_BOOT 5*60 +#define STAY_CONNECTED_AFTER_BOOT 30*60 void setup() { Serial.begin(9600); @@ -28,6 +29,9 @@ void setup() { Ntp::setup(); Ir::setup(); Mqtt::setup(); + Bmp::setup(); + Display::displayFloat(Bmp::bmp.readTemperature()); + delay(3000); hourChanged.setWaiting(); wifiConnected.setWaiting();