From 1884ed45ee8e81cea23d9bccb061fed26170f275 Mon Sep 17 00:00:00 2001 From: HrSh3rl0ck Date: Sat, 9 Sep 2023 00:16:23 +0200 Subject: [PATCH] Update for T-Beam v1.2 + some QOL After some tests, I could only find an incorrect ampere meter. I didn't find any function in the new PMU - so yeah, it's a just "nice to know" for me so I removed it. Maybe someone can program it somehow, but I've tried a lot... And a little QOL Update - i dont need the display to be always on... Push the middle Button (IO38) and the OLED Display will be deactivated or activated. (It was desired with the Issues). And ive added a timezone adapt - so the time is always right (does not include date!). --- README.md | 9 +++ data/tracker.json | 1 + platformio.ini | 5 ++ src/LoRa_APRS_Tracker.cpp | 58 ++++++++++++++--- src/configuration.cpp | 2 + src/configuration.h | 5 +- src/display.cpp | 9 +++ src/display.h | 2 + src/pins.h | 2 +- src/power_management.cpp | 129 +++++++++++++++++++++++++++++++------- src/power_management.h | 19 +++++- 11 files changed, 204 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 332ff19..fd7ab71 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,11 @@ +# Ive updated Peterus's LoRa Software to the new T-Beam v1.2 + +The new MPU hasnt the same functions as the old one - so the Ampere Meter isnt working anymore. Its a "nice to have" for me - so ive removed it... +Nothing more to say ^^ + +And a little QOL Update - i dont need the display to be always on... Push the middle Button (IO38) and the OLED Display will be deactivated or activated. (It was desired with the Issues). And ive added a timezone adapt - so the time is always right (does not include date!). + + # LoRa APRS Tracker The LoRa APRS Tracker will work with very cheep hardware which you can buy from amazon, ebay or aliexpress. @@ -11,6 +19,7 @@ You can use one of the Lora32 boards: * TTGO T-Beam V0.7 (433MHz SX1278) * TTGO T-Beam V1 (433MHz SX1278) +* TTGO T-Beam V1.2 (433MHz SX1278) This boards cost around 30 Euros, they are very cheap but perfect for an LoRa iGate. Keep in minde: you need a 433MHz version! diff --git a/data/tracker.json b/data/tracker.json index 174af42..586cbba 100644 --- a/data/tracker.json +++ b/data/tracker.json @@ -1,5 +1,6 @@ { "debug": false, + "adaptTimezone": 2, "beacons": [ { "callsign": "NOCALL-7", diff --git a/platformio.ini b/platformio.ini index 586c350..5e1edab 100644 --- a/platformio.ini +++ b/platformio.ini @@ -18,11 +18,16 @@ lib_deps = paulstoffregen/Time @ 1.6 shaggydog/OneButton @ 1.5.0 peterus/esp-logger @ 1.0.0 + lewisxhe/XPowersLib@^0.1.8 check_tool = cppcheck check_flags = cppcheck: --suppress=*:*.pio\* --inline-suppr -DCPPCHECK check_skip_packages = yes +[env:ttgo-t-beam-v1_2] +board = ttgo-t-beam +build_flags = -Werror -Wall -DTTGO_T_Beam_V1_2 + [env:ttgo-t-beam-v1] board = ttgo-t-beam build_flags = -Werror -Wall -DTTGO_T_Beam_V1_0 diff --git a/src/LoRa_APRS_Tracker.cpp b/src/LoRa_APRS_Tracker.cpp index 0a959d7..7ca4078 100644 --- a/src/LoRa_APRS_Tracker.cpp +++ b/src/LoRa_APRS_Tracker.cpp @@ -13,7 +13,7 @@ #include "pins.h" #include "power_management.h" -#define VERSION "22.19.0" +#define VERSION "23.09.08" logging::Logger logger; @@ -29,6 +29,8 @@ TinyGPSPlus gps; void setup_gps(); void load_config(); void setup_lora(); +bool OLED_deactivated = false; +int OLED_deactivatedTime = 0; String create_lat_aprs(RawDegrees lat); String create_long_aprs(RawDegrees lng); @@ -64,12 +66,13 @@ static void toggle_display() { void setup() { Serial.begin(115200); -#ifdef TTGO_T_Beam_V1_0 + +#if defined(TTGO_T_Beam_V1_0) || defined(TTGO_T_Beam_V1_2) Wire.begin(SDA, SCL); if (!powerManagement.begin(Wire)) { - logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "AXP192", "init done!"); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "PMU", "init done!"); } else { - logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "AXP192", "init failed!"); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "PMU", "init failed!"); } powerManagement.activateLoRa(); powerManagement.activateOLED(); @@ -82,9 +85,9 @@ void setup() { logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Main", "Version: " VERSION); setup_display(); - show_display("OE5BPA", "LoRa APRS Tracker", "by Peter Buchegger", "Version: " VERSION, 2000); + show_display("OE5BPA", "LoRa APRS Tracker", "by Peter Buchegger", "Updated by HrSh3rl0ck", "Version: " VERSION, 2000); load_config(); - + setup_gps(); setup_lora(); @@ -131,6 +134,26 @@ void loop() { } } + pinMode(GPIO_NUM_38, INPUT_PULLUP); + int btn_pressenIO38 = analogRead(GPIO_NUM_38); + if(btn_pressenIO38 != 4095){ + if(OLED_deactivatedTime >= 180){ + if(OLED_deactivated) { + OLED_deactivated = false; + awake_display(); + OLED_deactivatedTime = 0; + } else { + OLED_deactivated = true; + sleep_display(); + OLED_deactivatedTime = 0; + }; + } else { + OLED_deactivatedTime += 1; + }; + } else { + OLED_deactivatedTime = 0; + }; + bool gps_time_update = gps.time.isUpdated(); bool gps_loc_update = gps.location.isUpdated(); static bool gps_loc_update_valid = false; @@ -151,7 +174,7 @@ void loop() { static unsigned int rate_limit_message_text = 0; if (gps.time.isValid()) { - setTime(gps.time.hour(), gps.time.minute(), gps.time.second(), gps.date.day(), gps.date.month(), gps.date.year()); + setTime((gps.time.hour()), gps.time.minute(), gps.time.second(), gps.date.day(), gps.date.month(), gps.date.year()); if (gps_loc_update && nextBeaconTimeStamp <= now()) { send_update = true; @@ -178,7 +201,7 @@ void loop() { static bool BatteryIsConnected = false; static String batteryVoltage = ""; static String batteryChargeCurrent = ""; -#ifdef TTGO_T_Beam_V1_0 +#if defined(TTGO_T_Beam_V1_0) || defined(TTGO_T_Beam_V1_2) static unsigned int rate_limit_check_battery = 0; if (!(rate_limit_check_battery++ % 60)) BatteryIsConnected = powerManagement.isBatteryConnect(); @@ -286,7 +309,12 @@ void loop() { aprsmsg += BeaconMan.getCurrentBeaconConfig()->message; } if (BatteryIsConnected) { - aprsmsg += " - _Bat.: " + batteryVoltage + "V - Cur.: " + batteryChargeCurrent + "mA"; + #if defined(TTGO_T_Beam_V0_7) || defined(TTGO_T_Beam_V1_0) + aprsmsg += " - _Bat.: " + batteryVoltage + "V - Cur.: " + batteryChargeCurrent + "mA"; + #endif + #ifdef TTGO_T_Beam_V1_2 + aprsmsg += " - _Bat.: " + batteryVoltage + "V"; + #endif } if (BeaconMan.getCurrentBeaconConfig()->enhance_precision) { @@ -328,7 +356,17 @@ void loop() { if (gps_time_update) { - show_display(BeaconMan.getCurrentBeaconConfig()->callsign, createDateString(now()) + " " + createTimeString(now()), String("Sats: ") + gps.satellites.value() + " HDOP: " + gps.hdop.hdop(), String("Next Bcn: ") + (BeaconMan.getCurrentBeaconConfig()->smart_beacon.active ? "~" : "") + createTimeString(nextBeaconTimeStamp), BatteryIsConnected ? (String("Bat: ") + batteryVoltage + "V, " + batteryChargeCurrent + "mA") : "Powered via USB", String("Smart Beacon: " + getSmartBeaconState())); + show_display(BeaconMan.getCurrentBeaconConfig()->callsign, + createDateString(now()) + " " + createTimeString(now() + (Config.adaptTimezone * 60 * 60)), + String("Sats: ") + gps.satellites.value() + " HDOP: " + gps.hdop.hdop(), + String("Next Bcn: ") + (BeaconMan.getCurrentBeaconConfig()->smart_beacon.active ? "~" : "") + createTimeString(nextBeaconTimeStamp + (Config.adaptTimezone * 60 * 60)), + #if defined(TTGO_T_Beam_V0_7) || defined(TTGO_T_Beam_V1_0) + BatteryIsConnected ? (String("Bat: ") + batteryVoltage + "V, " + batteryChargeCurrent + "mA") : "Powered via USB", + #endif + #ifdef TTGO_T_Beam_V1_2 + BatteryIsConnected ? (String("Bat: ") + batteryVoltage + "V") : "Powered via USB", + #endif + String("Smart Beacon: " + getSmartBeaconState())); if (BeaconMan.getCurrentBeaconConfig()->smart_beacon.active) { // Change the Tx internal based on the current speed diff --git a/src/configuration.cpp b/src/configuration.cpp index dc9f572..808fe07 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -37,6 +37,7 @@ Configuration ConfigurationManagement::readConfiguration() { Configuration conf; conf.debug = data["debug"] | false; + conf.adaptTimezone = data["adaptTimezone"] | 0; JsonArray beacons = data["beacons"].as(); for (JsonVariant v : beacons) { @@ -119,6 +120,7 @@ void ConfigurationManagement::writeConfiguration(Configuration conf) { } data["debug"] = conf.debug; + data["adaptTimezone"] = conf.adaptTimezone; data["button"]["tx"] = conf.button.tx; data["button"]["alt_message"] = conf.button.alt_message; diff --git a/src/configuration.h b/src/configuration.h index c7dae47..cdb877f 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -72,10 +72,11 @@ public: int alt_message; }; - Configuration() : debug(false) { - } + Configuration() : debug(false) ,adaptTimezone(0) { + }; bool debug; + int adaptTimezone; std::list beacons; LoRa lora; PTT ptt; diff --git a/src/display.cpp b/src/display.cpp index 5c3effa..6f2beb7 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -11,6 +11,15 @@ extern logging::Logger logger; Adafruit_SSD1306 display(128, 64, &Wire, OLED_RST); +void sleep_display() +{ + display.ssd1306_command(SSD1306_DISPLAYOFF); +}; +void awake_display() +{ + display.ssd1306_command(SSD1306_DISPLAYON); +}; + // cppcheck-suppress unusedFunction void setup_display() { pinMode(OLED_RST, OUTPUT); diff --git a/src/display.h b/src/display.h index d7681ca..fe36881 100644 --- a/src/display.h +++ b/src/display.h @@ -3,6 +3,8 @@ #define DISPLAY_H_ void setup_display(); +void sleep_display(); +void awake_display(); void display_toggle(bool toggle); void show_display(String header, int wait = 0); diff --git a/src/pins.h b/src/pins.h index 88e47ab..4835883 100644 --- a/src/pins.h +++ b/src/pins.h @@ -16,7 +16,7 @@ #define GPS_TX 12 #endif -#ifdef TTGO_T_Beam_V1_0 +#if defined(TTGO_T_Beam_V1_0) || defined(TTGO_T_Beam_V1_2) #define GPS_RX 12 #define GPS_TX 34 #endif diff --git a/src/power_management.cpp b/src/power_management.cpp index d9527a4..523bee4 100644 --- a/src/power_management.cpp +++ b/src/power_management.cpp @@ -7,80 +7,165 @@ PowerManagement::PowerManagement() { // cppcheck-suppress unusedFunction bool PowerManagement::begin(TwoWire &port) { - bool result = axp.begin(port, AXP192_SLAVE_ADDRESS); - if (!result) { - axp.setDCDC1Voltage(3300); - } - return result; + #if defined(TTGO_T_Beam_V0_7) || defined(TTGO_T_Beam_V1_0) + bool result = axp.begin(port, AXP192_SLAVE_ADDRESS); + if (!result) { + axp.setDCDC1Voltage(3300); + } + return result; + #endif + #ifdef TTGO_T_Beam_V1_2 + bool result = PMU.begin(Wire, AXP2101_SLAVE_ADDRESS, 21, 22); + if (result) { + PMU.disableDC2(); + PMU.disableDC3(); + PMU.disableDC4(); + PMU.disableDC5(); + PMU.disableALDO1(); + PMU.disableALDO4(); + PMU.disableBLDO1(); + PMU.disableBLDO2(); + PMU.disableDLDO1(); + PMU.disableDLDO2(); + + PMU.setDC1Voltage(3300); + PMU.enableDC1(); + } + return result; + #endif } // cppcheck-suppress unusedFunction void PowerManagement::activateLoRa() { - axp.setPowerOutPut(AXP192_LDO2, AXP202_ON); + #if defined(TTGO_T_Beam_V0_7) || defined(TTGO_T_Beam_V1_0) + axp.setPowerOutPut(AXP192_LDO2, AXP202_ON); + #endif + #ifdef TTGO_T_Beam_V1_2 + PMU.setALDO2Voltage(3300); + PMU.enableALDO2(); + #endif } // cppcheck-suppress unusedFunction void PowerManagement::deactivateLoRa() { - axp.setPowerOutPut(AXP192_LDO2, AXP202_OFF); + #if defined(TTGO_T_Beam_V0_7) || defined(TTGO_T_Beam_V1_0) + axp.setPowerOutPut(AXP192_LDO2, AXP202_OFF); + #endif + #ifdef TTGO_T_Beam_V1_2 + PMU.disableALDO2(); + #endif } // cppcheck-suppress unusedFunction void PowerManagement::activateGPS() { - axp.setPowerOutPut(AXP192_LDO3, AXP202_ON); + #if defined(TTGO_T_Beam_V0_7) || defined(TTGO_T_Beam_V1_0) + axp.setPowerOutPut(AXP192_LDO3, AXP202_ON); + #endif + #ifdef TTGO_T_Beam_V1_2 + PMU.setALDO3Voltage(3300); + PMU.enableALDO3(); + #endif } // cppcheck-suppress unusedFunction void PowerManagement::deactivateGPS() { - axp.setPowerOutPut(AXP192_LDO3, AXP202_OFF); + #if defined(TTGO_T_Beam_V0_7) || defined(TTGO_T_Beam_V1_0) + axp.setPowerOutPut(AXP192_LDO3, AXP202_OFF); + #endif + #ifdef TTGO_T_Beam_V1_2 + PMU.disableALDO3(); + #endif } // cppcheck-suppress unusedFunction void PowerManagement::activateOLED() { - axp.setPowerOutPut(AXP192_DCDC1, AXP202_ON); + #if defined(TTGO_T_Beam_V0_7) || defined(TTGO_T_Beam_V1_0) + axp.setPowerOutPut(AXP192_DCDC1, AXP202_ON); + #endif + #ifdef TTGO_T_Beam_V1_2 + PMU.enableDC1(); + #endif } // cppcheck-suppress unusedFunction void PowerManagement::decativateOLED() { - axp.setPowerOutPut(AXP192_DCDC1, AXP202_OFF); + #if defined(TTGO_T_Beam_V0_7) || defined(TTGO_T_Beam_V1_0) + axp.setPowerOutPut(AXP192_DCDC1, AXP202_OFF); + #endif + #ifdef TTGO_T_Beam_V1_2 + PMU.disableDC1(); + #endif } // cppcheck-suppress unusedFunction void PowerManagement::disableChgLed() { - axp.setChgLEDMode(AXP20X_LED_OFF); + #if defined(TTGO_T_Beam_V0_7) || defined(TTGO_T_Beam_V1_0) + axp.setChgLEDMode(AXP20X_LED_OFF); + #endif } // cppcheck-suppress unusedFunction void PowerManagement::enableChgLed() { - axp.setChgLEDMode(AXP20X_LED_LOW_LEVEL); + #if defined(TTGO_T_Beam_V0_7) || defined(TTGO_T_Beam_V1_0) + axp.setChgLEDMode(AXP20X_LED_LOW_LEVEL); + #endif } // cppcheck-suppress unusedFunction void PowerManagement::activateMeasurement() { - axp.adc1Enable(AXP202_BATT_CUR_ADC1 | AXP202_BATT_VOL_ADC1, true); + #if defined(TTGO_T_Beam_V0_7) || defined(TTGO_T_Beam_V1_0) + axp.adc1Enable(AXP202_BATT_CUR_ADC1 | AXP202_BATT_VOL_ADC1, true); + #endif + #ifdef TTGO_T_Beam_V1_2 + PMU.enableBattDetection(); + PMU.enableVbusVoltageMeasure(); + PMU.enableBattVoltageMeasure(); + PMU.enableSystemVoltageMeasure(); + #endif } // cppcheck-suppress unusedFunction void PowerManagement::deactivateMeasurement() { - axp.adc1Enable(AXP202_BATT_CUR_ADC1 | AXP202_BATT_VOL_ADC1, false); + #if defined(TTGO_T_Beam_V0_7) || defined(TTGO_T_Beam_V1_0) + axp.adc1Enable(AXP202_BATT_CUR_ADC1 | AXP202_BATT_VOL_ADC1, false); + #endif } // cppcheck-suppress unusedFunction double PowerManagement::getBatteryVoltage() { - return axp.getBattVoltage() / 1000.0; + #if defined(TTGO_T_Beam_V0_7) || defined(TTGO_T_Beam_V1_0) + return axp.getBattVoltage() / 1000.0; + #endif + #ifdef TTGO_T_Beam_V1_2 + return PMU.getBattVoltage() / 1000.0; + #endif } // cppcheck-suppress unusedFunction double PowerManagement::getBatteryChargeDischargeCurrent() { - if (axp.isChargeing()) { - return axp.getBattChargeCurrent(); - } - return -1.0 * axp.getBattDischargeCurrent(); + #if defined(TTGO_T_Beam_V0_7) || defined(TTGO_T_Beam_V1_0) + if (axp.isChargeing()) { + return axp.getBattChargeCurrent(); + } + return -1.0 * axp.getBattDischargeCurrent(); + #endif + return 0; } bool PowerManagement::isBatteryConnect() { - return axp.isBatteryConnect(); + #if defined(TTGO_T_Beam_V0_7) || defined(TTGO_T_Beam_V1_0) + return axp.isBatteryConnect(); + #endif + #ifdef TTGO_T_Beam_V1_2 + return PMU.isBatteryConnect(); + #endif } bool PowerManagement::isChargeing() { - return axp.isChargeing(); + #if defined(TTGO_T_Beam_V0_7) || defined(TTGO_T_Beam_V1_0) + return axp.isChargeing(); + #endif + #ifdef TTGO_T_Beam_V1_2 + return PMU.isCharging(); + #endif } diff --git a/src/power_management.h b/src/power_management.h index 73edfbf..e64241b 100644 --- a/src/power_management.h +++ b/src/power_management.h @@ -2,7 +2,17 @@ #define POWER_MANAGEMENT_H_ #include -#include + +#if defined(TTGO_T_Beam_V0_7) || defined(TTGO_T_Beam_V1_0) + #include +#endif +#ifdef TTGO_T_Beam_V1_2 + #define XPOWERS_CHIP_AXP2101 + #include +#endif + + + class PowerManagement { public: @@ -31,7 +41,12 @@ public: bool isChargeing(); private: - AXP20X_Class axp; + #if defined(TTGO_T_Beam_V0_7) || defined(TTGO_T_Beam_V1_0) + AXP20X_Class axp; + #endif + #ifdef TTGO_T_Beam_V1_2 + XPowersPMU PMU; + #endif }; #endif