Skip to content

Commit

Permalink
fixed WakeFromRTC_C33
Browse files Browse the repository at this point in the history
  • Loading branch information
cristidragomir97 committed May 17, 2024
1 parent 6bbce31 commit 249760b
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 6 deletions.
83 changes: 83 additions & 0 deletions examples/DeepSleep_WakeFromRTC_H7/DeepSleep_WakeFromRTC_H7.ino
Original file line number Diff line number Diff line change
@@ -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() {}
16 changes: 11 additions & 5 deletions examples/Standby_WakeFromRTC_C33/Standby_WakeFromRTC_C33.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()) {
Expand All @@ -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(){}
2 changes: 1 addition & 1 deletion src/Board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,4 @@ bool Board::setReferenceVoltage(float voltage) {


return UNKNOWN_VALUE;
}
}

0 comments on commit 249760b

Please sign in to comment.