From b59153d8df7b297664551e2af8bc4f427858e556 Mon Sep 17 00:00:00 2001 From: richonguzman Date: Sat, 17 May 2025 11:43:54 -0400 Subject: [PATCH] wx sensor added --- src/battery_utils.cpp | 11 +-- src/utils.cpp | 2 +- src/wx_utils.cpp | 67 +++++++++++++------ .../platformio.ini | 3 +- 4 files changed, 56 insertions(+), 27 deletions(-) diff --git a/src/battery_utils.cpp b/src/battery_utils.cpp index 25472ae..fe439e9 100644 --- a/src/battery_utils.cpp +++ b/src/battery_utils.cpp @@ -157,7 +157,12 @@ namespace BATTERY_Utils { return (2 * (sampleSum/100) * adcReadingTransformation) + voltageDividerCorrection; // raw voltage without mapping } #else - return (2 * (sampleSum/100) * adcReadingTransformation) + voltageDividerCorrection; // raw voltage without mapping + #ifdef LIGHTGATEWAY_PLUS_1_0 + double inputDivider = (1.0 / (560.0 + 100.0)) * 100.0; // The voltage divider is a 560k + 100k resistor in series, 100k on the low side. + return (((sampleSum/100) * adcReadingTransformation) / inputDivider) + 0.41; + #else + return (2 * (sampleSum/100) * adcReadingTransformation) + voltageDividerCorrection; // raw voltage without mapping + #endif #endif #endif // return mapVoltage(voltage, 3.34, 4.71, 3.0, 4.2); // mapped voltage @@ -246,9 +251,7 @@ namespace BATTERY_Utils { String telemetry = "|"; telemetry += generateEncodedTelemetryBytes(telemetryCounter, true, 0); telemetryCounter++; - if (telemetryCounter == 1000) { - telemetryCounter = 0; - } + if (telemetryCounter == 1000) telemetryCounter = 0; if (Config.battery.sendInternalVoltage) telemetry += generateEncodedTelemetryBytes(checkInternalVoltage(), false, 0); if (Config.battery.sendExternalVoltage) telemetry += generateEncodedTelemetryBytes(checkExternalVoltage(), false, 1); telemetry += "|"; diff --git a/src/utils.cpp b/src/utils.cpp index ef249d9..c387cad 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -229,7 +229,7 @@ namespace Utils { #endif if (Config.wxsensor.active) { - const char* sensorData = (wxModuleType == 0) ? ".../...g...t..." : WX_Utils::readDataSensor().c_str(); + String sensorData = (wxModuleType == 0) ? ".../...g...t..." : WX_Utils::readDataSensor(); beaconPacket += sensorData; secondaryBeaconPacket += sensorData; } diff --git a/src/wx_utils.cpp b/src/wx_utils.cpp index 55ee081..3342a56 100644 --- a/src/wx_utils.cpp +++ b/src/wx_utils.cpp @@ -1,4 +1,7 @@ #include +#ifdef LIGHTGATEWAY_PLUS_1_0 +#include "Adafruit_SHTC3.h" +#endif #include "configuration.h" #include "board_pinout.h" #include "wx_utils.h" @@ -23,11 +26,14 @@ float newHum, newTemp, newPress, newGas; Adafruit_BME280 bme280; #if defined(HELTEC_V3) || defined(HELTEC_V3_2) Adafruit_BMP280 bmp280(&Wire1); -Adafruit_Si7021 sensor = Adafruit_Si7021(); +Adafruit_Si7021 sensor = Adafruit_Si7021(); #else Adafruit_BMP280 bmp280; Adafruit_BME680 bme680; -Adafruit_Si7021 sensor = Adafruit_Si7021(); +Adafruit_Si7021 sensor = Adafruit_Si7021(); +#endif +#ifdef LIGHTGATEWAY_PLUS_1_0 +Adafruit_SHTC3 shtc3 = Adafruit_SHTC3(); #endif @@ -41,16 +47,23 @@ namespace WX_Utils { err = Wire1.endTransmission(); #else Wire.beginTransmission(addr); + #ifdef LIGHTGATEWAY_PLUS_1_0 + Wire.write(0x35); + Wire.write(0x17); + #endif err = Wire.endTransmission(); #endif if (err == 0) { - //Serial.println(addr); this shows any connected board to I2C - if (addr == 0x76 || addr == 0x77) { // BME/BMP + //Serial.println(addr); //this shows any connected board to I2C + if (addr == 0x76 || addr == 0x77) { // BME or BMP wxModuleAddress = addr; return; } else if (addr == 0x40) { // Si7011 wxModuleAddress = addr; return; + } else if (addr == 0x70) { // SHTC3 + wxModuleAddress = addr; + return; } } } @@ -58,47 +71,53 @@ namespace WX_Utils { void setup() { if (Config.wxsensor.active) { - getWxModuleAddres(); + getWxModuleAddres(); if (wxModuleAddress != 0x00) { bool wxModuleFound = false; if (wxModuleAddress == 0x76 || wxModuleAddress == 0x77) { #if defined(HELTEC_V3) || defined(HELTEC_V3_2) || defined(HELTEC_WSL_V3) || defined(HELTEC_WSL_V3_DISPLAY) if (bme280.begin(wxModuleAddress, &Wire1)) { Serial.println("BME280 sensor found"); - wxModuleType = 1; - wxModuleFound = true; + wxModuleType = 1; + wxModuleFound = true; } #else if (bme280.begin(wxModuleAddress)) { Serial.println("BME280 sensor found"); - wxModuleType = 1; - wxModuleFound = true; + wxModuleType = 1; + wxModuleFound = true; } if (!wxModuleFound) { if (bme680.begin(wxModuleAddress)) { Serial.println("BME680 sensor found"); - wxModuleType = 3; - wxModuleFound = true; + wxModuleType = 3; + wxModuleFound = true; } } #endif if (!wxModuleFound) { if (bmp280.begin(wxModuleAddress)) { Serial.println("BMP280 sensor found"); - wxModuleType = 2; - wxModuleFound = true; + wxModuleType = 2; + wxModuleFound = true; } } } else if (wxModuleAddress == 0x40) { if(sensor.begin()) { Serial.println("Si7021 sensor found"); - wxModuleType = 4; - wxModuleFound = true; + wxModuleType = 4; + wxModuleFound = true; } - } + } else if (wxModuleAddress == 0x70) { + if (shtc3.begin()) { + Serial.println("SHTC3 sensor found"); + wxModuleType = 5; + wxModuleFound = true; + } + } if (!wxModuleFound) { - displayShow("ERROR", "", "BME/BMP/Si7021 sensor active", "but no sensor found...", 2000); - Serial.println("BME/BMP/Si7021 sensor Active in config but not found! Check Wiring"); + displayShow("ERROR", "", "BME/BMP/Si7021/SHTC3 sensor active", "but no sensor found...", 2000); + Serial.println("BME/BMP/Si7021/SHTC3 sensor Active in config but not found! Check Wiring"); } else { switch (wxModuleType) { case 1: @@ -212,9 +231,15 @@ namespace WX_Utils { break; case 4: // Si7021 newTemp = sensor.readTemperature(); - newPress = 0; newHum = sensor.readHumidity(); + newPress = 0; break; + case 5: // SHTC3 + sensors_event_t humidity, temp; + shtc3.getEvent(&humidity, &temp); + newTemp = temp.temperature; + newHum = humidity.relative_humidity; + newPress = 0; } if (isnan(newTemp) || isnan(newHum) || isnan(newPress)) { @@ -225,13 +250,13 @@ namespace WX_Utils { String tempStr = generateTempString(((newTemp + Config.wxsensor.temperatureCorrection) * 1.8) + 32); String humStr; - if (wxModuleType == 1 || wxModuleType == 3 || wxModuleType == 4) { + if (wxModuleType == 1 || wxModuleType == 3 || wxModuleType == 4 || wxModuleType == 5) { humStr = generateHumString(newHum); } else if (wxModuleType == 2) { humStr = ".."; } - String presStr = (wxModuleAddress == 4) + String presStr = (wxModuleType == 4 || wxModuleType == 5) ? "....." #ifdef HAS_GPS : generatePresString(newPress + (gps.altitude.meters() / CORRECTION_FACTOR)); diff --git a/variants/QRPLabs_LightGateway_Plus_1_0/platformio.ini b/variants/QRPLabs_LightGateway_Plus_1_0/platformio.ini index 9e6277d..f6b528b 100644 --- a/variants/QRPLabs_LightGateway_Plus_1_0/platformio.ini +++ b/variants/QRPLabs_LightGateway_Plus_1_0/platformio.ini @@ -7,4 +7,5 @@ build_flags = -D LIGHTGATEWAY_PLUS_1_0 lib_deps = ${common.lib_deps} - ${common.display_libs} \ No newline at end of file + ${common.display_libs} + adafruit/Adafruit SHTC3 Library @ 1.0.1 \ No newline at end of file