From 28e4fc0643336b33df3c9ef1c060877663c6ecc7 Mon Sep 17 00:00:00 2001 From: free-x Date: Fri, 24 Jan 2025 12:22:26 +0100 Subject: [PATCH 1/4] extend CI for OBP boards --- lib/obp60task/platformio.ini | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/obp60task/platformio.ini b/lib/obp60task/platformio.ini index da78f39..16f3269 100644 --- a/lib/obp60task/platformio.ini +++ b/lib/obp60task/platformio.ini @@ -2,7 +2,9 @@ #if you want a pio run to only build #your special environments you can set this here #by uncommenting the next line -default_envs = obp60_s3 +default_envs = + obp60_s3 + obp40_s3 [env:obp60_s3] platform = espressif32@6.8.1 From 7afcb864042343dd863439f07793d678309d1370 Mon Sep 17 00:00:00 2001 From: norbert-walter Date: Fri, 24 Jan 2025 15:23:02 +0100 Subject: [PATCH 2/4] OBP40 Battery voltage measuring and capacity calculation --- lib/obp60task/OBPSensorTask.cpp | 33 +++++++++++++++++++++++++++++++-- lib/obp60task/Pagedata.h | 2 ++ lib/obp60task/platformio.ini | 6 +++++- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/lib/obp60task/OBPSensorTask.cpp b/lib/obp60task/OBPSensorTask.cpp index 99071ab..cd488ab 100644 --- a/lib/obp60task/OBPSensorTask.cpp +++ b/lib/obp60task/OBPSensorTask.cpp @@ -88,8 +88,16 @@ void sensorTask(void *param){ double voffset = (api->getConfig()->getConfigItem(api->getConfig()->vOffset,true)->asString()).toFloat(); double vslope = (api->getConfig()->getConfigItem(api->getConfig()->vSlope,true)->asString()).toFloat(); 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 + #ifdef LIPO_ACCU_1200 + sensors.BatteryChargeStatus = 0; // Set to discharging + sensors.batteryLevelLiPo = 0; // Level 0...100% + #endif sensors.batteryCurrent = 0; sensors.batteryPower = 0; // Fill average arrays with start values @@ -459,8 +467,29 @@ void sensorTask(void *param){ // Send supply voltage value all 1s if(millis() > starttime5 + 1000 && String(powsensor1) == "off"){ 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 + #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 batV.reading(int(sensors.batteryVoltage * 100)); // Calculate the average values for different time lines from integer values diff --git a/lib/obp60task/Pagedata.h b/lib/obp60task/Pagedata.h index b385b5c..d511aee 100644 --- a/lib/obp60task/Pagedata.h +++ b/lib/obp60task/Pagedata.h @@ -31,6 +31,8 @@ typedef struct{ double batteryVoltage300 = 0; // Sliding average over 300 values double batteryCurrent300 = 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 solarCurrent = 0; double solarPower = 0; diff --git a/lib/obp60task/platformio.ini b/lib/obp60task/platformio.ini index da78f39..662032a 100644 --- a/lib/obp60task/platformio.ini +++ b/lib/obp60task/platformio.ini @@ -2,7 +2,9 @@ #if you want a pio run to only build #your special environments you can set this here #by uncommenting the next line -default_envs = obp60_s3 +default_envs = + obp60_s3 + obp40_s3 [env:obp60_s3] platform = espressif32@6.8.1 @@ -91,6 +93,8 @@ build_flags= -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 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} 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 From e9ee49a6ef923a6e888a40364acb109c1650c8bb Mon Sep 17 00:00:00 2001 From: norbert-walter Date: Fri, 24 Jan 2025 17:33:34 +0100 Subject: [PATCH 3/4] Add undervoltage for LiPo accu for OBP40 --- lib/obp60task/obp60task.cpp | 39 ++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/lib/obp60task/obp60task.cpp b/lib/obp60task/obp60task.cpp index 3defb2b..b87c4bd 100644 --- a/lib/obp60task/obp60task.cpp +++ b/lib/obp60task/obp60task.cpp @@ -308,13 +308,42 @@ void registerAllPages(PageList &list){ // Undervoltage detection for shutdown display void underVoltageDetection(GwApi *api, CommonData &common){ + float actVoltage = 0; + float minVoltage = 0; // Read settings float vslope = uint(api->getConfig()->getConfigItem(api->getConfig()->vSlope,true)->asFloat()); float voffset = uint(api->getConfig()->getConfigItem(api->getConfig()->vOffset,true)->asFloat()); // Read supply voltage - float actVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.17) * 20; // V = 1/20 * Vin + #if defined VOLTAGE_SENSOR && defined LIPO_ACCU_1200 + actVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.53) * 2; // Vin = 1/2 for OBP40 + minVoltage = 3.65; // Absolut minimum volatge for 3,7V LiPo accu + #else + actVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.17) * 20; // Vin = 1/20 for OBP60 + minVoltage = MIN_VOLTAGE; + #endif actVoltage = actVoltage * vslope + voffset; - if(actVoltage < MIN_VOLTAGE){ + if(actVoltage < minVoltage){ + #if defined VOLTAGE_SENSOR && defined LIPO_ACCU_1200 + // Switch off all power lines + setPortPin(OBP_BACKLIGHT_LED, false); // Backlight Off + setFlashLED(false); // Flash LED Off + buzzer(TONE4, 20); // Buzzer tone 4kHz 20ms + // Shutdown EInk display + getdisplay().setFullWindow(); // Set full Refresh + //getdisplay().setPartialWindow(0, 0, getdisplay().width(), getdisplay().height()); // Set partial update + getdisplay().fillScreen(common.bgcolor); // Clear screen + getdisplay().setTextColor(common.fgcolor); + getdisplay().setFont(&Ubuntu_Bold20pt7b); + getdisplay().setCursor(65, 150); + getdisplay().print("Undervoltage"); + getdisplay().setFont(&Ubuntu_Bold8pt7b); + getdisplay().setCursor(65, 175); + getdisplay().print("To wake up press reset"); + getdisplay().nextPage(); // Partial update + getdisplay().powerOff(); // Display power off + setPortPin(OBP_POWER_EPD, false); // Power off ePaper display + setPortPin(OBP_POWER_SD, false); // Power off SD card + #else // Switch off all power lines setPortPin(OBP_BACKLIGHT_LED, false); // Backlight Off setFlashLED(false); // Flash LED Off @@ -327,8 +356,12 @@ void underVoltageDetection(GwApi *api, CommonData &common){ getdisplay().setFont(&Ubuntu_Bold20pt7b); getdisplay().setCursor(65, 150); getdisplay().print("Undervoltage"); + getdisplay().setFont(&Ubuntu_Bold8pt7b); + getdisplay().setCursor(65, 175); + getdisplay().print("To wake up repower system"); getdisplay().nextPage(); // Partial update getdisplay().powerOff(); // Display power off + #endif // Stop system while(true){ esp_deep_sleep_start(); // Deep Sleep without weakup. Weakup only after power cycle (restart). @@ -353,7 +386,7 @@ void deepSleep(CommonData &common){ getdisplay().print("Sleep Mode"); getdisplay().setFont(&Ubuntu_Bold8pt7b); getdisplay().setCursor(65, 175); - getdisplay().print("For wakeup press wheel and wait 5s"); + getdisplay().print("To wake up press wheel and wait 5s"); getdisplay().nextPage(); // Partial update getdisplay().powerOff(); // Display power off setPortPin(OBP_POWER_EPD, false); // Power off ePaper display From 0b7863cb86785766929a184da43481a85e8a7061 Mon Sep 17 00:00:00 2001 From: norbert-walter Date: Fri, 24 Jan 2025 18:41:48 +0100 Subject: [PATCH 4/4] Typo --- lib/obp60task/obp60task.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/obp60task/obp60task.cpp b/lib/obp60task/obp60task.cpp index b87c4bd..4c0ff64 100644 --- a/lib/obp60task/obp60task.cpp +++ b/lib/obp60task/obp60task.cpp @@ -370,7 +370,7 @@ void underVoltageDetection(GwApi *api, CommonData &common){ } #ifdef BOARD_OBP40S3 -// Deep sleep funktion +// Deep sleep function void deepSleep(CommonData &common){ // Switch off all power lines setPortPin(OBP_BACKLIGHT_LED, false); // Backlight Off