From 249760b86dc255e57a42d93426117ef702f87ffb Mon Sep 17 00:00:00 2001 From: Cristian Paul Dragomir Date: Fri, 17 May 2024 10:42:51 +0300 Subject: [PATCH] fixed WakeFromRTC_C33 --- .../DeepSleep_WakeFromRTC_H7.ino | 83 +++++++++++++++++++ .../Standby_WakeFromRTC_C33.ino | 16 ++-- src/Board.cpp | 2 +- 3 files changed, 95 insertions(+), 6 deletions(-) create mode 100644 examples/DeepSleep_WakeFromRTC_H7/DeepSleep_WakeFromRTC_H7.ino diff --git a/examples/DeepSleep_WakeFromRTC_H7/DeepSleep_WakeFromRTC_H7.ino b/examples/DeepSleep_WakeFromRTC_H7/DeepSleep_WakeFromRTC_H7.ino new file mode 100644 index 0000000..f1082c5 --- /dev/null +++ b/examples/DeepSleep_WakeFromRTC_H7/DeepSleep_WakeFromRTC_H7.ino @@ -0,0 +1,83 @@ +/* + Charger Demo + + This sketch demonstrates how to use the PowerManagement library enable low power modes on the Arduino Portenta H7. + * In the setup() function, it enters standby mode and waits for a wakeup event from the RTC. + * The loop() functionit is not used in this sketch. + + IMPORTANT: Please note that this sketch has to be uploaded to the M4 core too in order to achieve the lowest power consumption. + + Requirements: + - Arduino Arduino Portenta H7 + - Arduino IDE + - PowerManagement library (installable from the Arduino Library Manager) + + Usage: + + 1. Connect a battery to the board. + + 2. Upload the Sketch to the M4 core: + - Open the provided sketch in the Arduino IDE. + - Select your board type and port from the "Tools" menu. + - Select the M4 core from the "Tools" menu. + - Click the "Upload" button to upload the sketch to your board. + + 3. Upload the Sketch to the M7 core: + - Select the M7 core from the "Tools" menu. + - Click the "Upload" button to upload the sketch to your board. + + 4. Observer LED behavior: + - The blue LED will turn on when the board is awake. + - The blue LED will turn off when the board goes to sleep. + - The red LED will blink if the board fails to initialize. +*/ + +#include "Arduino_PowerManagement.h" +#include "MAX1726Driver.h" + +Board board; +Charger charger; +MAX1726Driver fuelgauge(&Wire1); + +void setup() { + // When uploading this sketch to the M4 core, it just goes to standby mode. + #if defined(ARDUINO_GENERIC_STM32H747_M4) + board.standByUntilWakeupEvent(); + return; + #endif + + charger.begin(); + + // Turn off the built-in LED + pinMode(LED_BUILTIN, OUTPUT); + digitalWrite(LED_BUILTIN, HIGH); + + // Turn on the blue LED to show that the board is still awake + pinMode(LEDB, OUTPUT); + digitalWrite(LEDB, LOW); + + if(!board.begin()){ + // If the board fails to initialize, it will blink the red LED + pinMode(LEDR, OUTPUT); + while (true){ + digitalWrite(LEDR, LOW); + delay(1000); + digitalWrite(LEDR, HIGH); + delay(1000); + } + } + + charger.setEnabled(false); // -> Please measure if it makes a difference + delay(10000); // -> Give time to take the measurement + + // Takes 45s to get into shutdown mode + fuelgauge.setOperationMode(FuelGaugeOperationMode::shutdown); + + // The LED should go off when the board goes to sleep + board.setAllPeripheralsPower(false); + + board.enableWakeupFromRTC(0, 0, 60); // Go to standby for 60 seconds + board.standByUntilWakeupEvent(); +} + +void loop() {} \ No newline at end of file diff --git a/examples/Standby_WakeFromRTC_C33/Standby_WakeFromRTC_C33.ino b/examples/Standby_WakeFromRTC_C33/Standby_WakeFromRTC_C33.ino index 0bf8ca7..a4663e9 100644 --- a/examples/Standby_WakeFromRTC_C33/Standby_WakeFromRTC_C33.ino +++ b/examples/Standby_WakeFromRTC_C33/Standby_WakeFromRTC_C33.ino @@ -14,7 +14,7 @@ void blinkLed(int ledPin, int delayTime = 1000){ } void setup() { - board.setAllPeripheralsPower(true); // TODO: Check if this is necessary + pinMode(LEDR, OUTPUT); // Used to indicate errors digitalWrite(LEDR, HIGH); // Turn off the red LED @@ -24,14 +24,17 @@ void setup() { digitalWrite(LED_BUILTIN, HIGH); // Turn off the built-in LED pinMode(LEDB, OUTPUT); // Used to indicate that the board is awake - // Turn on the blue LED to show that the board is still awake - digitalWrite(LEDB, LOW); + if(!board.begin()){ while (true){ blinkLed(LEDR); } } + + board.setAllPeripheralsPower(true); // TODO: Check if this is necessary + // Turn on the blue LED to show that the board is still awake + digitalWrite(LEDB, LOW); RTC.begin(); if (!RTC.isRunning()) { @@ -43,8 +46,11 @@ void setup() { } board.enableWakeupFromRTC(0, 0, 10, [](){}, &RTC); // Sleep for 10 seconds - // board.setAllPeripheralsPower(false); + + delay(1000); // Let the user see that the board is ready to sleep + + board.setAllPeripheralsPower(false); board.standByUntilWakeupEvent(); } -void loop(){} +void loop(){} \ No newline at end of file diff --git a/src/Board.cpp b/src/Board.cpp index be35aa2..297ff53 100644 --- a/src/Board.cpp +++ b/src/Board.cpp @@ -319,4 +319,4 @@ bool Board::setReferenceVoltage(float voltage) { return UNKNOWN_VALUE; -} +} \ No newline at end of file