external Voltage Measurement added

This commit is contained in:
richonguzman 2023-09-20 21:28:17 -03:00
parent 5462521418
commit c13f9a62d2
7 changed files with 60 additions and 36 deletions

View File

@ -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!)
__________________________________________

View File

@ -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
}
}

View File

@ -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();

View File

@ -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;
}
}

View File

@ -5,7 +5,8 @@
namespace BATTERY_Utils {
float checkVoltages();
float checkBattery();
float checkExternalVoltage();
}

View File

@ -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; i<sampleNum; i++) {
sample = analogRead(Config.externalVoltagePin);
sampleSum += sample;
delayMicroseconds(50);
}
batteryVoltage = ((sampleSum/sampleNum) - readingCorrection);
return "VBat=" + String(batteryVoltage,2) + ")";
}
void processStatus() {
String status = Config.callsign + ">APLRG1";
@ -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);

View File

@ -5,7 +5,6 @@
namespace Utils {
String meassureExternalBattery();
void processStatus();
String getLocalIP();
void setupDisplay();