From 459752c1ef96c7952f100be09597c75ecb1f178d Mon Sep 17 00:00:00 2001 From: Brenton Poke Date: Sun, 29 Sep 2024 00:55:20 -0400 Subject: [PATCH 1/5] using XPowersLib Signed-off-by: Brenton Poke --- .../TBeam-SX126/TBeam-AXP-Example.ino | 114 +++++++++--------- 1 file changed, 56 insertions(+), 58 deletions(-) diff --git a/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX126/TBeam-AXP-Example.ino b/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX126/TBeam-AXP-Example.ino index a7ba0ba..6ebddc3 100644 --- a/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX126/TBeam-AXP-Example.ino +++ b/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX126/TBeam-AXP-Example.ino @@ -21,10 +21,12 @@ // AXP setup #include -#include +#define XPOWERS_CHIP_AXP192 +#include -AXP20X_Class axp; +XPowersPMU axp; +bool runSensor(void *); const uint8_t i2c_sda = 21; const uint8_t i2c_scl = 22; @@ -33,61 +35,57 @@ DuckDisplay* display = NULL; // Set device ID between "" -String deviceId = "MAMA001"; MamaDuck duck; auto timer = timer_create_default(); const int INTERVAL_MS = 60000; -char message[32]; +char message[32]; int counter = 1; void setup() { - // We are using a hardcoded device id here, but it should be retrieved or - // given during the device provisioning then converted to a byte vector to - // setup the duck NOTE: The Device ID must be exactly 8 bytes otherwise it - // will get rejected - std::string deviceId("MAMA0001"); - std::vector devId; - devId.insert(devId.end(), deviceId.begin(), deviceId.end()); - - // Use the default setup provided by the SDK - duck.setupWithDefaults(devId); - Serial.println("MAMA-DUCK...READY!"); - - // initialize the timer. The timer thread runs separately from the main loop - // and will trigger sending a counter message. - timer.every(INTERVAL_MS, runSensor); - - Wire.begin(i2c_sda, i2c_scl); - - int ret = axp.begin(Wire, AXP192_SLAVE_ADDRESS); - - if (ret == AXP_FAIL) { - Serial.println("AXP Power begin failed"); - while (1); - } + // We are using a hardcoded device id here, but it should be retrieved or + // given during the device provisioning then converted to a byte vector to + // setup the duck NOTE: The Device ID must be exactly 8 bytes otherwise it + // will get rejected + std::string deviceId("MAMA0001"); + std::vector devId; + devId.insert(devId.end(), deviceId.begin(), deviceId.end()); + + // Use the default setup provided by the SDK + duck.setupWithDefaults(devId); + Serial.println("MAMA-DUCK...READY!"); + + // initialize the timer. The timer thread runs separately from the main loop + // and will trigger sending a counter message. + timer.every(INTERVAL_MS, runSensor); + + Wire.begin(i2c_sda, i2c_scl); + + int ret = axp.begin(Wire, AXP192_SLAVE_ADDRESS,i2c_sda,i2c_scl); + + axp.enableIRQ(XPOWERS_AXP192_BAT_CHG_DONE_IRQ | XPOWERS_AXP192_BAT_CHG_START_IRQ); } void loop() { - timer.tick(); - // Use the default run(). The Mama duck is designed to also forward data it receives - // from other ducks, across the network. It has a basic routing mechanism built-in - // to prevent messages from hoping endlessly. - duck.run(); + timer.tick(); + // Use the default run(). The Mama duck is designed to also forward data it receives + // from other ducks, across the network. It has a basic routing mechanism built-in + // to prevent messages from hoping endlessly. + duck.run(); } bool runSensor(void *) { - - -float isCharging = axp.isChargeing(); -boolean isFullyCharged = axp.isChargingDoneIRQ(); -float batteryVoltage = axp.getBattVoltage(); -float batteryDischarge = axp.getAcinCurrent(); -float getTemp = axp.getTemp(); -int battPercentage = axp.getBattPercentage(); - + + + float isCharging = axp.isCharging(); + boolean isFullyCharged = axp.isBatChagerDoneIrq(); + float batteryVoltage = axp.getBattVoltage(); + float batteryDischarge = axp.getAcinCurrent(); + float getTemp = axp.getTemperature(); + int battPercentage = axp.getBatteryPercent(); + Serial.println("--- T-BEAM Power Information ---"); Serial.print("Duck charging (1 = Yes): "); Serial.println(isCharging); @@ -96,24 +94,24 @@ int battPercentage = axp.getBattPercentage(); Serial.print("Battery Voltage: "); Serial.println(batteryVoltage); Serial.print("Battery Discharge: "); - Serial.println(batteryDischarge); + Serial.println(batteryDischarge); Serial.print("Board Temperature: "); Serial.println(getTemp); Serial.print("battery Percentage: "); Serial.println(battPercentage); - - - String sensorVal = - "Charging: " + - String(isCharging) ; - " BattFull: " + - String(isFullyCharged)+ - " Voltage " + - String(batteryVoltage) ; - " Temp: " + - String(getTemp); - - - duck.sendData(topics::sensor, sensorVal); - return true; + + + std::string sensorVal = + "Charging: "; + sensorVal.append(isCharging ? "Yes" : "No") + .append(" BattFull: ") + .append(isFullyCharged ? "Yes" : "No") + .append(" Voltage: ") + .append(std::to_string(batteryVoltage)) + .append(" Temp: ") + .append(std::to_string(getTemp)); + + + duck.sendData(topics::sensor, sensorVal); + return true; } From 0a3626aed860e05351523218556ea8a1770842da Mon Sep 17 00:00:00 2001 From: Taraqur Date: Sun, 20 Oct 2024 23:00:40 -0400 Subject: [PATCH 2/5] made some tweaks Signed-off-by: Taraqur --- .gitignore | 6 +- .../TBeam-SX126/TBeam-AXP-Example.ino | 6 +- .../TBeam-SX126/platformio.ini | 147 ++++++++++++++++-- .../TBeam-SX127/platformio.ini | 146 +++++++++++++++-- 4 files changed, 277 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index 496ee2c..e25283f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ -.DS_Store \ No newline at end of file +.DS_Store +.pio +.vs_code +.vscode +secrets.h \ No newline at end of file diff --git a/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX126/TBeam-AXP-Example.ino b/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX126/TBeam-AXP-Example.ino index 6ebddc3..2cf34ed 100644 --- a/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX126/TBeam-AXP-Example.ino +++ b/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX126/TBeam-AXP-Example.ino @@ -38,7 +38,7 @@ DuckDisplay* display = NULL; MamaDuck duck; auto timer = timer_create_default(); -const int INTERVAL_MS = 60000; +const int INTERVAL_MS = 10000; char message[32]; int counter = 1; @@ -79,8 +79,8 @@ void loop() { bool runSensor(void *) { - float isCharging = axp.isCharging(); - boolean isFullyCharged = axp.isBatChagerDoneIrq(); + int isCharging = axp.isCharging(); + boolean isFullyCharged = axp.isBatChargeDoneIrq(); float batteryVoltage = axp.getBattVoltage(); float batteryDischarge = axp.getAcinCurrent(); float getTemp = axp.getTemperature(); diff --git a/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX126/platformio.ini b/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX126/platformio.ini index 4305db4..351b77e 100644 --- a/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX126/platformio.ini +++ b/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX126/platformio.ini @@ -8,19 +8,142 @@ ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html + +; Some useful platformio CLI commands to build and uplaod the example code. + +; using the released CDP library +; platformio run -e prod_heltec_wifi_lora_32_V3 -t upload + +; using the local CDP library +; platformio run -e local_heltec_wifi_lora_32_V3 -t upload + + [platformio] -src_dir = . + src_dir = . +;; uncomment the line below to build for your board + + default_envs = local_heltec_wifi_lora_32_V3 +; default_envs = local_heltec_wifi_lora_32_V3 +; default_envs = local_heltec_wifi_lora_32_V2 +; default_envs = local_ttgo_t_beam + +; default_envs = prod_heltec_wifi_lora_32_V3 +; default_envs = prod_heltec_wifi_lora_32_V2 +; default_envs = prod_ttgo_t_beam + +description = MamaDuck CDP examples + +[env] + lib_deps = + WIRE + SPI + contrem/arduino-timer@^3.0.1 + lewisxhe/XPowersLib + +[env:esp32] + lib_deps = + +[env:local_cdp] + lib_deps = symlink://../../../ ; local CDP library + +[env:release_cdp] + lib_deps = + https://github.com/ClusterDuck-Protocol/ClusterDuck-Protocol/archive/refs/tags/4.2.0.zip + + +; ------------------------------------------------------------------------------------------------------- +; ---- PRODUCTION ENVIRONMENTS +; ------------------------------------------------------------------------------------------------------- + + +; PRODUCTION HELTEC_WIFI_LORA_32_V2 +[env:prod_heltec_wifi_lora_32_V2] + platform = espressif32 + board = heltec_wifi_lora_32_V2 + framework = arduino + monitor_speed = 115200 + monitor_filters = time + lib_deps = + ${env:esp32.lib_deps} + ${env:release_cdp.lib_deps} + +; PRODUCTION HELTEC_WIFI_LORA_32_V3 +[env:prod_heltec_wifi_lora_32_V3] + platform = espressif32 + board = heltec_wifi_lora_32_V3 + framework = arduino + monitor_speed = 115200 + monitor_filters = time + lib_deps = + ${env:esp32.lib_deps} + ${env:release_cdp.lib_deps} + +; PRODUCTION LILYGO_T_BEAM_SX1262 +[env:prod_lilygo_t_beam_sx1262] + platform = espressif32 + board = ttgo-t-beam + framework = arduino + monitor_speed = 115200 + monitor_filters = time + lib_deps = + ${env:esp32.lib_deps} + ${env:release_cdp.lib_deps} + lewisxhe/XPowersLib + +; PRODUCTION TTGO_LORA32_V1 +[env:prod_ttgo_lora32_v1] + platform = espressif32 + board = ttgo-lora32-v1 + framework = arduino + monitor_speed = 115200 + monitor_filters = time + lib_deps = + ${env:esp32.lib_deps} + ${env:release_cdp.lib_deps} +; ------------------------------------------------------------------------------------------------------- +; ---- LOCAL ENVIRONMENTS +; ------------------------------------------------------------------------------------------------------- -[env:ttgo-t-beam] -platform = espressif32 -board = ttgo-t-beam -framework = arduino -monitor_speed = 115200 -monitor_filters = time +; LOCAL HELTEC_WIFI_LORA_32_V2 +[env:local_heltec_wifi_lora_32_V2] + platform = espressif32 + board = heltec_wifi_lora_32_V2 + framework = arduino + monitor_speed = 115200 + monitor_filters = time + lib_deps = + ${env:esp32.lib_deps} + ${env:local_cdp.lib_deps} + +; LOCAL HELTEC_WIFI_LORA_32_V3 +[env:local_heltec_wifi_lora_32_V3] + platform = espressif32 + board = heltec_wifi_lora_32_V3 + framework = arduino + monitor_speed = 115200 + monitor_filters = time + lib_deps = + ${env:esp32.lib_deps} + ${env:local_cdp.lib_deps} -lib_deps = - https://github.com/Call-for-Code/ClusterDuck-Protocol - lewisxhe/AXP202X_Library +; LOCAL LILYGO_T_BEAM_SX1262 +[env:local_lilygo_t_beam_sx1262] + platform = espressif32 + board = ttgo-t-beam + framework = arduino + monitor_speed = 115200 + monitor_filters = time + lib_deps = + ${env:esp32.lib_deps} + ${env:local_cdp.lib_deps} -; uncomment for OTA update -; upload_port = duck.local +; LOCAL TTGO_LORA32_V1 +[env:local_ttgo_lora32_v1] + platform = espressif32 + board = ttgo-lora32-v1 + framework = arduino + monitor_speed = 115200 + monitor_filters = time + lib_deps = + ${env:esp32.lib_deps} + ${env:local_cdp.lib_deps} \ No newline at end of file diff --git a/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX127/platformio.ini b/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX127/platformio.ini index 4305db4..a89816b 100644 --- a/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX127/platformio.ini +++ b/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX127/platformio.ini @@ -8,19 +8,141 @@ ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html + +; Some useful platformio CLI commands to build and uplaod the example code. + +; using the released CDP library +; platformio run -e prod_heltec_wifi_lora_32_V3 -t upload + +; using the local CDP library +; platformio run -e local_heltec_wifi_lora_32_V3 -t upload + + [platformio] -src_dir = . + src_dir = . +;; uncomment the line below to build for your board + + default_envs = local_heltec_wifi_lora_32_V3 +; default_envs = local_heltec_wifi_lora_32_V3 +; default_envs = local_heltec_wifi_lora_32_V2 +; default_envs = local_ttgo_t_beam + +; default_envs = prod_heltec_wifi_lora_32_V3 +; default_envs = prod_heltec_wifi_lora_32_V2 +; default_envs = prod_ttgo_t_beam + +description = MamaDuck CDP examples + +[env] + lib_deps = + WIRE + SPI + contrem/arduino-timer@^3.0.1 + bblanchon/ArduinoJson@^7.0.3 + +[env:esp32] + lib_deps = + +[env:local_cdp] + lib_deps = symlink://../../../ ; local CDP library + +[env:release_cdp] + lib_deps = + https://github.com/ClusterDuck-Protocol/ClusterDuck-Protocol/archive/refs/tags/4.2.0.zip + + +; ------------------------------------------------------------------------------------------------------- +; ---- PRODUCTION ENVIRONMENTS +; ------------------------------------------------------------------------------------------------------- + + +; PRODUCTION HELTEC_WIFI_LORA_32_V2 +[env:prod_heltec_wifi_lora_32_V2] + platform = espressif32 + board = heltec_wifi_lora_32_V2 + framework = arduino + monitor_speed = 115200 + monitor_filters = time + lib_deps = + ${env:esp32.lib_deps} + ${env:release_cdp.lib_deps} + +; PRODUCTION HELTEC_WIFI_LORA_32_V3 +[env:prod_heltec_wifi_lora_32_V3] + platform = espressif32 + board = heltec_wifi_lora_32_V3 + framework = arduino + monitor_speed = 115200 + monitor_filters = time + lib_deps = + ${env:esp32.lib_deps} + ${env:release_cdp.lib_deps} + +; PRODUCTION LILYGO_T_BEAM_SX1262 +[env:prod_lilygo_t_beam_sx1262] + platform = espressif32 + board = ttgo-t-beam + framework = arduino + monitor_speed = 115200 + monitor_filters = time + lib_deps = + ${env:esp32.lib_deps} + ${env:release_cdp.lib_deps} + +; PRODUCTION TTGO_LORA32_V1 +[env:prod_ttgo_lora32_v1] + platform = espressif32 + board = ttgo-lora32-v1 + framework = arduino + monitor_speed = 115200 + monitor_filters = time + lib_deps = + ${env:esp32.lib_deps} + ${env:release_cdp.lib_deps} +; ------------------------------------------------------------------------------------------------------- +; ---- LOCAL ENVIRONMENTS +; ------------------------------------------------------------------------------------------------------- -[env:ttgo-t-beam] -platform = espressif32 -board = ttgo-t-beam -framework = arduino -monitor_speed = 115200 -monitor_filters = time +; LOCAL HELTEC_WIFI_LORA_32_V2 +[env:local_heltec_wifi_lora_32_V2] + platform = espressif32 + board = heltec_wifi_lora_32_V2 + framework = arduino + monitor_speed = 115200 + monitor_filters = time + lib_deps = + ${env:esp32.lib_deps} + ${env:local_cdp.lib_deps} + +; LOCAL HELTEC_WIFI_LORA_32_V3 +[env:local_heltec_wifi_lora_32_V3] + platform = espressif32 + board = heltec_wifi_lora_32_V3 + framework = arduino + monitor_speed = 115200 + monitor_filters = time + lib_deps = + ${env:esp32.lib_deps} + ${env:local_cdp.lib_deps} -lib_deps = - https://github.com/Call-for-Code/ClusterDuck-Protocol - lewisxhe/AXP202X_Library +; LOCAL LILYGO_T_BEAM_SX1262 +[env:local_lilygo_t_beam_sx1262] + platform = espressif32 + board = ttgo-t-beam + framework = arduino + monitor_speed = 115200 + monitor_filters = time + lib_deps = + ${env:esp32.lib_deps} + ${env:local_cdp.lib_deps} -; uncomment for OTA update -; upload_port = duck.local +; LOCAL TTGO_LORA32_V1 +[env:local_ttgo_lora32_v1] + platform = espressif32 + board = ttgo-lora32-v1 + framework = arduino + monitor_speed = 115200 + monitor_filters = time + lib_deps = + ${env:esp32.lib_deps} + ${env:local_cdp.lib_deps} \ No newline at end of file From 353e8b18e26afe844632aafe9704116dea9725a2 Mon Sep 17 00:00:00 2001 From: Brenton Poke Date: Sat, 8 Feb 2025 17:54:34 -0500 Subject: [PATCH 3/5] these should be working now --- .../TBeam-SX126/TBeam-AXP-Example.ino | 12 +- .../TBeam-SX126/platformio.ini | 10 +- .../TBeam-SX127/TBeam-AXP-Example.ino | 118 ++++++++++++++---- .../TBeam-SX127/platformio.ini | 12 +- 4 files changed, 115 insertions(+), 37 deletions(-) diff --git a/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX126/TBeam-AXP-Example.ino b/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX126/TBeam-AXP-Example.ino index 6ebddc3..76bfd1a 100644 --- a/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX126/TBeam-AXP-Example.ino +++ b/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX126/TBeam-AXP-Example.ino @@ -38,7 +38,7 @@ DuckDisplay* display = NULL; MamaDuck duck; auto timer = timer_create_default(); -const int INTERVAL_MS = 60000; +const int INTERVAL_MS = 20000; char message[32]; int counter = 1; @@ -52,8 +52,10 @@ void setup() { devId.insert(devId.end(), deviceId.begin(), deviceId.end()); // Use the default setup provided by the SDK - duck.setupWithDefaults(devId); - Serial.println("MAMA-DUCK...READY!"); + duck.setDeviceId(deviceId); + // initialize the serial component with the hardware supported baudrate + duck.setupSerial(115200); + duck.setupRadio(); // initialize the timer. The timer thread runs separately from the main loop // and will trigger sending a counter message. @@ -79,8 +81,8 @@ void loop() { bool runSensor(void *) { - float isCharging = axp.isCharging(); - boolean isFullyCharged = axp.isBatChagerDoneIrq(); + bool isCharging = axp.isCharging(); + bool isFullyCharged = axp.isBatChargeDoneIrq(); float batteryVoltage = axp.getBattVoltage(); float batteryDischarge = axp.getAcinCurrent(); float getTemp = axp.getTemperature(); diff --git a/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX126/platformio.ini b/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX126/platformio.ini index 4305db4..516593d 100644 --- a/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX126/platformio.ini +++ b/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX126/platformio.ini @@ -18,9 +18,15 @@ framework = arduino monitor_speed = 115200 monitor_filters = time +build_flags = + -std=c++2a + -Wno-format + -DCDP_LOG_DEBUG + -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE lib_deps = - https://github.com/Call-for-Code/ClusterDuck-Protocol - lewisxhe/AXP202X_Library + ArduinoOTA + https://github.com/ClusterDuck-Protocol/ClusterDuck-Protocol.git + lewisxhe/XPowersLib@^0.2.7 ; uncomment for OTA update ; upload_port = duck.local diff --git a/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX127/TBeam-AXP-Example.ino b/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX127/TBeam-AXP-Example.ino index a7ba0ba..e302f11 100644 --- a/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX127/TBeam-AXP-Example.ino +++ b/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX127/TBeam-AXP-Example.ino @@ -21,9 +21,14 @@ // AXP setup #include -#include +#define XPOWERS_CHIP_AXP192 +#define ARDUINO_TTGO_LoRa32_V1 +#include -AXP20X_Class axp; +XPowersPMU axp; + +#define XPOWERS_AXP192_BAT_CHG_DONE_IRQ 0x01 +#define XPOWERS_AXP192_BAT_CHG_START_IRQ 0x02 const uint8_t i2c_sda = 21; const uint8_t i2c_scl = 22; @@ -31,13 +36,20 @@ const uint8_t i2c_scl = 22; DuckDisplay* display = NULL; +//#define LORA_FREQ 915.0 // Frequency Range. Set for US Region 915.0Mhz +//#define LORA_TXPOWER 20 // Transmit Power +//// LORA HELTEC PIN CONFIG +//#define LORA_CS_PIN 18 +//#define LORA_DIO0_PIN 26 +//#define LORA_DIO1_PIN -1 // unused +//#define LORA_RST_PIN 14 // Set device ID between "" String deviceId = "MAMA001"; MamaDuck duck; auto timer = timer_create_default(); -const int INTERVAL_MS = 60000; +const int INTERVAL_MS = 20000; char message[32]; int counter = 1; @@ -47,11 +59,13 @@ void setup() { // setup the duck NOTE: The Device ID must be exactly 8 bytes otherwise it // will get rejected std::string deviceId("MAMA0001"); - std::vector devId; - devId.insert(devId.end(), deviceId.begin(), deviceId.end()); // Use the default setup provided by the SDK - duck.setupWithDefaults(devId); + duck.setDeviceId(deviceId); + // initialize the serial component with the hardware supported baudrate + duck.setupSerial(115200); + duck.setupRadio(); + // duck.setupRadio(LORA_FREQ, LORA_CS_PIN, LORA_RST_PIN, LORA_DIO0_PIN, LORA_DIO1_PIN, LORA_TXPOWER); Serial.println("MAMA-DUCK...READY!"); // initialize the timer. The timer thread runs separately from the main loop @@ -60,12 +74,61 @@ void setup() { Wire.begin(i2c_sda, i2c_scl); - int ret = axp.begin(Wire, AXP192_SLAVE_ADDRESS); + int ret = axp.begin(Wire, 0x34,i2c_sda,i2c_scl); + axp.setSysPowerDownVoltage(3000); + + // Set the minimum common working voltage of the PMU VBUS input, + // below this value will turn off the PMU + axp.setVbusVoltageLimit(XPOWERS_AXP192_VBUS_VOL_LIM_4V5); + + // Turn off USB input current limit + axp.setVbusCurrentLimit(XPOWERS_AXP192_VBUS_CUR_LIM_OFF); + + // DC1 700~3500mV, IMAX=1.2A + axp.setDC1Voltage(3300); + Serial.printf("DC1 :%s Voltage:%u mV \n", axp.isEnableDC1() ? "+" : "-", axp.getDC1Voltage()); + + // DC2 700~2750 mV, IMAX=1.6A; + axp.setDC2Voltage(700); + Serial.printf("DC2 :%s Voltage:%u mV \n", axp.isEnableDC2() ? "+" : "-", axp.getDC2Voltage()); + + // DC3 700~3500 mV,IMAX=0.7A; + axp.setDC3Voltage(3300); + Serial.printf("DC3 :%s Voltage:%u mV \n", axp.isEnableDC3() ? "+" : "-", axp.getDC3Voltage()); + + + //LDO2 1800~3300 mV, 100mV/step, IMAX=200mA + axp.setLDO2Voltage(1800); + + //LDO3 1800~3300 mV, 100mV/step, IMAX=200mA + axp.setLDO3Voltage(1800); + + //LDOio 1800~3300 mV, 100mV/step, IMAX=50mA + axp.setLDOioVoltage(3300); - if (ret == AXP_FAIL) { - Serial.println("AXP Power begin failed"); - while (1); - } + axp.enableDC2(); + axp.enableDC3(); + axp.enableLDO2(); + axp.enableLDO3(); + axp.enableLDOio(); + + axp.enableTemperatureMeasure(); + axp.enableBattDetection(); + axp.enableVbusVoltageMeasure(); + axp.enableBattVoltageMeasure(); + axp.enableSystemVoltageMeasure(); + + axp.clearIrqStatus(); + + axp.enableIRQ( + XPOWERS_AXP192_BAT_INSERT_IRQ | XPOWERS_AXP192_BAT_REMOVE_IRQ | //BATTERY + XPOWERS_AXP192_VBUS_INSERT_IRQ | XPOWERS_AXP192_VBUS_REMOVE_IRQ | //VBUS + XPOWERS_AXP192_PKEY_SHORT_IRQ | XPOWERS_AXP192_PKEY_LONG_IRQ | //POWER KEY + XPOWERS_AXP192_BAT_CHG_DONE_IRQ | XPOWERS_AXP192_BAT_CHG_START_IRQ | //CHARGE + // XPOWERS_AXP192_PKEY_NEGATIVE_IRQ | XPOWERS_AXP192_PKEY_POSITIVE_IRQ | //POWER KEY + XPOWERS_AXP192_TIMER_TIMEOUT_IRQ //Timer + ); + runSensor(nullptr); } void loop() { @@ -79,14 +142,14 @@ void loop() { } bool runSensor(void *) { - - -float isCharging = axp.isChargeing(); -boolean isFullyCharged = axp.isChargingDoneIRQ(); + + +bool isCharging = axp.isCharging(); +bool isFullyCharged = axp.isBatChargeDoneIrq(); float batteryVoltage = axp.getBattVoltage(); float batteryDischarge = axp.getAcinCurrent(); -float getTemp = axp.getTemp(); -int battPercentage = axp.getBattPercentage(); +float getTemp = axp.getTemperature(); +int battPercentage = axp.getBatteryPercent(); Serial.println("--- T-BEAM Power Information ---"); Serial.print("Duck charging (1 = Yes): "); @@ -101,19 +164,20 @@ int battPercentage = axp.getBattPercentage(); Serial.println(getTemp); Serial.print("battery Percentage: "); Serial.println(battPercentage); - - String sensorVal = - "Charging: " + - String(isCharging) ; - " BattFull: " + - String(isFullyCharged)+ - " Voltage " + - String(batteryVoltage) ; - " Temp: " + - String(getTemp); + + std::string sensorVal = + "Charging: "; + sensorVal.append(isCharging ? "Yes" : "No") + .append(" BattFull: ") + .append(isFullyCharged ? "Yes" : "No") + .append(" Voltage: ") + .append(std::to_string(batteryVoltage)) + .append(" Temp: ") + .append(std::to_string(getTemp)); duck.sendData(topics::sensor, sensorVal); + return true; } diff --git a/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX127/platformio.ini b/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX127/platformio.ini index 4305db4..8f28e5a 100644 --- a/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX127/platformio.ini +++ b/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX127/platformio.ini @@ -13,14 +13,20 @@ src_dir = . [env:ttgo-t-beam] platform = espressif32 -board = ttgo-t-beam +board = ttgo-lora32-v1 framework = arduino monitor_speed = 115200 monitor_filters = time +build_flags = + -std=c++2a + -Wno-format + -DCDP_LOG_DEBUG + -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE lib_deps = - https://github.com/Call-for-Code/ClusterDuck-Protocol - lewisxhe/AXP202X_Library + ArduinoOTA + https://github.com/ClusterDuck-Protocol/ClusterDuck-Protocol.git + lewisxhe/XPowersLib@^0.2.7 ; uncomment for OTA update ; upload_port = duck.local From 0f691e4a9f8dbaa41e960437450f03a3784f1974 Mon Sep 17 00:00:00 2001 From: Brenton Poke Date: Sat, 8 Feb 2025 17:54:34 -0500 Subject: [PATCH 4/5] these should be working now Signed-off-by: Brenton Poke --- .../TBeam-SX126/TBeam-AXP-Example.ino | 12 +- .../TBeam-SX126/platformio.ini | 10 +- .../TBeam-SX127/TBeam-AXP-Example.ino | 118 ++++++++++++++---- .../TBeam-SX127/platformio.ini | 12 +- 4 files changed, 115 insertions(+), 37 deletions(-) diff --git a/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX126/TBeam-AXP-Example.ino b/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX126/TBeam-AXP-Example.ino index 6ebddc3..76bfd1a 100644 --- a/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX126/TBeam-AXP-Example.ino +++ b/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX126/TBeam-AXP-Example.ino @@ -38,7 +38,7 @@ DuckDisplay* display = NULL; MamaDuck duck; auto timer = timer_create_default(); -const int INTERVAL_MS = 60000; +const int INTERVAL_MS = 20000; char message[32]; int counter = 1; @@ -52,8 +52,10 @@ void setup() { devId.insert(devId.end(), deviceId.begin(), deviceId.end()); // Use the default setup provided by the SDK - duck.setupWithDefaults(devId); - Serial.println("MAMA-DUCK...READY!"); + duck.setDeviceId(deviceId); + // initialize the serial component with the hardware supported baudrate + duck.setupSerial(115200); + duck.setupRadio(); // initialize the timer. The timer thread runs separately from the main loop // and will trigger sending a counter message. @@ -79,8 +81,8 @@ void loop() { bool runSensor(void *) { - float isCharging = axp.isCharging(); - boolean isFullyCharged = axp.isBatChagerDoneIrq(); + bool isCharging = axp.isCharging(); + bool isFullyCharged = axp.isBatChargeDoneIrq(); float batteryVoltage = axp.getBattVoltage(); float batteryDischarge = axp.getAcinCurrent(); float getTemp = axp.getTemperature(); diff --git a/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX126/platformio.ini b/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX126/platformio.ini index 4305db4..516593d 100644 --- a/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX126/platformio.ini +++ b/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX126/platformio.ini @@ -18,9 +18,15 @@ framework = arduino monitor_speed = 115200 monitor_filters = time +build_flags = + -std=c++2a + -Wno-format + -DCDP_LOG_DEBUG + -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE lib_deps = - https://github.com/Call-for-Code/ClusterDuck-Protocol - lewisxhe/AXP202X_Library + ArduinoOTA + https://github.com/ClusterDuck-Protocol/ClusterDuck-Protocol.git + lewisxhe/XPowersLib@^0.2.7 ; uncomment for OTA update ; upload_port = duck.local diff --git a/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX127/TBeam-AXP-Example.ino b/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX127/TBeam-AXP-Example.ino index a7ba0ba..e302f11 100644 --- a/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX127/TBeam-AXP-Example.ino +++ b/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX127/TBeam-AXP-Example.ino @@ -21,9 +21,14 @@ // AXP setup #include -#include +#define XPOWERS_CHIP_AXP192 +#define ARDUINO_TTGO_LoRa32_V1 +#include -AXP20X_Class axp; +XPowersPMU axp; + +#define XPOWERS_AXP192_BAT_CHG_DONE_IRQ 0x01 +#define XPOWERS_AXP192_BAT_CHG_START_IRQ 0x02 const uint8_t i2c_sda = 21; const uint8_t i2c_scl = 22; @@ -31,13 +36,20 @@ const uint8_t i2c_scl = 22; DuckDisplay* display = NULL; +//#define LORA_FREQ 915.0 // Frequency Range. Set for US Region 915.0Mhz +//#define LORA_TXPOWER 20 // Transmit Power +//// LORA HELTEC PIN CONFIG +//#define LORA_CS_PIN 18 +//#define LORA_DIO0_PIN 26 +//#define LORA_DIO1_PIN -1 // unused +//#define LORA_RST_PIN 14 // Set device ID between "" String deviceId = "MAMA001"; MamaDuck duck; auto timer = timer_create_default(); -const int INTERVAL_MS = 60000; +const int INTERVAL_MS = 20000; char message[32]; int counter = 1; @@ -47,11 +59,13 @@ void setup() { // setup the duck NOTE: The Device ID must be exactly 8 bytes otherwise it // will get rejected std::string deviceId("MAMA0001"); - std::vector devId; - devId.insert(devId.end(), deviceId.begin(), deviceId.end()); // Use the default setup provided by the SDK - duck.setupWithDefaults(devId); + duck.setDeviceId(deviceId); + // initialize the serial component with the hardware supported baudrate + duck.setupSerial(115200); + duck.setupRadio(); + // duck.setupRadio(LORA_FREQ, LORA_CS_PIN, LORA_RST_PIN, LORA_DIO0_PIN, LORA_DIO1_PIN, LORA_TXPOWER); Serial.println("MAMA-DUCK...READY!"); // initialize the timer. The timer thread runs separately from the main loop @@ -60,12 +74,61 @@ void setup() { Wire.begin(i2c_sda, i2c_scl); - int ret = axp.begin(Wire, AXP192_SLAVE_ADDRESS); + int ret = axp.begin(Wire, 0x34,i2c_sda,i2c_scl); + axp.setSysPowerDownVoltage(3000); + + // Set the minimum common working voltage of the PMU VBUS input, + // below this value will turn off the PMU + axp.setVbusVoltageLimit(XPOWERS_AXP192_VBUS_VOL_LIM_4V5); + + // Turn off USB input current limit + axp.setVbusCurrentLimit(XPOWERS_AXP192_VBUS_CUR_LIM_OFF); + + // DC1 700~3500mV, IMAX=1.2A + axp.setDC1Voltage(3300); + Serial.printf("DC1 :%s Voltage:%u mV \n", axp.isEnableDC1() ? "+" : "-", axp.getDC1Voltage()); + + // DC2 700~2750 mV, IMAX=1.6A; + axp.setDC2Voltage(700); + Serial.printf("DC2 :%s Voltage:%u mV \n", axp.isEnableDC2() ? "+" : "-", axp.getDC2Voltage()); + + // DC3 700~3500 mV,IMAX=0.7A; + axp.setDC3Voltage(3300); + Serial.printf("DC3 :%s Voltage:%u mV \n", axp.isEnableDC3() ? "+" : "-", axp.getDC3Voltage()); + + + //LDO2 1800~3300 mV, 100mV/step, IMAX=200mA + axp.setLDO2Voltage(1800); + + //LDO3 1800~3300 mV, 100mV/step, IMAX=200mA + axp.setLDO3Voltage(1800); + + //LDOio 1800~3300 mV, 100mV/step, IMAX=50mA + axp.setLDOioVoltage(3300); - if (ret == AXP_FAIL) { - Serial.println("AXP Power begin failed"); - while (1); - } + axp.enableDC2(); + axp.enableDC3(); + axp.enableLDO2(); + axp.enableLDO3(); + axp.enableLDOio(); + + axp.enableTemperatureMeasure(); + axp.enableBattDetection(); + axp.enableVbusVoltageMeasure(); + axp.enableBattVoltageMeasure(); + axp.enableSystemVoltageMeasure(); + + axp.clearIrqStatus(); + + axp.enableIRQ( + XPOWERS_AXP192_BAT_INSERT_IRQ | XPOWERS_AXP192_BAT_REMOVE_IRQ | //BATTERY + XPOWERS_AXP192_VBUS_INSERT_IRQ | XPOWERS_AXP192_VBUS_REMOVE_IRQ | //VBUS + XPOWERS_AXP192_PKEY_SHORT_IRQ | XPOWERS_AXP192_PKEY_LONG_IRQ | //POWER KEY + XPOWERS_AXP192_BAT_CHG_DONE_IRQ | XPOWERS_AXP192_BAT_CHG_START_IRQ | //CHARGE + // XPOWERS_AXP192_PKEY_NEGATIVE_IRQ | XPOWERS_AXP192_PKEY_POSITIVE_IRQ | //POWER KEY + XPOWERS_AXP192_TIMER_TIMEOUT_IRQ //Timer + ); + runSensor(nullptr); } void loop() { @@ -79,14 +142,14 @@ void loop() { } bool runSensor(void *) { - - -float isCharging = axp.isChargeing(); -boolean isFullyCharged = axp.isChargingDoneIRQ(); + + +bool isCharging = axp.isCharging(); +bool isFullyCharged = axp.isBatChargeDoneIrq(); float batteryVoltage = axp.getBattVoltage(); float batteryDischarge = axp.getAcinCurrent(); -float getTemp = axp.getTemp(); -int battPercentage = axp.getBattPercentage(); +float getTemp = axp.getTemperature(); +int battPercentage = axp.getBatteryPercent(); Serial.println("--- T-BEAM Power Information ---"); Serial.print("Duck charging (1 = Yes): "); @@ -101,19 +164,20 @@ int battPercentage = axp.getBattPercentage(); Serial.println(getTemp); Serial.print("battery Percentage: "); Serial.println(battPercentage); - - String sensorVal = - "Charging: " + - String(isCharging) ; - " BattFull: " + - String(isFullyCharged)+ - " Voltage " + - String(batteryVoltage) ; - " Temp: " + - String(getTemp); + + std::string sensorVal = + "Charging: "; + sensorVal.append(isCharging ? "Yes" : "No") + .append(" BattFull: ") + .append(isFullyCharged ? "Yes" : "No") + .append(" Voltage: ") + .append(std::to_string(batteryVoltage)) + .append(" Temp: ") + .append(std::to_string(getTemp)); duck.sendData(topics::sensor, sensorVal); + return true; } diff --git a/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX127/platformio.ini b/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX127/platformio.ini index 4305db4..8f28e5a 100644 --- a/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX127/platformio.ini +++ b/TTGO-TBeam/TBeam-AXP-Example/TBeam-SX127/platformio.ini @@ -13,14 +13,20 @@ src_dir = . [env:ttgo-t-beam] platform = espressif32 -board = ttgo-t-beam +board = ttgo-lora32-v1 framework = arduino monitor_speed = 115200 monitor_filters = time +build_flags = + -std=c++2a + -Wno-format + -DCDP_LOG_DEBUG + -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE lib_deps = - https://github.com/Call-for-Code/ClusterDuck-Protocol - lewisxhe/AXP202X_Library + ArduinoOTA + https://github.com/ClusterDuck-Protocol/ClusterDuck-Protocol.git + lewisxhe/XPowersLib@^0.2.7 ; uncomment for OTA update ; upload_port = duck.local From 64300597e91df065b8399eb25d55ef0b826ed756 Mon Sep 17 00:00:00 2001 From: Taraqur Date: Sun, 20 Oct 2024 23:00:40 -0400 Subject: [PATCH 5/5] made some tweaks Signed-off-by: Taraqur Signed-off-by: Brenton Poke # Conflicts: # TTGO-TBeam/TBeam-AXP-Example/TBeam-SX126/TBeam-AXP-Example.ino # TTGO-TBeam/TBeam-AXP-Example/TBeam-SX126/platformio.ini # TTGO-TBeam/TBeam-AXP-Example/TBeam-SX127/platformio.ini --- .gitignore | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 496ee2c..e25283f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ -.DS_Store \ No newline at end of file +.DS_Store +.pio +.vs_code +.vscode +secrets.h \ No newline at end of file