From 00754ff572135092030f5c58d847cc83a4e2fcda Mon Sep 17 00:00:00 2001 From: Michael Taggatz Date: Tue, 30 Jan 2018 16:38:35 +0100 Subject: [PATCH 1/2] Adding appBME280 to M5Stack-SAM, APPS and GFX_MENU, to read from a Grove - Barometer Sensor. --- M5Stack-SAM/APPS.ino | 32 +++++++++++++++++++++++++++++++- M5Stack-SAM/GFX_MENU.ino | 10 +++++++++- M5Stack-SAM/M5Stack-SAM.ino | 13 +++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/M5Stack-SAM/APPS.ino b/M5Stack-SAM/APPS.ino index 7ab385f..5195e75 100644 --- a/M5Stack-SAM/APPS.ino +++ b/M5Stack-SAM/APPS.ino @@ -33,7 +33,6 @@ void appBLEBaecon(){ menuUpdate(menuidx, menulock); } - void appDHT12(){ menuDrawMenu(F("DHT12"),F(""),F("ESC"),F(""),sys_menucolor,sys_windowcolor,sys_menutextcolor); M5.Lcd.drawString(F("TEMPERATURE"),30,80,2); @@ -60,6 +59,37 @@ void appDHT12(){ menuUpdate(menuidx, menulock); } + +void appBME280(){ + menuDrawMenu(F("BME280"),F(""),F("ESC"),F(""),sys_menucolor,sys_windowcolor,sys_menutextcolor); + M5.Lcd.drawString(F("TEMPERATURE"),30,60,2); + M5.Lcd.drawString(F("°C"),250,60,2); + M5.Lcd.drawString(F("HUMIDITY"),30,120,2); + M5.Lcd.drawString(F("%RH"),250,120,2); + M5.Lcd.drawString(F("PRESSURE"),30,180,2); + M5.Lcd.drawString(F("hPa"),250,180,2); + menuidx = 1; + menulock = 0; + M5.Lcd.setTextColor(sys_menutextcolor, sys_windowcolor); + while(M5.BtnB.wasPressed()){ + M5.update(); + } + while(!M5.BtnB.wasPressed()){ + M5.update(); + if(millis()-tmp_tmr > 1000){ + tmp_tmr = millis(); + float tmp_temp = bme280.readTemperature(); + float tmp_humi = bme280.readHumidity(); + float tmp_pres = (bme280.readPressure()/100.0F); + //menuWindowClr(sys_windowcolor); + M5.Lcd.drawFloat(tmp_temp, 1, 140, 40, 6); + M5.Lcd.drawFloat(tmp_humi, 1, 140, 100, 6); + M5.Lcd.drawFloat(tmp_pres, 1, 140, 160, 6); + } + } + menuUpdate(menuidx, menulock); +} + void appStopky(){ boolean tmp_run = false; float tmp_sec = 0; diff --git a/M5Stack-SAM/GFX_MENU.ino b/M5Stack-SAM/GFX_MENU.ino index 5cbe9da..2fe57c1 100644 --- a/M5Stack-SAM/GFX_MENU.ino +++ b/M5Stack-SAM/GFX_MENU.ino @@ -112,7 +112,7 @@ void menuSystemLevel(byte inmenuidx){ void menuAplikaceLevel(byte inmenuidx){ menuidxmin = 0; - menuidxmax = 4; + menuidxmax = 5; switch (inmenuidx) { case 0: menuIsMenu = LOW; @@ -135,6 +135,11 @@ void menuAplikaceLevel(byte inmenuidx){ windowPrintInfoText(F("BLE Beacon SIMULATOR"),sys_menutextcolor); break; case 4: + menuIsMenu = LOW; + menuWindowClr(sys_windowcolor); + windowPrintInfoText(F("BME280"),sys_menutextcolor); + break; + case 5: menuIsMenu = LOW; menuWindowClr(sys_windowcolor); windowPrintInfoText(F("RETURN"),sys_menutextcolor); @@ -178,6 +183,9 @@ void menuRunApp(byte inmenuidx, byte inmenulock){ appBLEBaecon(); } if(inmenulock==1 and inmenuidx==4){ + appBME280(); + } + if(inmenulock==1 and inmenuidx==5){ menuidx = 1; menulock = 0; menuUpdate(menuidx, menulock); diff --git a/M5Stack-SAM/M5Stack-SAM.ino b/M5Stack-SAM/M5Stack-SAM.ino index 3462be8..834fd50 100644 --- a/M5Stack-SAM/M5Stack-SAM.ino +++ b/M5Stack-SAM/M5Stack-SAM.ino @@ -1,12 +1,18 @@ #include #include "EEPROM.h" #include "utility/DHT12.h" +#include // appBME280 +#include // appBME280 #include #include "SimpleBeacon.h" SimpleBeacon ble; DHT12 dht12; +#define SEALEVELPRESSURE_HPA (1013.25) // appBME280 +Adafruit_BME280 bme280; // appBME280 +bool status; // appBME280 + #define TFT_GREY 0x5AEB #define TFT_BROWN 0x38E0 @@ -29,6 +35,13 @@ unsigned long tmp_tmr = 0; void setup(void) { Serial.begin(115200); + + status = bme280.begin(0x76); +// if (!status) { +// Serial.println("Could not find a valid BME280 sensor, check wiring!"); +// while (1); +// } + if (!EEPROM.begin(EEPROM_SIZE)) { From 3249b8246d44197ee513b3d776fa6399738cd3a6 Mon Sep 17 00:00:00 2001 From: Michael Taggatz Date: Sun, 4 Feb 2018 11:08:46 +0100 Subject: [PATCH 2/2] Adding #define WEATHER_SENSOR to compile with appDHT12, or instead with appBME280. --- M5Stack-SAM/APPS.ino | 4 +++- M5Stack-SAM/GFX_MENU.ino | 22 ++++++++++----------- M5Stack-SAM/M5Stack-SAM.ino | 39 ++++++++++++++++++++++++------------- 3 files changed, 40 insertions(+), 25 deletions(-) diff --git a/M5Stack-SAM/APPS.ino b/M5Stack-SAM/APPS.ino index 5195e75..c08ff98 100644 --- a/M5Stack-SAM/APPS.ino +++ b/M5Stack-SAM/APPS.ino @@ -33,6 +33,7 @@ void appBLEBaecon(){ menuUpdate(menuidx, menulock); } +#if defined(WS_DHT12) void appDHT12(){ menuDrawMenu(F("DHT12"),F(""),F("ESC"),F(""),sys_menucolor,sys_windowcolor,sys_menutextcolor); M5.Lcd.drawString(F("TEMPERATURE"),30,80,2); @@ -59,7 +60,7 @@ void appDHT12(){ menuUpdate(menuidx, menulock); } - +#elif defined(WS_BME280) void appBME280(){ menuDrawMenu(F("BME280"),F(""),F("ESC"),F(""),sys_menucolor,sys_windowcolor,sys_menutextcolor); M5.Lcd.drawString(F("TEMPERATURE"),30,60,2); @@ -89,6 +90,7 @@ void appBME280(){ } menuUpdate(menuidx, menulock); } +#endif void appStopky(){ boolean tmp_run = false; diff --git a/M5Stack-SAM/GFX_MENU.ino b/M5Stack-SAM/GFX_MENU.ino index 2fe57c1..88d54ce 100644 --- a/M5Stack-SAM/GFX_MENU.ino +++ b/M5Stack-SAM/GFX_MENU.ino @@ -112,12 +112,16 @@ void menuSystemLevel(byte inmenuidx){ void menuAplikaceLevel(byte inmenuidx){ menuidxmin = 0; - menuidxmax = 5; + menuidxmax = 4; switch (inmenuidx) { case 0: menuIsMenu = LOW; menuWindowClr(sys_windowcolor); - windowPrintInfoText(F("DHT12"),sys_menutextcolor); + #if defined(WS_DHT12) + windowPrintInfoText(F("DHT12"),sys_menutextcolor); + #elif defined(WS_BME280) + windowPrintInfoText(F("BME280"),sys_menutextcolor); + #endif break; case 1: menuIsMenu = LOW; @@ -135,11 +139,6 @@ void menuAplikaceLevel(byte inmenuidx){ windowPrintInfoText(F("BLE Beacon SIMULATOR"),sys_menutextcolor); break; case 4: - menuIsMenu = LOW; - menuWindowClr(sys_windowcolor); - windowPrintInfoText(F("BME280"),sys_menutextcolor); - break; - case 5: menuIsMenu = LOW; menuWindowClr(sys_windowcolor); windowPrintInfoText(F("RETURN"),sys_menutextcolor); @@ -171,7 +170,11 @@ void menuRunApp(byte inmenuidx, byte inmenulock){ } if(inmenulock==1 and inmenuidx==0){ - appDHT12(); + #if defined(WS_DHT12) + appDHT12(); + #elif defined(WS_BME280) + appBME280(); + #endif } if(inmenulock==1 and inmenuidx==1){ appStopky(); @@ -183,9 +186,6 @@ void menuRunApp(byte inmenuidx, byte inmenulock){ appBLEBaecon(); } if(inmenulock==1 and inmenuidx==4){ - appBME280(); - } - if(inmenulock==1 and inmenuidx==5){ menuidx = 1; menulock = 0; menuUpdate(menuidx, menulock); diff --git a/M5Stack-SAM/M5Stack-SAM.ino b/M5Stack-SAM/M5Stack-SAM.ino index 834fd50..d2f0b91 100644 --- a/M5Stack-SAM/M5Stack-SAM.ino +++ b/M5Stack-SAM/M5Stack-SAM.ino @@ -1,17 +1,33 @@ #include #include "EEPROM.h" -#include "utility/DHT12.h" -#include // appBME280 -#include // appBME280 #include #include "SimpleBeacon.h" +/* + * To let the Menu not grow to fast, both "Weather" Apps, + * appDHT12 and appBME280 use the same Menu Index. + * If you like appDHT12, use this define + * #define WEATHER_SENSOR WS_DHT12 + * else if you like appBME280, use this define + * #define WEATHER_SENSOR WS_BME280 + */ +#define WEATHER_SENSOR WS_BME280 + +#if defined(WS_DHT12) + #include "utility/DHT12.h" + DHT12 dht12; + +#elif defined(WS_BME280) + #include + #include + + #define SEALEVELPRESSURE_HPA (1013.25) + Adafruit_BME280 bme280; + bool status; +#endif + SimpleBeacon ble; -DHT12 dht12; -#define SEALEVELPRESSURE_HPA (1013.25) // appBME280 -Adafruit_BME280 bme280; // appBME280 -bool status; // appBME280 #define TFT_GREY 0x5AEB #define TFT_BROWN 0x38E0 @@ -36,13 +52,10 @@ unsigned long tmp_tmr = 0; void setup(void) { Serial.begin(115200); - status = bme280.begin(0x76); -// if (!status) { -// Serial.println("Could not find a valid BME280 sensor, check wiring!"); -// while (1); -// } + #if defined(WS_BME280) + status = bme280.begin(0x76); + #endif - if (!EEPROM.begin(EEPROM_SIZE)) { Serial.println("failed to initialise EEPROM");