mirror of
https://github.com/richonguzman/LoRa_APRS_iGate.git
synced 2026-01-28 11:24:22 +01:00
BME680 module test
This commit is contained in:
parent
036942f4f4
commit
ff7bf00425
|
|
@ -24,6 +24,8 @@ lib_deps =
|
|||
adafruit/Adafruit Unified Sensor@^1.1.9
|
||||
adafruit/Adafruit BME280 Library@^2.2.2
|
||||
adafruit/Adafruit BMP280 Library@^2.6.8
|
||||
adafruit/Adafruit BME680 Library@^2.0.4
|
||||
|
||||
|
||||
[env:ttgo-lora32-v21]
|
||||
board = ttgo-lora32-v21
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
Configuration Config;
|
||||
WiFiClient espClient;
|
||||
|
||||
String versionDate = "2023.12.20";
|
||||
String versionDate = "2023.12.24";
|
||||
int myWiFiAPIndex = 0;
|
||||
int myWiFiAPSize = Config.wifiAPs.size();
|
||||
WiFi_AP *currentWiFi = &Config.wifiAPs[myWiFiAPIndex];
|
||||
|
|
|
|||
|
|
@ -13,130 +13,144 @@ extern String fifthLine;
|
|||
|
||||
namespace BME_Utils {
|
||||
|
||||
#ifndef BMPSensor
|
||||
Adafruit_BME280 bme;
|
||||
#else
|
||||
Adafruit_BMP280 bme;
|
||||
#endif
|
||||
|
||||
void setup() {
|
||||
if (Config.bme.active) {
|
||||
bool status;
|
||||
status = bme.begin(0x76); // Don't forget to join pins for righ direction on BME280!
|
||||
if (!status) {
|
||||
Serial.println("Could not find a valid BME280 or BMP280 sensor, check wiring!");
|
||||
show_display("ERROR", "", "BME/BMP sensor active", "but no sensor found...");
|
||||
while (1); // sacar esto para que quede pegado si no encuentra BME280
|
||||
} else {
|
||||
#ifndef BMPSensor
|
||||
Serial.println("init : BME280 Module ... done!");
|
||||
#else
|
||||
Serial.println("init : BMP280 Module ... done!");
|
||||
#endif
|
||||
}
|
||||
} else {
|
||||
#ifndef BMPSensor
|
||||
Serial.println("(BME not 'active' in 'igate_conf.json')");
|
||||
#else
|
||||
Serial.println("(BMP not 'active' in 'igate_conf.json')");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
String generateTempString(float bmeTemp) {
|
||||
String strTemp;
|
||||
strTemp = String((int)bmeTemp);
|
||||
switch (strTemp.length()) {
|
||||
case 1:
|
||||
return "00" + strTemp;
|
||||
break;
|
||||
case 2:
|
||||
return "0" + strTemp;
|
||||
break;
|
||||
case 3:
|
||||
return strTemp;
|
||||
break;
|
||||
default:
|
||||
return "-999";
|
||||
}
|
||||
}
|
||||
|
||||
String generateHumString(float bmeHum) {
|
||||
String strHum;
|
||||
strHum = String((int)bmeHum);
|
||||
switch (strHum.length()) {
|
||||
case 1:
|
||||
return "0" + strHum;
|
||||
break;
|
||||
case 2:
|
||||
return strHum;
|
||||
break;
|
||||
case 3:
|
||||
if ((int)bmeHum == 100) {
|
||||
return "00";
|
||||
} else {
|
||||
return "-99";
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return "-99";
|
||||
}
|
||||
}
|
||||
|
||||
String generatePresString(float bmePress) {
|
||||
String strPress;
|
||||
strPress = String((int)bmePress);
|
||||
switch (strPress.length()) {
|
||||
case 1:
|
||||
return "000" + strPress + "0";
|
||||
break;
|
||||
case 2:
|
||||
return "00" + strPress + "0";
|
||||
break;
|
||||
case 3:
|
||||
return "0" + strPress + "0";
|
||||
break;
|
||||
case 4:
|
||||
return strPress + "0";
|
||||
break;
|
||||
case 5:
|
||||
return strPress;
|
||||
break;
|
||||
default:
|
||||
return "-99999";
|
||||
}
|
||||
}
|
||||
|
||||
String readDataSensor() {
|
||||
String wx, tempStr, humStr, presStr;
|
||||
float newTemp = bme.readTemperature();
|
||||
float newHum;
|
||||
#ifndef BMPSensor
|
||||
newHum = bme.readHumidity();
|
||||
#else
|
||||
newHum = 0;
|
||||
#ifdef BME280Sensor
|
||||
Adafruit_BME280 bme;
|
||||
#endif
|
||||
float newPress = (bme.readPressure() / 100.0F);
|
||||
|
||||
//bme.readAltitude(SEALEVELPRESSURE_HPA) // this is for approximate Altitude Calculation.
|
||||
|
||||
if (isnan(newTemp) || isnan(newHum) || isnan(newPress)) {
|
||||
Serial.println("BME280 Module data failed");
|
||||
wx = ".../...g...t...r...p...P...h..b.....";
|
||||
fifthLine = "";
|
||||
return wx;
|
||||
} else {
|
||||
tempStr = generateTempString((newTemp * 1.8) + 32);
|
||||
#ifndef BMPSensor
|
||||
humStr = generateHumString(newHum);
|
||||
#else
|
||||
humStr = "..";
|
||||
#endif
|
||||
presStr = generatePresString(newPress + (HEIGHT_CORRECTION/CORRECTION_FACTOR));
|
||||
fifthLine = "BME-> " + String(int(newTemp))+"C " + humStr + "% " + presStr.substring(0,4) + "hPa";
|
||||
wx = ".../...g...t" + tempStr + "r...p...P...h" + humStr + "b" + presStr;
|
||||
return wx;
|
||||
#ifdef BMP280Sensor
|
||||
Adafruit_BMP280 bme;
|
||||
#endif
|
||||
#ifdef BME680Sensor
|
||||
Adafruit_BME680 bme;
|
||||
#endif
|
||||
|
||||
void setup() {
|
||||
if (Config.bme.active) {
|
||||
bool status;
|
||||
status = bme.begin(0x76); // Don't forget to join pins for righ direction on BME280!
|
||||
if (!status) {
|
||||
Serial.println("Could not find a valid BME280 or BMP280 sensor, check wiring!");
|
||||
show_display("ERROR", "", "BME/BMP sensor active", "but no sensor found...");
|
||||
while (1); // sacar esto para que quede pegado si no encuentra BME280
|
||||
} else {
|
||||
#ifdef BME280Sensor
|
||||
Serial.println("init : BME280 Module ... done!");
|
||||
#endif
|
||||
#ifdef BMP280Sensor
|
||||
Serial.println("init : BMP280 Module ... done!");
|
||||
#endif
|
||||
#ifdef BME680Sensor
|
||||
Serial.println("init : BME680 Module ... done!");
|
||||
#endif
|
||||
}
|
||||
} else {
|
||||
Serial.println("(BME/BMP sensor not 'active' in 'igate_conf.json')");
|
||||
}
|
||||
}
|
||||
|
||||
String generateTempString(float bmeTemp) {
|
||||
String strTemp;
|
||||
strTemp = String((int)bmeTemp);
|
||||
switch (strTemp.length()) {
|
||||
case 1:
|
||||
return "00" + strTemp;
|
||||
break;
|
||||
case 2:
|
||||
return "0" + strTemp;
|
||||
break;
|
||||
case 3:
|
||||
return strTemp;
|
||||
break;
|
||||
default:
|
||||
return "-999";
|
||||
}
|
||||
}
|
||||
|
||||
String generateHumString(float bmeHum) {
|
||||
String strHum;
|
||||
strHum = String((int)bmeHum);
|
||||
switch (strHum.length()) {
|
||||
case 1:
|
||||
return "0" + strHum;
|
||||
break;
|
||||
case 2:
|
||||
return strHum;
|
||||
break;
|
||||
case 3:
|
||||
if ((int)bmeHum == 100) {
|
||||
return "00";
|
||||
} else {
|
||||
return "-99";
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return "-99";
|
||||
}
|
||||
}
|
||||
|
||||
String generatePresString(float bmePress) {
|
||||
String strPress;
|
||||
strPress = String((int)bmePress);
|
||||
switch (strPress.length()) {
|
||||
case 1:
|
||||
return "000" + strPress + "0";
|
||||
break;
|
||||
case 2:
|
||||
return "00" + strPress + "0";
|
||||
break;
|
||||
case 3:
|
||||
return "0" + strPress + "0";
|
||||
break;
|
||||
case 4:
|
||||
return strPress + "0";
|
||||
break;
|
||||
case 5:
|
||||
return strPress;
|
||||
break;
|
||||
default:
|
||||
return "-99999";
|
||||
}
|
||||
}
|
||||
|
||||
String readDataSensor() {
|
||||
String wx, tempStr, humStr, presStr;
|
||||
float newHum;
|
||||
|
||||
float newTemp = bme.readTemperature();
|
||||
#if defined(BME280Sensor) || defined(BME680Sensor)
|
||||
newHum = bme.readHumidity();
|
||||
#endif
|
||||
#ifdef BMP280Sensor
|
||||
newHum = 0;
|
||||
#endif
|
||||
float newPress = (bme.readPressure() / 100.0F);
|
||||
|
||||
#ifdef BME680Sensor
|
||||
float newGas = bme.gas_resistance / 1000.0; // in Kilo ohms
|
||||
#endif
|
||||
|
||||
//bme.readAltitude(SEALEVELPRESSURE_HPA) // this is for approximate Altitude Calculation.
|
||||
|
||||
if (isnan(newTemp) || isnan(newHum) || isnan(newPress)) {
|
||||
Serial.println("BME/BMP Module data failed");
|
||||
wx = ".../...g...t...r...p...P...h..b.....";
|
||||
fifthLine = "";
|
||||
return wx;
|
||||
} else {
|
||||
tempStr = generateTempString((newTemp * 1.8) + 32);
|
||||
#if defined(BME280Sensor) || defined(BME680Sensor)
|
||||
humStr = generateHumString(newHum,type);
|
||||
#endif
|
||||
#ifdef BMP280Sensor
|
||||
humStr = "..";
|
||||
#endif
|
||||
presStr = generatePresString(newPress + (HEIGHT_CORRECTION/CORRECTION_FACTOR));
|
||||
fifthLine = "BME-> " + String(int(newTemp))+"C " + humStr + "% " + presStr.substring(0,4) + "hPa";
|
||||
wx = ".../...g...t" + tempStr + "r...p...P...h" + humStr + "b" + presStr;
|
||||
#ifdef BME680Sensor
|
||||
wx += "Gas: " + String(newGas) + "Kohms";
|
||||
#endif
|
||||
return wx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -4,21 +4,28 @@
|
|||
#include <Arduino.h>
|
||||
#include <Adafruit_Sensor.h>
|
||||
|
||||
//#define BMPSensor // uncoment this line if BMP280 Module is connected instead of BME280
|
||||
#define BME280Sensor // its set by default but you should comment it with "//"
|
||||
//#define BMP280Sensor // and delete "//" from the one you want to use.
|
||||
//#define BME680Sensor
|
||||
|
||||
#ifndef BMPSensor
|
||||
#ifdef BME280Sensor
|
||||
#include <Adafruit_BME280.h>
|
||||
#else
|
||||
#endif
|
||||
#ifdef BMP280Sensor
|
||||
#include <Adafruit_BMP280.h>
|
||||
#endif
|
||||
#ifdef BME680Sensor
|
||||
#include <Adafruit_BME680.h>
|
||||
#endif
|
||||
|
||||
namespace BME_Utils {
|
||||
|
||||
void setup();
|
||||
String generateTempString(float bmeTemp);
|
||||
String generateHumString(float bmeHum);
|
||||
String generatePresString(float bmePress);
|
||||
String readDataSensor();
|
||||
|
||||
String generateTempString(float bmeTemp);
|
||||
String generateHumString(float bmeHum);
|
||||
String generatePresString(float bmePress);
|
||||
String readDataSensor();
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue