updated Bat Reading and BME680 Test

This commit is contained in:
richonguzman 2023-12-24 10:03:00 -03:00
parent c79304b576
commit 444f307f49
4 changed files with 50 additions and 19 deletions

View File

@ -34,6 +34,7 @@ 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
h2zero/NimBLE-Arduino@^1.4.1
check_tool = cppcheck

View File

@ -14,11 +14,15 @@ extern logging::Logger logger;
namespace BME_Utils {
#ifndef BMPSensor
#ifdef BME280Sensor
Adafruit_BME280 bme;
#else
#endif
#ifdef BMP280Sensor
Adafruit_BMP280 bme;
#endif
#ifdef BME680Sensor
Adafruit_BME680 bme;
#endif
void setup() {
if (Config.bme.active) {
@ -29,18 +33,26 @@ namespace BME_Utils {
logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "BME", " BME280 Active in config but not found! Check Wiring");
while (1);
} else {
#ifndef BMPSensor
#ifdef BME280Sensor
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "BME", " BME280 Module init done!");
#else
#endif
#ifdef BMP280Sensor
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "BMP", " BMP280 Module init done!");
#endif
#ifdef BME680Sensor
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "BME", " BMP680 Module init done!");
#endif
}
} else {
#ifndef BMPSensor
#ifdef BME280Sensor
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "BME", " BME280 Module not active in 'tracker_conf.json'");
#else
#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
}
}
@ -146,14 +158,20 @@ namespace BME_Utils {
String readDataSensor(String type) {
String wx, tempStr, humStr, presStr;
float newTemp = bme.readTemperature();
float newHum;
#ifndef BMPSensor
float newTemp = bme.readTemperature();
#if defined(BME280Sensor) || defined(BME680Sensor)
newHum = bme.readHumidity();
#else
#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
if (isnan(newTemp) || isnan(newHum) || isnan(newPress)) {
Serial.println("BME280 Module data failed");
@ -165,20 +183,25 @@ namespace BME_Utils {
return wx;
} else {
tempStr = generateTempString(newTemp, type);
#ifndef BMPSensor
#if defined(BME280Sensor) || defined(BME680Sensor)
humStr = generateHumString(newHum,type);
#else
#endif
#ifdef BMP280Sensor
humStr = "..";
#endif
presStr = generatePresString(newPress + (Config.bme.heightCorrection/CORRECTION_FACTOR), type);
if (type == "OLED") {
#ifndef BMPSensor
#if defined(BME280Sensor) || defined(BME680Sensor)
wx = tempStr + "C " + humStr + "% " + presStr + "hPa";
#else
#endif
#ifdef BMP280Sensor
wx = "T: " + tempStr + "C " + "P: " + presStr + "hPa";
#endif
} else {
wx = ".../...g...t" + tempStr + "r...p...P...h" + humStr + "b" + presStr;
#ifdef BME680Sensor
wx += "Gas: " + String(newGas) + " k ohms";
#endif
}
return wx;
}

View File

@ -4,13 +4,19 @@
#include <Adafruit_Sensor.h>
#include <Arduino.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 {

View File

@ -9,6 +9,8 @@ extern Configuration Config;
extern logging::Logger logger;
extern bool disableGPS;
int lora32BatReadingCorr = 6; // % of correction to higher value to reflect the real battery voltage (adjust this to your needs)
// cppcheck-suppress unusedFunction
bool PowerManagement::begin(TwoWire &port) {
#if defined(TTGO_T_Beam_V0_7) || defined(ESP32_DIY_LoRa_GPS) || defined(TTGO_T_LORA_V2_1_GPS) || defined(TTGO_T_LORA_V2_1_TNC) || defined(ESP32_DIY_1W_LoRa_GPS)
@ -139,11 +141,10 @@ double PowerManagement::getBatteryVoltage() {
// the measured voltage is inaccurate du to known nonlinearity and ~100mV offset of the ESP32 A/D converter
int adc_value;
double voltage;
// analogSetAttenuation(ADC_11db); // this is the default setting (range 0-3.3V)
adc_value = analogRead(35); // ADC1_CHANNEL_7
adc_value = analogRead(35);
voltage = (adc_value * 3.3 ) / 4095;
voltage += 0.1; // add 0.1V offset
voltage = 2 * voltage; // multiply result by two because the voltage was measured after the 1:2 divider
voltage = 2 * voltage * (1 + lora32BatReadingCorr/100) ; // multiply result by two because the voltage was measured after the 1:2 divider
return voltage;
#endif
#if defined(TTGO_T_Beam_V1_0) || defined(TTGO_T_Beam_V1_0_SX1268)