-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6bbce31
commit 249760b
Showing
3 changed files
with
95 additions
and
6 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
examples/DeepSleep_WakeFromRTC_H7/DeepSleep_WakeFromRTC_H7.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -319,4 +319,4 @@ bool Board::setReferenceVoltage(float voltage) { | |
|
||
|
||
return UNKNOWN_VALUE; | ||
} | ||
} |