OBP40 Battery voltage measuring and capacity calculation
This commit is contained in:
parent
a9525676b2
commit
7afcb86404
|
@ -88,8 +88,16 @@ void sensorTask(void *param){
|
||||||
double voffset = (api->getConfig()->getConfigItem(api->getConfig()->vOffset,true)->asString()).toFloat();
|
double voffset = (api->getConfig()->getConfigItem(api->getConfig()->vOffset,true)->asString()).toFloat();
|
||||||
double vslope = (api->getConfig()->getConfigItem(api->getConfig()->vSlope,true)->asString()).toFloat();
|
double vslope = (api->getConfig()->getConfigItem(api->getConfig()->vSlope,true)->asString()).toFloat();
|
||||||
if(String(powsensor1) == "off"){
|
if(String(powsensor1) == "off"){
|
||||||
sensors.batteryVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.17) * 20; // Vin = 1/20
|
#ifdef VOLTAGE_SENSOR
|
||||||
|
sensors.batteryVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.53) * 2; // Vin = 1/2 for OBP40
|
||||||
|
#else
|
||||||
|
sensors.batteryVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.17) * 20; // Vin = 1/20 for OBP60
|
||||||
|
#endif
|
||||||
sensors.batteryVoltage = sensors.batteryVoltage * vslope + voffset; // Calibration
|
sensors.batteryVoltage = sensors.batteryVoltage * vslope + voffset; // Calibration
|
||||||
|
#ifdef LIPO_ACCU_1200
|
||||||
|
sensors.BatteryChargeStatus = 0; // Set to discharging
|
||||||
|
sensors.batteryLevelLiPo = 0; // Level 0...100%
|
||||||
|
#endif
|
||||||
sensors.batteryCurrent = 0;
|
sensors.batteryCurrent = 0;
|
||||||
sensors.batteryPower = 0;
|
sensors.batteryPower = 0;
|
||||||
// Fill average arrays with start values
|
// Fill average arrays with start values
|
||||||
|
@ -459,8 +467,29 @@ void sensorTask(void *param){
|
||||||
// Send supply voltage value all 1s
|
// Send supply voltage value all 1s
|
||||||
if(millis() > starttime5 + 1000 && String(powsensor1) == "off"){
|
if(millis() > starttime5 + 1000 && String(powsensor1) == "off"){
|
||||||
starttime5 = millis();
|
starttime5 = millis();
|
||||||
sensors.batteryVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.17) * 20; // Vin = 1/20
|
#ifdef VOLTAGE_SENSOR
|
||||||
|
sensors.batteryVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.53) * 2; // Vin = 1/2 for OBP40
|
||||||
|
#else
|
||||||
|
sensors.batteryVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.17) * 20; // Vin = 1/20 for OBP60
|
||||||
|
#endif
|
||||||
sensors.batteryVoltage = sensors.batteryVoltage * vslope + voffset; // Calibration
|
sensors.batteryVoltage = sensors.batteryVoltage * vslope + voffset; // Calibration
|
||||||
|
#ifdef LIPO_ACCU_1200
|
||||||
|
if(sensors.batteryVoltage > 4.1){
|
||||||
|
sensors.BatteryChargeStatus = 1; // Charging active
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
sensors.BatteryChargeStatus = 0; // Discharging
|
||||||
|
}
|
||||||
|
// Polynomfit for LiPo capacity calculation for 3,7V LiPo accus, 0...100%
|
||||||
|
sensors.batteryLevelLiPo = sensors.batteryVoltage * sensors.batteryVoltage * 174.9513 + sensors.batteryVoltage * 1147,7686 + 1868.5120;
|
||||||
|
// Limiter
|
||||||
|
if(sensors.batteryLevelLiPo > 100){
|
||||||
|
sensors.batteryLevelLiPo = 100;
|
||||||
|
}
|
||||||
|
if(sensors.batteryLevelLiPo < 0){
|
||||||
|
sensors.batteryLevelLiPo = 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
// Save new data in average array
|
// Save new data in average array
|
||||||
batV.reading(int(sensors.batteryVoltage * 100));
|
batV.reading(int(sensors.batteryVoltage * 100));
|
||||||
// Calculate the average values for different time lines from integer values
|
// Calculate the average values for different time lines from integer values
|
||||||
|
|
|
@ -31,6 +31,8 @@ typedef struct{
|
||||||
double batteryVoltage300 = 0; // Sliding average over 300 values
|
double batteryVoltage300 = 0; // Sliding average over 300 values
|
||||||
double batteryCurrent300 = 0;
|
double batteryCurrent300 = 0;
|
||||||
double batteryPower300 = 0;
|
double batteryPower300 = 0;
|
||||||
|
double batteryLevelLiPo = 0; // Battery level for OBP40 LiPo accu
|
||||||
|
int BatteryChargeStatus = 0; // LiPo charge status: 0 = discharge, 1 = loading activ
|
||||||
double solarVoltage = 0;
|
double solarVoltage = 0;
|
||||||
double solarCurrent = 0;
|
double solarCurrent = 0;
|
||||||
double solarPower = 0;
|
double solarPower = 0;
|
||||||
|
|
|
@ -2,7 +2,9 @@
|
||||||
#if you want a pio run to only build
|
#if you want a pio run to only build
|
||||||
#your special environments you can set this here
|
#your special environments you can set this here
|
||||||
#by uncommenting the next line
|
#by uncommenting the next line
|
||||||
default_envs = obp60_s3
|
default_envs =
|
||||||
|
obp60_s3
|
||||||
|
obp40_s3
|
||||||
|
|
||||||
[env:obp60_s3]
|
[env:obp60_s3]
|
||||||
platform = espressif32@6.8.1
|
platform = espressif32@6.8.1
|
||||||
|
@ -91,6 +93,8 @@ build_flags=
|
||||||
-D DISABLE_DIAGNOSTIC_OUTPUT #Disable diagnostic output for GxEPD2 lib
|
-D DISABLE_DIAGNOSTIC_OUTPUT #Disable diagnostic output for GxEPD2 lib
|
||||||
-D BOARD_OBP40S3 #Board OBP40 V1.0 with ESP32S3 SKU:DIE07300S (CrowPanel 4.2)
|
-D BOARD_OBP40S3 #Board OBP40 V1.0 with ESP32S3 SKU:DIE07300S (CrowPanel 4.2)
|
||||||
-D DISPLAY_GDEY042T81 #new E-Ink display from Waveshare, R10 2.2 ohm
|
-D DISPLAY_GDEY042T81 #new E-Ink display from Waveshare, R10 2.2 ohm
|
||||||
|
-D LIPO_ACCU_1200 #Hardware extension, LiPo accu 3,7V 1200mAh
|
||||||
|
-D VOLTAGE_SENSOR #Hardware extension, LiPo voltage sensor with two resistors
|
||||||
${env.build_flags}
|
${env.build_flags}
|
||||||
upload_port = /dev/ttyUSB0 #OBP40 download via external USB/Serail converter
|
upload_port = /dev/ttyUSB0 #OBP40 download via external USB/Serail converter
|
||||||
upload_protocol = esptool #firmware upload via USB OTG seriell, by first upload need to set the ESP32-S3 in the upload mode with shortcut GND to Pin27
|
upload_protocol = esptool #firmware upload via USB OTG seriell, by first upload need to set the ESP32-S3 in the upload mode with shortcut GND to Pin27
|
||||||
|
|
Loading…
Reference in New Issue