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 a7ba0ba..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 @@ -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,59 @@ 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]; +const int INTERVAL_MS = 20000; +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.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. + 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(); - + + + bool isCharging = axp.isCharging(); + bool isFullyCharged = axp.isBatChargeDoneIrq(); + 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 +96,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; } 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