adding new bme

This commit is contained in:
richonguzman 2024-05-13 12:13:36 -04:00
parent c23c22f393
commit cc1a163f06
6 changed files with 150 additions and 111 deletions

View File

@ -5,7 +5,6 @@
#include <logger.h>
#define SEALEVELPRESSURE_HPA (1013.25)
#define HEIGHT_CORRECTION 0 // in meters
#define CORRECTION_FACTOR (8.2296) // for meters
extern Configuration Config;
@ -13,69 +12,116 @@ extern logging::Logger logger;
float newHum, newTemp, newPress, newGas;
bool bmeSensorFound = false;
uint32_t bmeLastReading = -60000;
int wxModuleType = 0;
uint8_t wxModuleAddress = 0x00;
namespace BME_Utils {
#ifdef BME280Sensor
Adafruit_BME280 bme;
#endif
#ifdef BMP280Sensor
Adafruit_BMP280 bme;
#endif
#ifdef BME680Sensor
Adafruit_BME680 bme;
#endif
Adafruit_BME280 bme280;
Adafruit_BME680 bme680;
#ifdef HELTEC_V3_GPS
Adafruit_BMP280 bmp280(&Wire1);
#else
Adafruit_BMP280 bmp280;
#endif
namespace BME_Utils {
void getWxModuleAddres() {
uint8_t err, addr;
for(addr = 1; addr < 0x7F; addr++) {
#ifdef HELTEC_V3_GPS
Wire1.beginTransmission(addr);
err = Wire1.endTransmission();
#else
Wire.beginTransmission(addr);
err = Wire.endTransmission();
#endif
if (err == 0) {
if (addr == 0x76 || addr == 0x77) {
wxModuleAddress = addr;
//
Serial.println("Sensor encontrado : " + String(wxModuleAddress,DEC));
//
return;
}
}
}
}
void setup() {
if (Config.bme.active) {
bool status;
#ifdef HELTEC_V3_GPS
status = bme.begin(0x76, &Wire1);
#else
status = bme.begin(0x76);
#endif
if (!status) {
show_display("ERROR", "", "BME/BMP sensor active", "but no sensor found...", "", 2000);
logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "BME", " BME/BMP sensor Active in config but not found! Check Wiring");
} else {
#ifdef BME280Sensor
bme.setSampling(Adafruit_BME280::MODE_FORCED,
Adafruit_BME280::SAMPLING_X1,
Adafruit_BME280::SAMPLING_X1,
Adafruit_BME280::SAMPLING_X1,
Adafruit_BME280::FILTER_OFF
);
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "BME", " BME280 Module init done!");
getWxModuleAddres();
if (wxModuleAddress != 0x00) {
bool wxModuleFound = false;
#ifdef HELTEC_V3_GPS
if (bme280.begin(wxModuleAddress, &Wire1)) {
logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "BME", " BME280 sensor found");
wxModuleType = 1;
wxModuleFound = true;
}
if (!wxModuleFound) {
if (bme680.begin(wxModuleAddress, &Wire1)) {
logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "BME", " BME680 sensor found");
wxModuleType = 3;
wxModuleFound = true;
}
}
#else
if (bme280.begin(wxModuleAddress)) {
logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "BME", " BME280 sensor found");
wxModuleType = 1;
wxModuleFound = true;
}
if (!wxModuleFound) {
if (bme680.begin(wxModuleAddress)) {
logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "BME", " BME680 sensor found");
wxModuleType = 3;
wxModuleFound = true;
}
}
#endif
#ifdef BMP280Sensor
bme.setSampling(Adafruit_BMP280::MODE_FORCED,
Adafruit_BMP280::SAMPLING_X1,
Adafruit_BMP280::SAMPLING_X1,
Adafruit_BMP280::FILTER_OFF
);
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "BMP", " BMP280 Module init done!");
#endif
#ifdef BME680Sensor
bme.setTemperatureOversampling(BME680_OS_1X);
bme.setHumidityOversampling(BME680_OS_1X);
bme.setPressureOversampling(BME680_OS_1X);
bme.setIIRFilterSize(BME680_FILTER_SIZE_0);
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "BME", " BMP680 Module init done!");
#endif
bmeSensorFound = true;
}
} else {
#ifdef BME280Sensor
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "BME", " BME280 Module not active in 'tracker_conf.json'");
#endif
#ifdef BMP280Sensor
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "BMP", " BMP280 Module not active in 'tracker_conf.json'");
#endif
#ifdef BME680Sensor
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "BMP", " BMP680 Module not active in 'tracker_conf.json'");
#endif
if (!wxModuleFound) {
if (bmp280.begin(wxModuleAddress)) {
logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "BME", " BMP280 sensor found");
wxModuleType = 2;
wxModuleFound = true;
}
}
if (!wxModuleFound) {
show_display("ERROR", "", "BME/BMP sensor active", "but no sensor found...", "", 2000);
logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "BME", " BME/BMP sensor Active in config but not found! Check Wiring");
} else {
switch (wxModuleType) {
case 1:
bme280.setSampling(Adafruit_BME280::MODE_FORCED,
Adafruit_BME280::SAMPLING_X1,
Adafruit_BME280::SAMPLING_X1,
Adafruit_BME280::SAMPLING_X1,
Adafruit_BME280::FILTER_OFF
);
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "BME", " BME280 Module init done!");
break;
case 2:
bmp280.setSampling(Adafruit_BMP280::MODE_FORCED,
Adafruit_BMP280::SAMPLING_X1,
Adafruit_BMP280::SAMPLING_X1,
Adafruit_BMP280::FILTER_OFF
);
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "BMP", " BMP280 Module init done!");
break;
case 3:
bme680.setTemperatureOversampling(BME680_OS_1X);
bme680.setHumidityOversampling(BME680_OS_1X);
bme680.setPressureOversampling(BME680_OS_1X);
bme680.setIIRFilterSize(BME680_FILTER_SIZE_0);
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "BME", " BMP680 Module init done!");
break;
}
}
}
}
}
@ -181,31 +227,32 @@ namespace BME_Utils {
String readDataSensor(String type) {
String wx, tempStr, humStr, presStr;
uint32_t lastReading = millis() - bmeLastReading;
if (lastReading > 60 * 1000) {
#if defined(BME280Sensor) || defined(BMP280Sensor)
bme.takeForcedMeasurement();
newTemp = bme.readTemperature();
newPress = (bme.readPressure() / 100.0F);
#ifdef BME280Sensor
newHum = bme.readHumidity();
#endif
#ifdef BMP280Sensor
newHum = 0;
#endif
#endif
#ifdef BME680Sensor
bme.performReading();
delay(50);
if (bme.endReading()) {
newTemp = bme.temperature;
newPress = (bme.pressure / 100.0F);
newHum = bme.humidity;
newGas = bme.gas_resistance / 1000.0; // in Kilo ohms
}
#endif
switch (wxModuleType) {
case 1: // BME280
bme280.takeForcedMeasurement();
newTemp = bme280.readTemperature();
newPress = (bme280.readPressure() / 100.0F);
newHum = bme280.readHumidity();
break;
case 2: // BMP280
bmp280.takeForcedMeasurement();
newTemp = bmp280.readTemperature();
newPress = (bmp280.readPressure() / 100.0F);
newHum = 0;
break;
case 3: // BME680
bme680.performReading();
delay(50);
if (bme680.endReading()) {
newTemp = bme680.temperature;
newPress = (bme680.pressure / 100.0F);
newHum = bme680.humidity;
newGas = bme680.gas_resistance / 1000.0; // in Kilo ohms
}
break;
}
bmeLastReading = millis();
}
@ -218,26 +265,24 @@ namespace BME_Utils {
}
return wx;
} else {
tempStr = generateTempString(newTemp, type);
#if defined(BME280Sensor) || defined(BME680Sensor)
tempStr = generateTempString(newTemp + Config.bme.temperatureCorrection, type);
if (wxModuleType == 1 || wxModuleType == 3) {
humStr = generateHumString(newHum,type);
#endif
#ifdef BMP280Sensor
} else if (wxModuleType == 2) {
humStr = "..";
#endif
}
presStr = generatePresString(newPress + (Config.bme.heightCorrection/CORRECTION_FACTOR), type);
if (type == "OLED") {
#if defined(BME280Sensor) || defined(BME680Sensor)
if (wxModuleType == 1 || wxModuleType == 3) {
wx = tempStr + "C " + humStr + "% " + presStr + "hPa";
#endif
#ifdef BMP280Sensor
} else if (wxModuleType == 2) {
wx = "T: " + tempStr + "C " + "P: " + presStr + "hPa";
#endif
}
} else {
wx = ".../...g...t" + tempStr + "r...p...P...h" + humStr + "b" + presStr;
#ifdef BME680Sensor
if (wxModuleType == 3) {
wx += "Gas: " + String(newGas) + "Kohms";
#endif
}
}
return wx;
}

View File

@ -2,24 +2,15 @@
#define BME_UTILS_H_
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <Adafruit_BMP280.h>
#include <Adafruit_BME680.h>
#include <Arduino.h>
#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
#ifdef BME280Sensor
#include <Adafruit_BME280.h>
#endif
#ifdef BMP280Sensor
#include <Adafruit_BMP280.h>
#endif
#ifdef BME680Sensor
#include <Adafruit_BME680.h>
#endif
namespace BME_Utils {
void getWxModuleAddres();
void setup();
String generateTempString(float bmeTemp, String type);
String generateHumString(float bmeHum, String type);

View File

@ -54,8 +54,9 @@ void Configuration::readFile(fs::FS &fs, const char *fileName) {
winlink.password = data["winlink"]["password"].as<String>();
bme.active = data["bme"]["active"].as<bool>();
bme.sendTelemetry = data["bme"]["sendTelemetry"].as<bool>();
bme.heightCorrection = data["bme"]["heightCorrection"].as<int>();
bme.temperatureCorrection = data["bme"]["temperatureCorrection"].as<float>();
bme.sendTelemetry = data["bme"]["sendTelemetry"].as<bool>();
notification.ledTx = data["notification"]["ledTx"].as<bool>();
notification.ledTxPin = data["notification"]["ledTxPin"].as<int>();

View File

@ -39,8 +39,9 @@ public:
class BME {
public:
bool active;
bool sendTelemetry;
int heightCorrection;
float temperatureCorrection;
bool sendTelemetry;
};
class Notification {

View File

@ -42,7 +42,8 @@ extern String winlinkBody;
extern String winlinkAlias;
extern String winlinkAliasComplete;
extern bool winlinkCommentState;
extern bool bmeSensorFound;
extern int wxModuleType;
//extern bool bmeSensorFound;
String freqChangeWarning;
uint8_t lowBatteryPercent = 21;
@ -572,7 +573,7 @@ namespace MENU_Utils {
if (time_now % 10 < 5) {
fourthRowMainMenu = "A=" + fourthRowAlt + "m " + fourthRowSpeed + "km/h " + fourthRowCourse;
} else {
if (bmeSensorFound) {
if (wxModuleType != 0) {//bmeSensorFound) {
fourthRowMainMenu = BME_Utils::readDataSensor("OLED");
} else {
fourthRowMainMenu = "A=" + fourthRowAlt + "m " + fourthRowSpeed + "km/h " + fourthRowCourse;

View File

@ -38,7 +38,7 @@ extern bool smartBeaconValue;
extern uint8_t winlinkStatus;
extern bool winlinkCommentState;
extern bool bmeSensorFound;
extern int wxModuleType;// bmeSensorFound;
bool sendStandingUpdate = false;
uint8_t updateCounter = Config.sendCommentAfterXBeacons;
@ -404,7 +404,7 @@ namespace STATION_Utils {
} else {
packet = APRSPacketLib::generateGPSBeaconPacket(currentBeacon->callsign, "APLRT1", Config.path, "/", APRSPacketLib::encodeGPS(gps.location.lat(),gps.location.lng(), gps.course.deg(), gps.speed.knots(), currentBeacon->symbol, Config.sendAltitude, gps.altitude.feet(), sendStandingUpdate, "Wx"));
}
if (bmeSensorFound) {
if (wxModuleType != 0) {//bmeSensorFound) {
packet += BME_Utils::readDataSensor("APRS");
} else {
packet += ".../...g...t...r...p...P...h..b.....";