Compare commits

...

2 Commits

Author SHA1 Message Date
Ricardo Guzman (Richonguzman)
0eec028c5d update SENSOR BUS 2026-02-23 12:00:55 -03:00
Ricardo Guzman (Richonguzman)
c48dd15bd6 better ADC and VEXT control 2026-02-23 11:14:42 -03:00
19 changed files with 100 additions and 108 deletions

View File

@@ -1,17 +1,17 @@
/* Copyright (C) 2025 Ricardo Guzman - CA2RXU /* Copyright (C) 2025 Ricardo Guzman - CA2RXU
* *
* This file is part of LoRa APRS iGate. * This file is part of LoRa APRS iGate.
* *
* LoRa APRS iGate is free software: you can redistribute it and/or modify * LoRa APRS iGate is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* LoRa APRS iGate is distributed in the hope that it will be useful, * LoRa APRS iGate is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with LoRa APRS iGate. If not, see <https://www.gnu.org/licenses/>. * along with LoRa APRS iGate. If not, see <https://www.gnu.org/licenses/>.
*/ */
@@ -105,9 +105,9 @@ namespace BATTERY_Utils {
void getI2CVoltageSensorAddress() { void getI2CVoltageSensorAddress() {
uint8_t err, addr; uint8_t err, addr;
for(addr = 1; addr < 0x7F; addr++) { for(addr = 1; addr < 0x7F; addr++) {
#if defined(HELTEC_V3) || defined(HELTEC_V3_2) || defined(HELTEC_WSL_V3) || defined(HELTEC_WSL_V3_DISPLAY) #ifdef SENSOR_I2C_BUS
Wire1.beginTransmission(addr); SENSOR_I2C_BUS.beginTransmission(addr);
err = Wire1.endTransmission(); err = SENSOR_I2C_BUS.endTransmission();
#else #else
Wire.beginTransmission(addr); Wire.beginTransmission(addr);
err = Wire.endTransmission(); err = Wire.endTransmission();
@@ -145,7 +145,7 @@ namespace BATTERY_Utils {
} }
} }
float checkInternalVoltage() { float checkInternalVoltage() {
#if defined(HAS_AXP192) || defined(HAS_AXP2101) #if defined(HAS_AXP192) || defined(HAS_AXP2101)
if(POWER_Utils::isBatteryConnected()) { if(POWER_Utils::isBatteryConnected()) {
return POWER_Utils::getBatteryVoltage(); return POWER_Utils::getBatteryVoltage();
@@ -153,7 +153,7 @@ namespace BATTERY_Utils {
return 0.0; return 0.0;
} }
#else #else
#ifdef ADC_CTRL #ifdef ADC_CTRL
POWER_Utils::adc_ctrl_ON(); POWER_Utils::adc_ctrl_ON();
#endif #endif
@@ -177,7 +177,7 @@ namespace BATTERY_Utils {
#endif #endif
#endif #endif
#endif #endif
delay(3); delay(3);
} }
#ifdef ADC_CTRL #ifdef ADC_CTRL
@@ -241,7 +241,7 @@ namespace BATTERY_Utils {
#else #else
extVoltage = ((((sampleSum/100.0)* adcReadingTransformation) + readingCorrection) * voltageDividerTransformation) - multiplyCorrection; extVoltage = ((((sampleSum/100.0)* adcReadingTransformation) + readingCorrection) * voltageDividerTransformation) - multiplyCorrection;
#endif #endif
return extVoltage; // raw voltage without mapping return extVoltage; // raw voltage without mapping
// return mapVoltage(voltage, 5.05, 6.32, 4.5, 5.5); // mapped voltage // return mapVoltage(voltage, 5.05, 6.32, 4.5, 5.5); // mapped voltage

View File

@@ -49,40 +49,23 @@ extern bool stationCallsignIsValid;
namespace POWER_Utils { namespace POWER_Utils {
#ifdef VEXT_CTRL #ifdef ADC_CTRL_PIN
void vext_ctrl_ON() {
#if VEXT_CTRL_INVERTED == 1
digitalWrite(VEXT_CTRL, Config.digi.ecoMode == 1 ? HIGH : LOW);
#else
digitalWrite(VEXT_CTRL, Config.digi.ecoMode == 1 ? LOW : HIGH);
#endif
}
void vext_ctrl_OFF() {
#if VEXT_CTRL_INVERTED == 1
digitalWrite(VEXT_CTRL, Config.digi.ecoMode == 1 ? LOW : HIGH);
#else
digitalWrite(VEXT_CTRL, Config.digi.ecoMode == 1 ? HIGH : LOW);
#endif
}
#endif
#ifdef ADC_CTRL
void adc_ctrl_ON() { void adc_ctrl_ON() {
#if ADC_CTRL_INVERTED == 1 digitalWrite(ADC_CTRL_PIN, ADC_CTRL_ON_STATE);
digitalWrite(ADC_CTRL, LOW);
#else
digitalWrite(ADC_CTRL, HIGH);
#endif
} }
void adc_ctrl_OFF() { void adc_ctrl_OFF() {
#if ADC_CTRL_INVERTED == 1 digitalWrite(ADC_CTRL_PIN, !ADC_CTRL_ON_STATE);
digitalWrite(ADC_CTRL, HIGH); }
#else #endif
digitalWrite(ADC_CTRL, LOW);
#endif #ifdef VEXT_CTRL_PIN
void vext_ctrl_ON() {
digitalWrite(VEXT_CTRL_PIN, Config.digi.ecoMode == 1 ? !VEXT_CTRL_ON_STATE : VEXT_CTRL_ON_STATE);
}
void vext_ctrl_OFF() {
digitalWrite(VEXT_CTRL_PIN, Config.digi.ecoMode == 1 ? VEXT_CTRL_ON_STATE : !VEXT_CTRL_ON_STATE);
} }
#endif #endif
@@ -313,12 +296,8 @@ namespace POWER_Utils {
Wire.begin(OLED_SDA, OLED_SCL); Wire.begin(OLED_SDA, OLED_SCL);
#endif #endif
#ifdef USE_WIRE_WITH_BOARD_I2C_PINS #ifdef SENSOR_I2C_BUS
Wire.begin(BOARD_I2C_SDA, BOARD_I2C_SCL); SENSOR_I2C_BUS.begin(BOARD_I2C_SDA, BOARD_I2C_SCL);
#endif
#ifdef USE_WIRE1_WITH_BOARD_I2C_PINS
Wire1.begin(BOARD_I2C_SDA, BOARD_I2C_SCL);
#endif #endif
delay(1000); delay(1000);

View File

@@ -61,9 +61,9 @@ namespace WX_Utils {
void getWxModuleAddres() { void getWxModuleAddres() {
uint8_t err, addr; uint8_t err, addr;
for(addr = 1; addr < 0x7F; addr++) { for(addr = 1; addr < 0x7F; addr++) {
#if defined(HELTEC_V3) || defined(HELTEC_V3_2) || defined(HELTEC_WSL_V3) || defined(HELTEC_WSL_V3_DISPLAY) #ifdef SENSOR_I2C_BUS
Wire1.beginTransmission(addr); SENSOR_I2C_BUS.beginTransmission(addr);
err = Wire1.endTransmission(); err = SENSOR_I2C_BUS.endTransmission();
#else #else
Wire.beginTransmission(addr); Wire.beginTransmission(addr);
#ifdef LIGHTGATEWAY_PLUS_1_0 #ifdef LIGHTGATEWAY_PLUS_1_0

View File

@@ -31,7 +31,7 @@
#define GPIO_WAKEUP_PIN GPIO_SEL_38 #define GPIO_WAKEUP_PIN GPIO_SEL_38
// I2C // I2C
#define USE_WIRE_WITH_BOARD_I2C_PINS #define SENSOR_I2C_BUS Wire
#define BOARD_I2C_SDA 11 #define BOARD_I2C_SDA 11
#define BOARD_I2C_SCL 12 #define BOARD_I2C_SCL 12

View File

@@ -39,8 +39,8 @@
#define INTERNAL_LED_PIN 48 #define INTERNAL_LED_PIN 48
// I2C // I2C
#define USE_WIRE_WITH_OLED_PINS #define SENSOR_I2C_BUS Wire
#define OLED_SDA 5 #define BOARD_I2C_SDA 5
#define OLED_SCL 6 #define BOARD_I2C_SCL 6
#endif #endif

View File

@@ -48,7 +48,8 @@
// Aditional Config // Aditional Config
#define INTERNAL_LED_PIN 25 #define INTERNAL_LED_PIN 25
#define BATTERY_PIN 37 #define BATTERY_PIN 37
#define ADC_CTRL 21
#define ADC_CTRL_INVERTED 1 #define ADC_CTRL_PIN 21
#define ADC_CTRL_ON_STATE LOW
#endif #endif

View File

@@ -48,7 +48,8 @@
// Aditional Config // Aditional Config
#define INTERNAL_LED_PIN 25 #define INTERNAL_LED_PIN 25
#define BATTERY_PIN 37 #define BATTERY_PIN 37
#define ADC_CTRL 21 #define ADC_CTRL 21
#define ADC_CTRL_INVERTED 1 #define ADC_CTRL_ON_STATE LOW
#endif #endif

View File

@@ -33,7 +33,7 @@
#define GPIO_WAKEUP_PIN GPIO_SEL_14 #define GPIO_WAKEUP_PIN GPIO_SEL_14
// I2C // I2C
#define USE_WIRE1_WITH_BOARD_I2C_PINS #define SENSOR_I2C_BUS Wire1
#define BOARD_I2C_SDA 39 #define BOARD_I2C_SDA 39
#define BOARD_I2C_SCL 38 #define BOARD_I2C_SCL 38
@@ -50,9 +50,10 @@
// Aditional Config // Aditional Config
#define INTERNAL_LED_PIN 45 #define INTERNAL_LED_PIN 45
#define BATTERY_PIN 7 #define BATTERY_PIN 7
#define ADC_CTRL 46
#define ADC_CTRL_INVERTED 0 #define ADC_CTRL_PIN 46
#define VEXT_CTRL 18 #define ADC_CTRL_ON_STATE HIGH
#define VEXT_CTRL_INVERTED 0 #define VEXT_CTRL_PIN 18
#define VEXT_CTRL_ON_STATE HIGH
#endif #endif

View File

@@ -34,7 +34,7 @@
// I2C // I2C
#define USE_WIRE_WITH_OLED_PINS #define USE_WIRE_WITH_OLED_PINS
#define USE_WIRE1_WITH_BOARD_I2C_PINS #define SENSOR_I2C_BUS Wire1
#define BOARD_I2C_SDA 41 #define BOARD_I2C_SDA 41
#define BOARD_I2C_SCL 42 #define BOARD_I2C_SCL 42
@@ -53,9 +53,10 @@
// Aditional Config // Aditional Config
#define INTERNAL_LED_PIN 35 #define INTERNAL_LED_PIN 35
#define BATTERY_PIN 1 #define BATTERY_PIN 1
#define VEXT_CTRL 36
#define VEXT_CTRL_INVERTED 0 #define ADC_CTRL_PIN 37
#define ADC_CTRL 37 #define ADC_CTRL_ON_STATE LOW
#define ADC_CTRL_INVERTED 1 #define VEXT_CTRL_PIN 36
#define VEXT_CTRL_ON_STATE HIGH
#endif #endif

View File

@@ -34,7 +34,7 @@
// I2C // I2C
#define USE_WIRE_WITH_OLED_PINS #define USE_WIRE_WITH_OLED_PINS
#define USE_WIRE1_WITH_BOARD_I2C_PINS #define SENSOR_I2C_BUS Wire1
#define BOARD_I2C_SDA 41 #define BOARD_I2C_SDA 41
#define BOARD_I2C_SCL 42 #define BOARD_I2C_SCL 42
@@ -53,9 +53,10 @@
// Aditional Config // Aditional Config
#define INTERNAL_LED_PIN 35 #define INTERNAL_LED_PIN 35
#define BATTERY_PIN 1 #define BATTERY_PIN 1
#define VEXT_CTRL 36
#define VEXT_CTRL_INVERTED 1 #define ADC_CTRL_PIN 37
#define ADC_CTRL 37 #define ADC_CTRL_ON_STATE HIGH
#define ADC_CTRL_INVERTED 0 #define VEXT_CTRL_PIN 36
#define VEXT_CTRL_ON_STATE LOW
#endif #endif

View File

@@ -34,7 +34,7 @@
// I2C // I2C
#define USE_WIRE_WITH_OLED_PINS #define USE_WIRE_WITH_OLED_PINS
#define USE_WIRE1_WITH_BOARD_I2C_PINS #define SENSOR_I2C_BUS Wire1
#define BOARD_I2C_SDA 41 #define BOARD_I2C_SDA 41
#define BOARD_I2C_SCL 42 #define BOARD_I2C_SCL 42
@@ -53,10 +53,11 @@
// Aditional Config // Aditional Config
#define INTERNAL_LED_PIN 35 #define INTERNAL_LED_PIN 35
#define BATTERY_PIN 1 #define BATTERY_PIN 1
#define VEXT_CTRL 36
#define VEXT_CTRL_INVERTED 1 #define ADC_CTRL_PIN 37
#define ADC_CTRL 37 #define ADC_CTRL_ON_STATE HIGH
#define ADC_CTRL_INVERTED 0 #define VEXT_CTRL_PIN 36
#define VEXT_CTRL_ON_STATE LOW
// GPS ?? // GPS ??
#define VGNS_CTRL 34 // cambiar nombre para prender GPS ? #define VGNS_CTRL 34 // cambiar nombre para prender GPS ?

View File

@@ -33,7 +33,7 @@
#define GPIO_WAKEUP_PIN GPIO_SEL_14 #define GPIO_WAKEUP_PIN GPIO_SEL_14
// I2C // I2C
#define USE_WIRE1_WITH_BOARD_I2C_PINS #define SENSOR_I2C_BUS Wire1
#define BOARD_I2C_SDA 37 #define BOARD_I2C_SDA 37
#define BOARD_I2C_SCL 36 #define BOARD_I2C_SCL 36
@@ -50,9 +50,10 @@
// Aditional Config // Aditional Config
#define INTERNAL_LED_PIN 18 #define INTERNAL_LED_PIN 18
#define BATTERY_PIN 20 #define BATTERY_PIN 20
#define ADC_CTRL 19
#define ADC_CTRL_INVERTED 1 #define ADC_CTRL_PIN 19
#define VEXT_CTRL 45 #define ADC_CTRL_ON_STATE LOW
#define VEXT_CTRL_INVERTED 1 #define VEXT_CTRL_PIN 45
#define VEXT_CTRL_ON_STATE LOW
#endif #endif

View File

@@ -33,7 +33,7 @@
#define GPIO_WAKEUP_PIN GPIO_SEL_14 #define GPIO_WAKEUP_PIN GPIO_SEL_14
// I2C // I2C
#define USE_WIRE1_WITH_BOARD_I2C_PINS #define SENSOR_I2C_BUS Wire1
#define BOARD_I2C_SDA 37 #define BOARD_I2C_SDA 37
#define BOARD_I2C_SCL 36 #define BOARD_I2C_SCL 36
@@ -50,9 +50,10 @@
// Aditional Config // Aditional Config
#define INTERNAL_LED_PIN 18 #define INTERNAL_LED_PIN 18
#define BATTERY_PIN 20 #define BATTERY_PIN 20
#define ADC_CTRL 19
#define ADC_CTRL_INVERTED 1 #define ADC_CTRL_PIN 19
#define VEXT_CTRL 45 #define ADC_CTRL_ON_STATE LOW
#define VEXT_CTRL_INVERTED 1 #define VEXT_CTRL_PIN 45
#define VEXT_CTRL_ON_STATE LOW
#endif #endif

View File

@@ -50,9 +50,11 @@
// Aditional Config // Aditional Config
#define INTERNAL_LED_PIN 35 #define INTERNAL_LED_PIN 35
#define BATTERY_PIN 1 #define BATTERY_PIN 1
#define ADC_CTRL 37
#define VEXT_CTRL 36 #define ADC_CTRL_PIN 37
#define VEXT_CTRL_INVERTED 1 #define ADC_CTRL_ON_STATE LOW
#define VEXT_CTRL_PIN 36
#define VEXT_CTRL_ON_STATE LOW
#define BOARD_I2C_SDA 41 #define BOARD_I2C_SDA 41
#define BOARD_I2C_SCL 42 #define BOARD_I2C_SCL 42

View File

@@ -33,16 +33,17 @@
#define GPIO_WAKEUP_PIN GPIO_SEL_14 #define GPIO_WAKEUP_PIN GPIO_SEL_14
// I2C // I2C
#define USE_WIRE1_WITH_BOARD_I2C_PINS #define SENSOR_I2C_BUS Wire1
#define BOARD_I2C_SDA 41 #define BOARD_I2C_SDA 41
#define BOARD_I2C_SCL 42 #define BOARD_I2C_SCL 42
// Aditional Config // Aditional Config
#define INTERNAL_LED_PIN 35 #define INTERNAL_LED_PIN 35
#define BATTERY_PIN 1 #define BATTERY_PIN 1
#define ADC_CTRL 37
#define ADC_CTRL_INVERTED 1 #define ADC_CTRL_PIN 37
#define VEXT_CTRL 36 #define ADC_CTRL_ON_STATE LOW
#define VEXT_CTRL_INVERTED 1 #define VEXT_CTRL_PIN 36
#define VEXT_CTRL_ON_STATE LOW
#endif #endif

View File

@@ -33,7 +33,7 @@
#define GPIO_WAKEUP_PIN GPIO_SEL_14 #define GPIO_WAKEUP_PIN GPIO_SEL_14
// I2C // I2C
#define USE_WIRE1_WITH_BOARD_I2C_PINS #define SENSOR_I2C_BUS Wire1
#define BOARD_I2C_SDA 41 #define BOARD_I2C_SDA 41
#define BOARD_I2C_SCL 42 #define BOARD_I2C_SCL 42
@@ -44,9 +44,10 @@
// Aditional Config // Aditional Config
#define INTERNAL_LED_PIN 35 #define INTERNAL_LED_PIN 35
#define BATTERY_PIN 1 #define BATTERY_PIN 1
#define ADC_CTRL 37
#define ADC_CTRL_INVERTED 1 #define ADC_CTRL_PIN 37
#define VEXT_CTRL 36 #define ADC_CTRL_ON_STATE LOW
#define VEXT_CTRL_INVERTED 1 #define VEXT_CTRL_PIN 36
#define VEXT_CTRL_ON_STATE LOW
#endif #endif

View File

@@ -33,7 +33,7 @@
#define GPIO_WAKEUP_PIN GPIO_SEL_14 #define GPIO_WAKEUP_PIN GPIO_SEL_14
// I2C // I2C
#define USE_WIRE_WITH_BOARD_I2C_PINS #define SENSOR_I2C_BUS Wire
#define BOARD_I2C_SDA 7 #define BOARD_I2C_SDA 7
#define BOARD_I2C_SCL 6 #define BOARD_I2C_SCL 6
@@ -44,10 +44,11 @@
// Aditional Config // Aditional Config
#define INTERNAL_LED_PIN 18 #define INTERNAL_LED_PIN 18
#define BATTERY_PIN 1 #define BATTERY_PIN 1
#define VEXT_CTRL 3 // To turn on GPS and TFT
#define VEXT_CTRL_INVERTED 0 #define ADC_CTRL_PIN 2 // HELTEC Wireless Tracker ADC_CTRL = HIGH powers the voltage divider to read BatteryPin. Only on V05 = V1.1
#define ADC_CTRL 2 // HELTEC Wireless Tracker ADC_CTRL = HIGH powers the voltage divider to read BatteryPin. Only on V05 = V1.1 #define ADC_CTRL_ON_STATE HIGH
#define ADC_CTRL_INVERTED 0 #define VEXT_CTRL_PIN 3 // To turn on GPS and TFT
#define VEXT_CTRL_ON_STATE HIGH
// GPS // GPS
#define HAS_GPS #define HAS_GPS

View File

@@ -33,7 +33,7 @@
#define GPIO_WAKEUP_PIN GPIO_SEL_45 #define GPIO_WAKEUP_PIN GPIO_SEL_45
// I2C // I2C
#define USE_WIRE_WITH_BOARD_I2C_PINS #define SENSOR_I2C_BUS Wire
#define BOARD_I2C_SDA 18 #define BOARD_I2C_SDA 18
#define BOARD_I2C_SCL 8 #define BOARD_I2C_SCL 8

View File

@@ -33,7 +33,7 @@
#define GPIO_WAKEUP_PIN GPIO_SEL_45 #define GPIO_WAKEUP_PIN GPIO_SEL_45
// I2C // I2C
#define USE_WIRE_WITH_BOARD_I2C_PINS #define SENSOR_I2C_BUS Wire
#define BOARD_I2C_SDA 18 #define BOARD_I2C_SDA 18
#define BOARD_I2C_SCL 8 #define BOARD_I2C_SCL 8