Skip to content

Commit 00754ff

Browse files
committed
Adding appBME280 to M5Stack-SAM, APPS and GFX_MENU, to read from a Grove - Barometer Sensor.
1 parent c963547 commit 00754ff

3 files changed

Lines changed: 53 additions & 2 deletions

File tree

M5Stack-SAM/APPS.ino

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ void appBLEBaecon(){
3333
menuUpdate(menuidx, menulock);
3434
}
3535

36-
3736
void appDHT12(){
3837
menuDrawMenu(F("DHT12"),F(""),F("ESC"),F(""),sys_menucolor,sys_windowcolor,sys_menutextcolor);
3938
M5.Lcd.drawString(F("TEMPERATURE"),30,80,2);
@@ -60,6 +59,37 @@ void appDHT12(){
6059
menuUpdate(menuidx, menulock);
6160
}
6261

62+
63+
void appBME280(){
64+
menuDrawMenu(F("BME280"),F(""),F("ESC"),F(""),sys_menucolor,sys_windowcolor,sys_menutextcolor);
65+
M5.Lcd.drawString(F("TEMPERATURE"),30,60,2);
66+
M5.Lcd.drawString(F("°C"),250,60,2);
67+
M5.Lcd.drawString(F("HUMIDITY"),30,120,2);
68+
M5.Lcd.drawString(F("%RH"),250,120,2);
69+
M5.Lcd.drawString(F("PRESSURE"),30,180,2);
70+
M5.Lcd.drawString(F("hPa"),250,180,2);
71+
menuidx = 1;
72+
menulock = 0;
73+
M5.Lcd.setTextColor(sys_menutextcolor, sys_windowcolor);
74+
while(M5.BtnB.wasPressed()){
75+
M5.update();
76+
}
77+
while(!M5.BtnB.wasPressed()){
78+
M5.update();
79+
if(millis()-tmp_tmr > 1000){
80+
tmp_tmr = millis();
81+
float tmp_temp = bme280.readTemperature();
82+
float tmp_humi = bme280.readHumidity();
83+
float tmp_pres = (bme280.readPressure()/100.0F);
84+
//menuWindowClr(sys_windowcolor);
85+
M5.Lcd.drawFloat(tmp_temp, 1, 140, 40, 6);
86+
M5.Lcd.drawFloat(tmp_humi, 1, 140, 100, 6);
87+
M5.Lcd.drawFloat(tmp_pres, 1, 140, 160, 6);
88+
}
89+
}
90+
menuUpdate(menuidx, menulock);
91+
}
92+
6393
void appStopky(){
6494
boolean tmp_run = false;
6595
float tmp_sec = 0;

M5Stack-SAM/GFX_MENU.ino

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ void menuSystemLevel(byte inmenuidx){
112112

113113
void menuAplikaceLevel(byte inmenuidx){
114114
menuidxmin = 0;
115-
menuidxmax = 4;
115+
menuidxmax = 5;
116116
switch (inmenuidx) {
117117
case 0:
118118
menuIsMenu = LOW;
@@ -135,6 +135,11 @@ void menuAplikaceLevel(byte inmenuidx){
135135
windowPrintInfoText(F("BLE Beacon SIMULATOR"),sys_menutextcolor);
136136
break;
137137
case 4:
138+
menuIsMenu = LOW;
139+
menuWindowClr(sys_windowcolor);
140+
windowPrintInfoText(F("BME280"),sys_menutextcolor);
141+
break;
142+
case 5:
138143
menuIsMenu = LOW;
139144
menuWindowClr(sys_windowcolor);
140145
windowPrintInfoText(F("RETURN"),sys_menutextcolor);
@@ -178,6 +183,9 @@ void menuRunApp(byte inmenuidx, byte inmenulock){
178183
appBLEBaecon();
179184
}
180185
if(inmenulock==1 and inmenuidx==4){
186+
appBME280();
187+
}
188+
if(inmenulock==1 and inmenuidx==5){
181189
menuidx = 1;
182190
menulock = 0;
183191
menuUpdate(menuidx, menulock);

M5Stack-SAM/M5Stack-SAM.ino

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
#include <M5Stack.h>
22
#include "EEPROM.h"
33
#include "utility/DHT12.h"
4+
#include <Adafruit_Sensor.h> // appBME280
5+
#include <Adafruit_BME280.h> // appBME280
46
#include <Wire.h>
57
#include "SimpleBeacon.h"
68

79
SimpleBeacon ble;
810
DHT12 dht12;
911

12+
#define SEALEVELPRESSURE_HPA (1013.25) // appBME280
13+
Adafruit_BME280 bme280; // appBME280
14+
bool status; // appBME280
15+
1016
#define TFT_GREY 0x5AEB
1117
#define TFT_BROWN 0x38E0
1218

@@ -29,6 +35,13 @@ unsigned long tmp_tmr = 0;
2935

3036
void setup(void) {
3137
Serial.begin(115200);
38+
39+
status = bme280.begin(0x76);
40+
// if (!status) {
41+
// Serial.println("Could not find a valid BME280 sensor, check wiring!");
42+
// while (1);
43+
// }
44+
3245

3346
if (!EEPROM.begin(EEPROM_SIZE))
3447
{

0 commit comments

Comments
 (0)