From 867a85d228e23794dd3a823c0b9e187adba00aa7 Mon Sep 17 00:00:00 2001 From: richonguzman Date: Tue, 9 Jan 2024 01:53:51 -0300 Subject: [PATCH] HeltecV3 fixes --- src/LoRa_APRS_Tracker.cpp | 6 +- src/pins_config.h | 138 +++++++++++++++++++------------------- src/power_utils.cpp | 20 +++--- src/station_utils.cpp | 3 + 4 files changed, 88 insertions(+), 79 deletions(-) diff --git a/src/LoRa_APRS_Tracker.cpp b/src/LoRa_APRS_Tracker.cpp index af10975..29fff87 100644 --- a/src/LoRa_APRS_Tracker.cpp +++ b/src/LoRa_APRS_Tracker.cpp @@ -30,11 +30,11 @@ TinyGPSPlus gps; #if !defined(TTGO_T_Beam_S3_SUPREME_V3) && !defined(HELTEC_V3_GPS) BluetoothSerial SerialBT; #endif -#if defined(TTGO_T_Beam_V0_7) || defined(TTGO_T_Beam_V1_0) || defined(TTGO_T_Beam_V1_2) || defined(TTGO_T_Beam_V1_0_SX1268) || defined(ESP32_DIY_1W_LoRa_GPS) || defined(TTGO_T_Beam_V1_2_SX1262) || defined(TTGO_T_Beam_S3_SUPREME_V3) +#if defined(TTGO_T_Beam_V0_7) || defined(TTGO_T_Beam_V1_0) || defined(TTGO_T_Beam_V1_2) || defined(TTGO_T_Beam_V1_0_SX1268) || defined(ESP32_DIY_1W_LoRa_GPS) || defined(TTGO_T_Beam_V1_2_SX1262) || defined(TTGO_T_Beam_S3_SUPREME_V3) || defined(HELTEC_V3_GPS) OneButton userButton = OneButton(BUTTON_PIN, true, true); #endif -String versionDate = "2024.01.05"; +String versionDate = "2024.01.09"; int myBeaconsIndex = 0; int myBeaconsSize = Config.beacons.size(); @@ -148,7 +148,7 @@ void setup() { } if (!Config.simplifiedTrackerMode) { - #if defined(TTGO_T_Beam_V0_7) || defined(TTGO_T_Beam_V1_0) || defined(TTGO_T_Beam_V1_2) || defined(TTGO_T_Beam_V1_0_SX1268) || defined(ESP32_DIY_1W_LoRa_GPS) || defined(TTGO_T_Beam_V1_2_SX1262) || defined(TTGO_T_Beam_S3_SUPREME_V3) + #if defined(TTGO_T_Beam_V0_7) || defined(TTGO_T_Beam_V1_0) || defined(TTGO_T_Beam_V1_2) || defined(TTGO_T_Beam_V1_0_SX1268) || defined(ESP32_DIY_1W_LoRa_GPS) || defined(TTGO_T_Beam_V1_2_SX1262) || defined(TTGO_T_Beam_S3_SUPREME_V3) || defined(HELTEC_V3_GPS) userButton.attachClick(BUTTON_Utils::singlePress); userButton.attachLongPressStart(BUTTON_Utils::longPress); userButton.attachDoubleClick(BUTTON_Utils::doublePress); diff --git a/src/pins_config.h b/src/pins_config.h index 9f1e1de..30168d4 100644 --- a/src/pins_config.h +++ b/src/pins_config.h @@ -6,98 +6,100 @@ #undef OLED_RST #if !defined(TTGO_T_Beam_S3_SUPREME_V3) && !defined(HELTEC_V3_GPS) -#define OLED_SDA 21 -#define OLED_SCL 22 -#define OLED_RST 16 +#define OLED_SDA 21 +#define OLED_SCL 22 +#define OLED_RST 16 #endif #if defined(TTGO_T_Beam_V1_0) || defined(TTGO_T_Beam_V1_2) || defined(TTGO_T_Beam_V1_0_SX1268) || defined(TTGO_T_Beam_V1_2_SX1262) -#define GPS_RX 12 -#define GPS_TX 34 -#define BUTTON_PIN 38 // The middle button GPIO on the T-Beam +#define GPS_RX 12 +#define GPS_TX 34 +#define BUTTON_PIN 38 // The middle button GPIO on the T-Beam #endif #if defined(ESP32_DIY_LoRa_GPS) || defined(TTGO_T_LORA32_V2_1_GPS) -#define GPS_RX 12 -#define GPS_TX 34 -#define BUTTON_PIN -1 -#define LORA_SCK 5 -#define LORA_MISO 19 -#define LORA_MOSI 27 -#define LORA_CS 18 // CS --> NSS -#define LORA_RST 23 -#define LORA_IRQ 26 // IRQ --> DIO0 +#define GPS_RX 12 +#define GPS_TX 34 +#define BUTTON_PIN -1 +#define LORA_SCK 5 +#define LORA_MISO 19 +#define LORA_MOSI 27 +#define LORA_CS 18 // CS --> NSS +#define LORA_RST 23 +#define LORA_IRQ 26 // IRQ --> DIO0 #endif #ifdef ESP32_DIY_1W_LoRa_GPS -#define GPS_RX 17 -#define GPS_TX 16 -#define BUTTON_PIN 15 -#define RADIO_SCLK_PIN 18 -#define RADIO_MISO_PIN 19 -#define RADIO_MOSI_PIN 23 -#define RADIO_CS_PIN 5 -#define RADIO_RST_PIN 27 -#define RADIO_DIO1_PIN 12 -#define RADIO_BUSY_PIN 14 -#define RADIO_RXEN 32 -#define RADIO_TXEN 25 +#define GPS_RX 17 +#define GPS_TX 16 +#define BUTTON_PIN 15 +#define RADIO_SCLK_PIN 18 +#define RADIO_MISO_PIN 19 +#define RADIO_MOSI_PIN 23 +#define RADIO_CS_PIN 5 +#define RADIO_RST_PIN 27 +#define RADIO_DIO1_PIN 12 +#define RADIO_BUSY_PIN 14 +#define RADIO_RXEN 32 +#define RADIO_TXEN 25 #endif #if defined(TTGO_T_Beam_V1_0_SX1268) || defined(TTGO_T_Beam_V1_2_SX1262) -#define RADIO_SCLK_PIN 5 -#define RADIO_MISO_PIN 19 -#define RADIO_MOSI_PIN 27 -#define RADIO_CS_PIN 18 -#define RADIO_DIO0_PIN 26 -#define RADIO_RST_PIN 23 -#define RADIO_DIO1_PIN 33 -#define RADIO_BUSY_PIN 32 +#define RADIO_SCLK_PIN 5 +#define RADIO_MISO_PIN 19 +#define RADIO_MOSI_PIN 27 +#define RADIO_CS_PIN 18 +#define RADIO_DIO0_PIN 26 +#define RADIO_RST_PIN 23 +#define RADIO_DIO1_PIN 33 +#define RADIO_BUSY_PIN 32 #endif #ifdef TTGO_T_Beam_V0_7 -#define GPS_RX 15 -#define GPS_TX 12 -#define BUTTON_PIN 39 +#define GPS_RX 15 +#define GPS_TX 12 +#define BUTTON_PIN 39 #endif #ifdef TTGO_T_LORA32_V2_1_TNC -#define GPS_RX -1 -#define GPS_TX -1 -#define BUTTON_PIN -1 +#define GPS_RX -1 +#define GPS_TX -1 +#define BUTTON_PIN -1 #endif #if defined(TTGO_T_Beam_S3_SUPREME_V3) -#define OLED_SDA 17 -#define OLED_SCL 18 -#define OLED_RST 16 -#define GPS_RX 8 -#define GPS_TX 9 -#define BUTTON_PIN 0 -#define RADIO_SCLK_PIN 12 -#define RADIO_MISO_PIN 13 -#define RADIO_MOSI_PIN 11 -#define RADIO_CS_PIN 10 -#define RADIO_DIO0_PIN -1 -#define RADIO_RST_PIN 5 -#define RADIO_DIO1_PIN 1 -#define RADIO_BUSY_PIN 4 +#define OLED_SDA 17 +#define OLED_SCL 18 +#define OLED_RST 16 +#define GPS_RX 8 +#define GPS_TX 9 +#define BUTTON_PIN 0 +#define RADIO_SCLK_PIN 12 +#define RADIO_MISO_PIN 13 +#define RADIO_MOSI_PIN 11 +#define RADIO_CS_PIN 10 +#define RADIO_DIO0_PIN -1 +#define RADIO_RST_PIN 5 +#define RADIO_DIO1_PIN 1 +#define RADIO_BUSY_PIN 4 #endif #if defined(HELTEC_V3_GPS) -#define OLED_SDA 17 -#define OLED_SCL 18 -#define OLED_RST 21 -#define GPS_RX 19 -#define GPS_TX 20 -#define BUTTON_PIN 0 -#define RADIO_SCLK_PIN 9 -#define RADIO_MISO_PIN 11 -#define RADIO_MOSI_PIN 10 -#define RADIO_CS_PIN 8 -#define RADIO_RST_PIN 12 -#define RADIO_DIO1_PIN 14 -#define RADIO_BUSY_PIN 13 +#define OLED_SDA 17 +#define OLED_SCL 18 +#define OLED_RST 21 +#define GPS_RX 19 +#define GPS_TX 20 +#define BUTTON_PIN 0 +#define RADIO_SCLK_PIN 9 +#define RADIO_MISO_PIN 11 +#define RADIO_MOSI_PIN 10 +#define RADIO_CS_PIN 8 +#define RADIO_RST_PIN 12 +#define RADIO_DIO1_PIN 14 +#define RADIO_BUSY_PIN 13 +#define BATTERY_PIN 1 +//#define ADC_EN_PIN 37 #endif diff --git a/src/power_utils.cpp b/src/power_utils.cpp index dfacca8..0ea2179 100644 --- a/src/power_utils.cpp +++ b/src/power_utils.cpp @@ -40,17 +40,18 @@ namespace POWER_Utils { double getBatteryVoltage() { #if defined(TTGO_T_Beam_V0_7) || defined(ESP32_DIY_LoRa_GPS) || defined(TTGO_T_LORA32_V2_1_GPS) || defined(TTGO_T_LORA32_V2_1_TNC) || defined(ESP32_DIY_1W_LoRa_GPS) - int adc_value; - double voltage; - adc_value = analogRead(35); - voltage = (adc_value * 3.3 ) / 4095.0; // the battery voltage is divided by 2 with two 100kOhm resistors and connected to ADC1 Channel 7 -> pin 35 + int adc_value = analogRead(35);; + double voltage = (adc_value * 3.3 ) / 4095.0; // the battery voltage is divided by 2 with two 100kOhm resistors and connected to ADC1 Channel 7 -> pin 35 return (2 * (voltage + 0.1)) * (1 + (lora32BatReadingCorr/100)); // 2 x voltage divider/+0.1 because ESP32 nonlinearity ~100mV ADC offset/extra correction #endif #if defined(TTGO_T_Beam_V1_0) || defined(TTGO_T_Beam_V1_0_SX1268) || defined(TTGO_T_Beam_V1_2) || defined(TTGO_T_Beam_V1_2_SX1262) || defined(TTGO_T_Beam_S3_SUPREME_V3) return PMU.getBattVoltage() / 1000.0; #endif #if defined(HELTEC_V3_GPS) - return 0; // Add measurement later + int adc_value = analogRead(BATTERY_PIN); + double voltage = (adc_value * 3.3) / 4095.0; + double inputDivider = (1.0 / (390.0 + 100.0)) * 100.0; // The voltage divider is a 390k + 100k resistor in series, 100k on the low side. + return (voltage / inputDivider) + 0.3; // Yes, this offset is excessive, but the ADC on the ESP32s3 is quite inaccurate and noisy. Adjust to own measurements. #endif } @@ -128,7 +129,7 @@ namespace POWER_Utils { if (!(rate_limit_check_battery++ % 60)) BatteryIsConnected = isBatteryConnected(); if (BatteryIsConnected) { - #if defined(TTGO_T_Beam_V0_7) || defined(ESP32_DIY_LoRa_GPS) || defined(TTGO_T_LORA32_V2_1_GPS) || defined(TTGO_T_LORA32_V2_1_TNC) || defined(TTGO_T_Beam_V1_0) || defined(TTGO_T_Beam_V1_0_SX1268) || defined(ESP32_DIY_1W_LoRa_GPS) + #if defined(TTGO_T_Beam_V0_7) || defined(ESP32_DIY_LoRa_GPS) || defined(TTGO_T_LORA32_V2_1_GPS) || defined(TTGO_T_LORA32_V2_1_TNC) || defined(TTGO_T_Beam_V1_0) || defined(TTGO_T_Beam_V1_0_SX1268) || defined(ESP32_DIY_1W_LoRa_GPS) || defined(HELTEC_V3_GPS) batteryVoltage = String(getBatteryVoltage(), 2); #endif #if defined(TTGO_T_Beam_V1_2) || defined(TTGO_T_Beam_V1_2_SX1262) || defined(TTGO_T_Beam_S3_SUPREME_V3) @@ -211,7 +212,7 @@ namespace POWER_Utils { bool begin(TwoWire &port) { #if defined(TTGO_T_Beam_V0_7) || defined(ESP32_DIY_LoRa_GPS) || defined(TTGO_T_LORA32_V2_1_GPS) || defined(TTGO_T_LORA32_V2_1_TNC) || defined(ESP32_DIY_1W_LoRa_GPS) || defined(HELTEC_V3_GPS) - return true; // nor powerManagment chip for this boards (only a few measure battery voltage). + return true; // no powerManagment chip for this boards (only a few measure battery voltage). #endif #if defined(TTGO_T_Beam_V1_0) || defined(TTGO_T_Beam_V1_0_SX1268) bool result = PMU.begin(Wire, AXP192_SLAVE_ADDRESS, I2C_SDA, I2C_SCL); @@ -326,10 +327,13 @@ namespace POWER_Utils { PMU.setChargerConstantCurr(XPOWERS_AXP2101_CHG_CUR_800MA); PMU.setSysPowerDownVoltage(2600); #endif + #ifdef HELTEC_V3_GPS + pinMode(BATTERY_PIN, INPUT); // This could or should be elsewhere, but this was my point of entry. + #endif } void lowerCpuFrequency() { - #if defined(TTGO_T_Beam_V1_0) || defined(TTGO_T_Beam_V1_0_SX1268) || defined(TTGO_T_Beam_V1_2) || defined(ESP32_DIY_LoRa_GPS) || defined(TTGO_T_LORA32_V2_1_GPS) || defined(TTGO_T_LORA32_V2_1_TNC) || defined(ESP32_DIY_1W_LoRa_GPS) || defined(TTGO_T_Beam_V1_2_SX1262) || defined(TTGO_T_Beam_S3_SUPREME_V3) + #if defined(TTGO_T_Beam_V1_0) || defined(TTGO_T_Beam_V1_0_SX1268) || defined(TTGO_T_Beam_V1_2) || defined(ESP32_DIY_LoRa_GPS) || defined(TTGO_T_LORA32_V2_1_GPS) || defined(TTGO_T_LORA32_V2_1_TNC) || defined(ESP32_DIY_1W_LoRa_GPS) || defined(TTGO_T_Beam_V1_2_SX1262) || defined(TTGO_T_Beam_S3_SUPREME_V3) || defined(HELTEC_V3_GPS) if (setCpuFrequencyMhz(80)) { logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Main", "CPU frequency set to 80MHz"); } else { diff --git a/src/station_utils.cpp b/src/station_utils.cpp index d8db25b..80e10c2 100644 --- a/src/station_utils.cpp +++ b/src/station_utils.cpp @@ -417,6 +417,9 @@ namespace STATION_Utils { #if defined(TTGO_T_Beam_V1_2) || defined(TTGO_T_Beam_V1_2_SX1262) packet += " Bat=" + String(batteryVoltage.toFloat()/1000,2) + "V (" + batteryChargeCurrent + "%)"; #endif + #if defined(HELTEC_V3_GPS) + packet += " Bat=" + String(batteryVoltage.toFloat(),2) + "V"; + #endif } show_display("<<< TX >>>", "", packet,100); LoRa_Utils::sendNewPacket(packet);