Skip to content

Commit 8811c6c

Browse files
polished examples, modified readme
1 parent 268326b commit 8811c6c

File tree

6 files changed

+148
-126
lines changed

6 files changed

+148
-126
lines changed

README.md

+1-13
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,12 @@
22

33
[![Check Arduino](https://github.com/arduino-libraries/Arduino_LowPowerPortentaC33/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_LowPowerPortentaC33/actions/workflows/check-arduino.yml) [![Compile Examples](https://github.com/arduino-libraries/Arduino_LowPowerPortentaC33/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_LowPowerPortentaC33/actions/workflows/compile-examples.yml) [![Spell Check](https://github.com/arduino-libraries/Arduino_LowPowerPortentaC33/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_LowPowerPortentaC33/actions/workflows/spell-check.yml) [![Sync Labels](https://github.com/arduino-libraries/Arduino_LowPowerPortentaC33/actions/workflows/sync-labels.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_LowPowerPortentaC33/actions/workflows/sync-labels.yml)
44

5-
65
The Portenta C33 Low Power Library is a library designed to optimize power consumption for projects using the Portenta C33 boards, which are powered by the Renesas RA6M5 microcontroller. The library achieves this by providing access to various low power modes. These modes are essential for applications where power efficiency is crucial, such as in remote sensing, IoT devices, or battery-powered applications.
76

8-
97
## Examples
108
* [WakeFromGPIO](https://github.com/arduino-libraries/Arduino_LowPowerPortentaC33/blob/main/examples/WakeFromGPIO/WakeFromGPIO.ino) - This example demonstrates how you can use [the GPIO pins](https://github.com/arduino-libraries/Arduino_LowPowerPortentaC33/blob/main/docs/README.md#wakeup-pins) to wake your board from sleep.
11-
129
* [WakeFromRTC](https://github.com/arduino-libraries/Arduino_LowPowerPortentaC33/blob/main/examples/WakeFromRTC/WakeFromRTC.ino) - This example demonstrates how you can use the RTC to wake the board from sleep.
1310

14-
* [TurnPeripheralsOff](https://github.com/arduino-libraries/Arduino_LowPowerPortentaC33/blob/main/examples/TurnPeripheralsOff/TurnPeripheralsOff.ino) - This example extends the [WakeFromGPIO](https://github.com/arduino-libraries/Arduino_LowPowerPortentaC33/blob/main/examples/WakeFromGPIO/WakeFromGPIO.ino) example by enabling the user to disable several power lanes to achieve the minimum power consumption of about ~60µA.
15-
16-
1711
## 😴 Sleep Modes
1812

1913
### Sleep
@@ -40,7 +34,6 @@ Here's an overview of the reduction in power usage that you can expect from this
4034

4135
For more information about these measurements check out [this document](https://github.com/arduino-libraries/Arduino_LowPowerPortentaC33/blob/main/docs/README.md)
4236

43-
4437
## Usage
4538
### Selecting a wakeup source
4639
The wakeup source can be one of the deep-sleep enabled wakeup pins, and an RTC Alarm. You can select multiple pins and the RTC alarm to wake up the board.
@@ -75,9 +68,4 @@ To make your board wake up on an RTC alarm you simply need to call `lowPower.set
7568
Use lowPower.sleep() for Sleep Mode and lowPower.deepSleep() for Deep Sleep Mode. Upon calling these methods the board will sleep until one of the wakeup events mentioned earlier arises.
7669

7770

78-
79-
80-
> [!NOTE]
81-
> Note, this library reduces the power usage of the microcontroller, not the entire board and it's peripherals (Wi-Fi module for example). If you would like to reach the maximum power reduction possible for a Portenta C33 board, please check out the [TurnPeripheralsOff Example](https://github.com/arduino-libraries/Arduino_LowPowerPortentaC33/blob/main/examples/TurnPeripheralsOff/TurnPeripheralsOff.ino) that makes use of the [Arduino_PF1550 Library](https://github.com/arduino-libraries/Arduino_PF1550)
82-
83-
For more information about this libraries check the [library documentation](https://github.com/arduino-libraries/Arduino_LowPowerPortentaC33/blob/main/docs/README.md) or the [API Reference](https://github.com/arduino-libraries/Arduino_LowPowerPortentaC33/blob/main/docs/api.md)
71+
For more information about this library check the [API Reference](https://github.com/arduino-libraries/Arduino_LowPowerPortentaC33/blob/main/docs/api.md)

docs/README.md

+14-27
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,22 @@
1+
# Portenta C33 Sleep Measurements
12

3+
The screenshots below are taken from the nRF Power Profiler application using a Nordic PPK2 while running the blink sketch on the same board.
24

3-
## Usage
4-
### Selecting a wakeup source
5-
The wakeup source can be one of the deep-sleep enabled wakeup pins, and an RTC Alarm. You can select multiple pins and the RTC alarm to wake up the board.
65

7-
#### Wakeup Pins
8-
This feature can be used when you want to wake up the board from external stimuli, such as sensors or user input. Some sensors have an interrupt pin that you can connect to one of the wakeup pins (eg: most motion sensors), while some output voltage on a pin, (eg: Passive Infrared Sensors or user buttons).
6+
#### Normal operating conditions
7+
![](https://raw.githubusercontent.com/arduino-libraries/Arduino_LowPowerPortentaC33/main/extras/results/normal_usage_blink.png)
98

10-
To select a wakeup pin just call `lowPower.setWakeupPin(<pin_number>, <direction>)`. The direction can be either **RISING** if you want to wake up when voltage is applied to a pin, or **FALLING** if you want to wake when no voltage is applied anymore.
9+
#### Deep Sleep
10+
##### Peripherals off
11+
![](https://raw.githubusercontent.com/arduino-libraries/Arduino_LowPowerPortentaC33/main/extras/results/deep_sleep_no_peripherals.png)
1112

12-
Here is a list of the usable interrupts:
13+
##### Peripherals on
14+
![](https://raw.githubusercontent.com/arduino-libraries/Arduino_LowPowerPortentaC33/main/extras/results/deep_sleep_peripherals_on.png)
1315

14-
| Arduino Pin | MCU PIN | IRQ |
15-
|-------------|---------|---------|
16-
| A0 | P006 | IRQ11|
17-
| A1 | P005 | IRQ10|
18-
| A2 | P004 | IRQ9 |
19-
| A3 | P002 | IRQ8 |
20-
| A4 | P001 | IRQ7 |
21-
| A5 | P015 | IRQ13|
22-
| D4 | P401 | IRQ5 |
23-
| D7 | P402 | IRQ4 |
16+
#### Sleep Mode
17+
##### Peripherals off
18+
![](https://raw.githubusercontent.com/arduino-libraries/Arduino_LowPowerPortentaC33/main/extras/results/sleep_no_peripherals.png)
2419

25-
> [!IMPORTANT]
26-
> Not all IRQs are created equal, the number of the IRQ represents it's priority. (IRQ0 being the highest priority and IRQ15 the lowest). Be careful when selecting your IRQ pin to make sure the board behaves as expected.
27-
28-
#### RTC Alarm
29-
This feature is particularly useful when you want to set the board to wake up at specific times. You can use this in conjunction with the [RTC library]().
30-
To make your board wake up on an RTC alarm you simply need to call `lowPower.setWakeupRTC()` and it will enable that functionality. Check out [this example]() for more details about setting up the RTC.
31-
32-
33-
### Initiating sleep modes:
34-
Use lowPower.sleep() for Sleep Mode and lowPower.deepSleep() for Deep Sleep Mode. Upon calling these methods the board will sleep until one of the wakeup events mentioned earlier arises.
20+
##### Peripherals on
21+
![](https://raw.githubusercontent.com/arduino-libraries/Arduino_LowPowerPortentaC33/main/extras/results/sleep_peripherals_on.png)
3522

docs/measurements.md

-19
This file was deleted.

examples/TurnPeripheralsOff/TurnPeripheralsOff.ino

-44
This file was deleted.
+64-2
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,87 @@
1+
/*
2+
********************************************************************************
3+
* WakeFromGPIO.ino
4+
*
5+
* This example demonstrates how to wake up the Portenta C33 from deep sleep using a GPIO pin.
6+
* The pin can be configured to wake up the device on a rising or falling edge, but not all pins are supported.
7+
* Please check the README.md file for more information about the supported pins.
8+
*
9+
* The example uses two buttons connected to pin 0 and A3:
10+
* * The device will go to sleep when the button connected to pin 0 is pressed.
11+
* * The device will wake up when the button connected to pin A3 is pressed.
12+
*
13+
* The example also demonstrates how to use the PF1550 PMIC to turn off the peripherals
14+
* before going to sleep and turn them back on after waking up.
15+
* uncomment #define TURN_PERIPHERALS_OFF on line 28 to enable this feature.
16+
*
17+
* When the device is not sleeping it will blink the built-in LED every 100ms.
18+
*
19+
* INSTRUCTIONS:
20+
* - Make sure you are running the latest version of the Renesas Core
21+
* - Select the Portenta C33 board from the Tools menu
22+
* - Select the Portenta C33 USB port from the Tools menu
23+
* - Upload the code to your Portenta C33
24+
* - Connect a button to pin 0 and with a pull-up resistor to 3.3V
25+
* - Connect a button to pin A3 and with a pull-up resistor to 3.3V
26+
* (If you need information about how to wire the buttons check this link: https://docs.arduino.cc/built-in-examples/digital/Button/)
27+
*
28+
* Original author: C. Dragomir (http://arduino.cc)
29+
*/
30+
131
#include "Arduino_LowPowerPortentaC33.h"
232

33+
// #define TURN_PERIPHERALS_OFF
334
#define SLEEP_PIN 0
435
#define WAKE_PIN A3
536

637
LowPower lowPower;
738

39+
#ifdef TURN_PERIPHERALS_OFF
40+
#include "Arduino_PMIC.h"
41+
#endif
42+
43+
#ifdef TURN_PERIPHERALS_OFF
44+
void turnPeripheralsOff(){
45+
PMIC.getControl() -> turnLDO1Off(Ldo1Mode::Normal); // LDO1 is used for AVCC (Analog Power)
46+
PMIC.getControl() -> turnLDO2Off(Ldo2Mode::Normal); // LDO2 is used for the analog voltage reference
47+
PMIC.getControl() -> turnLDO3Off(Ldo3Mode::Normal); // LDO3 is a 1.2V regulator used by the Ethernet chip
48+
PMIC.getControl() -> turnSw1Off(Sw1Mode::Normal); // SW1 is a 3.3V regulator used by RGB Led, WIFI Chip, Secure element
49+
PMIC.getControl() -> turnSw2Off(Sw2Mode::Normal); // SW2 is the power regulator used for powering external circuits (Labeled 3V3 on the board)
50+
}
51+
52+
void turnPeripheralsOn(){
53+
PMIC.getControl() -> turnLDO1On(Ldo1Mode::Normal); // LDO1 is used for AVCC (Analog Power)
54+
PMIC.getControl() -> turnLDO2On(Ldo2Mode::Normal); // LDO2 is used for the analog voltage reference
55+
PMIC.getControl() -> turnLDO3On(Ldo3Mode::Normal); // LDO3 is a 1.2V regulator used by the Ethernet chip
56+
PMIC.getControl() -> turnSw1On(Sw1Mode::Normal); // SW1 is a 3.3V regulator used by RGB Led, WIFI Chip, Secure element
57+
PMIC.getControl() -> turnSw2On(Sw2Mode::Normal); // SW2 is the power regulator used for powering external circuits (Labeled 3V3 on the board)
58+
}
59+
#endif
860

961
void goToSleep(){
10-
lowPower.deepSleep(); // lowPower.deepSleep();
62+
turnPeripheralsOff();
63+
lowPower.deepSleep();
1164
}
1265

1366
void setup(){
1467
lowPower = LowPower();
1568
attachInterrupt(digitalPinToInterrupt(SLEEP_PIN), goToSleep, RISING);
1669
lowPower.enableWakeupFromPin(WAKE_PIN, RISING);
1770
pinMode(LED_BUILTIN, OUTPUT);
71+
72+
#ifdef TURN_PERIPHERALS_OFF
73+
PMIC.begin();
74+
turnPeripheralsOn();
75+
#endif
1876
}
1977

2078
void loop(){
2179
digitalWrite(LED_BUILTIN, HIGH);
2280
delay(100);
2381
digitalWrite(LED_BUILTIN, LOW);
2482
delay(100);
25-
}
83+
}
84+
85+
86+
87+

examples/WakeFromRTC/WakeFromRTC.ino

+69-21
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,119 @@
1+
/*
2+
********************************************************************************
3+
* WakeFromRTC.ino
4+
*
5+
* This example demonstrates how to use the RTC to wake up the
6+
* Portenta C33 from deep sleep. The device will go to sleep for 1 second and
7+
* then wake up. The built-in LED will blink every second.
8+
*
9+
* The example also demonstrates how to use the PF1550 PMIC to turn off the peripherals
10+
* before going to sleep and turn them back on after waking up.
11+
* uncomment #define TURN_PERIPHERALS_OFF on line 24 to enable this feature.
12+
*
13+
* INSTRUCTIONS:
14+
* - Make sure you are running the latest version of the Renesas Core
15+
* - Select the Portenta C33 board from the Tools menu
16+
* - Select the Portenta C33 USB port from the Tools menu
17+
* - Upload the code to your Portenta C33
18+
*
19+
* Original author: C. Dragomir (http://arduino.cc)
120
21+
*/
22+
23+
// #define TURN_PERIPHERALS_OFF
224

325
#include "RTC.h"
426
#include "Arduino_LowPowerPortentaC33.h"
527

28+
#ifdef TURN_PERIPHERALS_OFF
29+
#include "Arduino_PMIC.h"
30+
#endif
631

732
LowPower lowPower;
833
RTCTime initialTime(1, Month::JANUARY, 2000, 12, 10, 00, DayOfWeek::TUESDAY, SaveLight::SAVING_TIME_ACTIVE);
934

10-
void alarmCallback(){
11-
digitalWrite(LED_BUILTIN, HIGH);
12-
delay(1000);
13-
digitalWrite(LED_BUILTIN, LOW);
14-
lowPower.deepSleep();
15-
}
35+
#ifdef TURN_PERIPHERALS_OFF
36+
void turnPeripheralsOff(){
37+
PMIC.getControl() -> turnLDO1Off(Ldo1Mode::Normal); // LDO1 is used for AVCC (Analog Power)
38+
PMIC.getControl() -> turnLDO2Off(Ldo2Mode::Normal); // LDO2 is used for the analog voltage reference
39+
PMIC.getControl() -> turnLDO3Off(Ldo3Mode::Normal); // LDO3 is a 1.2V regulator used by the Ethernet chip
40+
PMIC.getControl() -> turnSw1Off(Sw1Mode::Normal); // SW1 is a 3.3V regulator used by RGB Led, WIFI Chip, Secure element
41+
PMIC.getControl() -> turnSw2Off(Sw2Mode::Normal); // SW2 is the power regulator used for powering external circuits (Labeled 3V3 on the board)
42+
}
1643

44+
void turnPeripheralsOn(){
45+
PMIC.getControl() -> turnLDO1On(Ldo1Mode::Normal); // LDO1 is used for AVCC (Analog Power)
46+
PMIC.getControl() -> turnLDO2On(Ldo2Mode::Normal); // LDO2 is used for the analog voltage reference
47+
PMIC.getControl() -> turnLDO3On(Ldo3Mode::Normal); // LDO3 is a 1.2V regulator used by the Ethernet chip
48+
PMIC.getControl() -> turnSw1On(Sw1Mode::Normal); // SW1 is a 3.3V regulator used by RGB Led, WIFI Chip, Secure element
49+
PMIC.getControl() -> turnSw2On(Sw2Mode::Normal); // SW2 is the power regulator used for powering external circuits (Labeled 3V3 on the board)
50+
}
51+
#endif
1752

18-
bool sleepFor(int hours, int minutes, int seconds){
53+
bool sleepFor(int hours, int minutes, int seconds)
1954
{
20-
55+
if(RTC.isRunning()){
56+
// Get the current time from the RTC
2157
RTCTime currentTime;
2258
if (!RTC.getTime(currentTime)) {
23-
Serial.println("Failed to get current time");
2459
return false; // Failed to get current time
2560
}
26-
Serial.println(currentTime.toString());
2761

2862
// Convert current time to UNIX timestamp and add the desired interval
2963
time_t currentTimestamp = currentTime.getUnixTime();
3064
currentTimestamp += hours * 3600 + minutes * 60 + seconds;
65+
3166
// Convert back to RTCTime
3267
RTCTime alarmTime(currentTimestamp);
68+
69+
3370
// Configure the alarm match criteria
3471
AlarmMatch match;
3572
match.addMatchSecond(); // Trigger the alarm when the seconds match
3673
match.addMatchMinute(); // Trigger the alarm when the minutes match
3774
match.addMatchHour(); // Trigger the alarm when the hours match
38-
// Set the alarm callback (assuming you have a callback function named alarmCallback)
39-
if (!RTC.setAlarmCallback(alarmCallback, alarmTime, match)) {
40-
Serial.println("Failed to set the alarm");
75+
76+
// Set the alarm
77+
if (!RTC.setAlarm(alarmTime, match)) {
4178
return false; // Failed to set the alarm
4279
}
4380

4481
// Enable the alarm
45-
Serial.println("Enabling the alarm");
4682
return true;
4783
}
4884
}
4985

5086
void setup(){
51-
Serial.begin(9600);
52-
5387
lowPower = LowPower();
5488
lowPower.enableWakeupFromRTC();
5589

56-
pinMode(LED_BUILTIN, OUTPUT);
57-
digitalWrite(LED_BUILTIN, LOW);
90+
#ifdef TURN_PERIPHERALS_OFF
91+
PMIC.begin();
92+
turnPeripheralsOn();
93+
#endif
5894

95+
// Initialize the RTC
5996
RTC.begin();
6097

98+
// Set the initial time if the RTC is not running
6199
if (!RTC.isRunning()) {
62100
RTC.setTime(initialTime);
63-
sleepFor(0, 0, 1);
64101
}
102+
103+
pinMode(LED_BUILTIN, OUTPUT); // Set the LED pin as an output
104+
digitalWrite(LED_BUILTIN, LOW); // Turn on the LED
105+
delay(1000); // lets the user see the led for 1 second
65106

66-
lowPower.deepSleep();
107+
// The device will wake up every second and blink the LED
108+
// effectivelly creating the same efect as the blink sketch
109+
if(sleepFor(0, 0, 1)){
110+
// turn peripherals off before going to sleep
111+
#ifdef TURN_PERIPHERALS_OFF
112+
turnPeripheralsOff();
113+
#endif
114+
lowPower.deepSleep();
115+
}
67116
}
68117

69118
void loop(){
70-
71119
}

0 commit comments

Comments
 (0)