From c13f9a62d25d506fb3860a593214800e20083e00 Mon Sep 17 00:00:00 2001 From: richonguzman Date: Wed, 20 Sep 2023 21:28:17 -0300 Subject: [PATCH] external Voltage Measurement added --- README.md | 1 + data/igate_conf.json | 8 ++++---- src/LoRa_APRS_iGate.cpp | 5 ++++- src/battery_utils.cpp | 38 +++++++++++++++++++++++++++++--------- src/battery_utils.h | 3 ++- src/utils.cpp | 40 ++++++++++++++++++++-------------------- src/utils.h | 1 - 7 files changed, 60 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index e7d3df4..1873237 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,7 @@ Versions: - 2023.07.16 Small OTA, BME module update. - 2023.07.31 StationMode5 added: iGate when WiFi and APRS available, DigiRepeater when not. - 2023.08.05 Ground Height Correction for Pressure readings added +- 2023.08.20 Added External Voltage Measurement (Max 15V!) __________________________________________ diff --git a/data/igate_conf.json b/data/igate_conf.json index a06b91e..cfc15ae 100644 --- a/data/igate_conf.json +++ b/data/igate_conf.json @@ -50,14 +50,14 @@ "active": false }, "ota": { - "username":"richon", - "password": "totoro" + "username":"", + "password": "" }, "other": { "beaconInterval": 15, "rememberStationTime": 30, "sendBatteryVoltage": false, - "externalVoltageMeasurement" : true, - "externalVoltagePin": 13 + "externalVoltageMeasurement" : false, + "externalVoltagePin": 34 } } \ No newline at end of file diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index bd28739..380f11d 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -20,7 +20,7 @@ Configuration Config; WiFiClient espClient; -String versionDate = "2023.09.19"; +String versionDate = "2023.09.20"; int myWiFiAPIndex = 0; int myWiFiAPSize = Config.wifiAPs.size(); WiFi_AP *currentWiFi = &Config.wifiAPs[myWiFiAPIndex]; @@ -49,6 +49,9 @@ void setup() { Serial.begin(115200); pinMode(batteryPin, INPUT); pinMode(greenLed, OUTPUT); + if (Config.externalVoltageMeasurement) { + pinMode(Config.externalVoltagePin, INPUT); + } delay(1000); Utils::setupDisplay(); WIFI_Utils::setup(); diff --git a/src/battery_utils.cpp b/src/battery_utils.cpp index c5f51f1..d28bb0e 100644 --- a/src/battery_utils.cpp +++ b/src/battery_utils.cpp @@ -1,20 +1,40 @@ #include "battery_utils.h" +#include "configuration.h" #include "pins_config.h" +extern Configuration Config; + float adcReadingTransformation = (3.3/4095); float voltageDividerCorrection = 0.288; +// for External Voltage Measurment (MAX = 15Volts !!!) +float R1 = 100.000; //in Kilo-Ohms +float R2 = 27.000; //in Kilo-Ohms +float readingCorrection = 0.125; +float multiplyCorrection = 0.035; + namespace BATTERY_Utils { -float checkVoltages() { - float sample; - int sampleSum = 0; - for (int i=0; i<100; i++) { - sample = analogRead(batteryPin); - sampleSum += sample; - delayMicroseconds(50); + float checkBattery() { + int sample; + int sampleSum = 0; + for (int i=0; i<100; i++) { + sample = analogRead(batteryPin); + sampleSum += sample; + delayMicroseconds(50); + } + return (2 * (sampleSum/100) * adcReadingTransformation) + voltageDividerCorrection; + } + + float checkExternalVoltage() { + int sample; + int sampleSum = 0; + for (int i=0; i<100; i++) { + sample = analogRead(Config.externalVoltagePin); + sampleSum += sample; + delayMicroseconds(50); + } + return ((((sampleSum/100)* adcReadingTransformation) + readingCorrection) * ((R1+R2)/R2)) - multiplyCorrection; } - return (2 * (sampleSum/100) * adcReadingTransformation) + voltageDividerCorrection; -} } \ No newline at end of file diff --git a/src/battery_utils.h b/src/battery_utils.h index 58e5df9..fe07a08 100644 --- a/src/battery_utils.h +++ b/src/battery_utils.h @@ -5,7 +5,8 @@ namespace BATTERY_Utils { -float checkVoltages(); +float checkBattery(); +float checkExternalVoltage(); } diff --git a/src/utils.cpp b/src/utils.cpp index db7bf1a..7da3fe3 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -45,7 +45,6 @@ extern bool WiFiConnect; String name; String email; -//const char* PARAM_MESSAGE = "message"; namespace Utils { @@ -53,20 +52,6 @@ void notFound(AsyncWebServerRequest *request) { request->send(404, "text/plain", "Not found"); } -String meassureExternalBattery() { - int16_t sample; - int sampleNum = 50; - float readingCorrection = 0.0018; - float batteryVoltage, sampleSum; - sampleSum = 0; - for (int i=0; iAPLRG1"; @@ -128,7 +113,10 @@ void checkBeaconInterval() { beaconPacket = iGateBeaconPacket; } if (Config.sendBatteryVoltage) { - beaconPacket += " (Batt=" + String(BATTERY_Utils::checkVoltages(),2) + "V)"; + beaconPacket += " (Batt=" + String(BATTERY_Utils::checkBattery(),2) + "V)"; + } + if (Config.externalVoltageMeasurement) { + beaconPacket += " (Ext V=" + String(BATTERY_Utils::checkExternalVoltage(),2) + "V)"; } if (stationMode==1 || stationMode==2) { thirdLine = getLocalIP(); @@ -138,7 +126,10 @@ void checkBeaconInterval() { sixthLine = ""; show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, "SENDING iGate BEACON", 1000); if (Config.sendBatteryVoltage) { - sixthLine = " (Batt=" + String(BATTERY_Utils::checkVoltages(),2) + "V)"; + sixthLine = " (Batt=" + String(BATTERY_Utils::checkBattery(),2) + "V)"; + } + if (Config.externalVoltageMeasurement) { + sixthLine = " (Ext V=" + String(BATTERY_Utils::checkExternalVoltage(),2) + "V)"; } seventhLine = " listening..."; espClient.write((beaconPacket + "\n").c_str()); @@ -157,7 +148,10 @@ void checkBeaconInterval() { sixthLine = ""; show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, "SENDING iGate BEACON", 0); if (Config.sendBatteryVoltage) { - sixthLine = " (Batt=" + String(BATTERY_Utils::checkVoltages(),2) + "V)"; + sixthLine = " (Batt=" + String(BATTERY_Utils::checkBattery(),2) + "V)"; + } + if (Config.externalVoltageMeasurement) { + sixthLine = " (Ext V=" + String(BATTERY_Utils::checkExternalVoltage(),2) + "V)"; } seventhLine = " listening..."; if (stationMode==4) { @@ -177,7 +171,10 @@ void checkBeaconInterval() { thirdLine = getLocalIP(); show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, "SENDING iGate BEACON", 1000); if (Config.sendBatteryVoltage) { - sixthLine = " (Batt=" + String(BATTERY_Utils::checkVoltages(),2) + "V)"; + sixthLine = " (Batt=" + String(BATTERY_Utils::checkBattery(),2) + "V)"; + } + if (Config.externalVoltageMeasurement) { + sixthLine = " (Ext V=" + String(BATTERY_Utils::checkExternalVoltage(),2) + "V)"; } seventhLine = " listening..."; espClient.write((beaconPacket + "\n").c_str()); @@ -185,7 +182,10 @@ void checkBeaconInterval() { } else { show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, "SENDING iGate BEACON", 0); if (Config.sendBatteryVoltage) { - sixthLine = " (Batt=" + String(BATTERY_Utils::checkVoltages(),2) + "V)"; + sixthLine = " (Batt=" + String(BATTERY_Utils::checkBattery(),2) + "V)"; + } + if (Config.externalVoltageMeasurement) { + sixthLine = " (Ext V=" + String(BATTERY_Utils::checkExternalVoltage(),2) + "V)"; } seventhLine = " listening..."; LoRa_Utils::sendNewPacket("APRS", beaconPacket); diff --git a/src/utils.h b/src/utils.h index ae20a22..f70f164 100644 --- a/src/utils.h +++ b/src/utils.h @@ -5,7 +5,6 @@ namespace Utils { -String meassureExternalBattery(); void processStatus(); String getLocalIP(); void setupDisplay();