8000 add Low-Power demo · esp8266/Arduino@7ea68d8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7ea68d8

Browse files
committed
add Low-Power demo
1 parent 287bc2d commit 7ea68d8

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

libraries/esp8266/examples/LowPowerDemo/LowPowerDemo.ino

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@
3939
#define DEBUG_PRINT(x)
4040
#endif
4141

42-
#define WAKE_UP_PIN D3 // GPIO0, can also force a serial flash upload with RESET
42+
#define WAKE_UP_PIN 0 // D3/GPIO0, can also force a serial flash upload with RESET
4343

4444
// un-comment one of the two lines below for your LED connection
45-
#define LED D1 // external LED for modules with built-in LEDs so it doesn't add to the current
46-
//#define LED D4 // GPIO2 LED for ESP-01,07 modules; D4 is LED_BUILTIN on most other modules
45+
#define LED 5 // D1/GPIO5 external LED for modules with built-in LEDs so it doesn't add to the current
46+
//#define LED 2 // D4/GPIO2 LED for ESP-01,07 modules; D4 is LED_BUILTIN on most other modules
4747

4848
ADC_MODE(ADC_VCC); // allows us to monitor the internal VCC level; it varies with WiFi load
4949
// don't connect anything to the analog input pin(s)!
@@ -69,7 +69,7 @@ struct {
6969
byte data[4]; // the last byte stores the reset count
7070
} rtcData;
7171

72-
byte resetLoop = 0; // keeps track of the number of Deep Sleep tests / resets
72+
byte resetCount = 0; // keeps track of the number of Deep Sleep tests / resets
7373
String resetCause = "";
7474

7575
const unsigned int blinkDelay = 100; // fast blink rate for the LED when waiting for the user
@@ -91,23 +91,23 @@ void setup() {
9191
Serial.println(resetCause);
9292
if (resetCause == "External System") {
9393
Serial.println(F("I'm awake and starting the low power tests"));
94-
resetLoop = 5;
94+
resetCount = 5;
9595
updateRTC(); // if external reset, wipe the RTC memory and start all over
9696
}
9797

9898
// Read struct from RTC memory
9999
if (ESP.rtcUserMemoryRead(64, (uint32_t*) &rtcData, sizeof(rtcData))) {
100100
uint32_t crcOfData = calculateCRC32((uint8_t*) &rtcData.data[0], sizeof(rtcData.data));
101101
if (crcOfData != rtcData.crc32) { // if the CRC is invalid
102-
resetLoop = 0; // set first test loop since power on or external reset
102+
resetCount = 0; // set first test loop since power on or external reset
103103
} else {
104-
resetLoop = rtcData.data[3]; // read the previous reset count
104+
resetCount = rtcData.data[3]; // read the previous reset count
105105
}
106106
}
107107
} // end of Setup()
108108

109109
void loop() {
110-
if (resetLoop == 0) {
110+
if (resetCount == 0) {
111111
// 1st test - running with WiFi unconfigured, reads ~67 mA minimum
112112
Serial.println(F("\n1st test - running with WiFi unconfigured"));
113113
float volts = ESP.getVcc();
@@ -171,7 +171,7 @@ void loop() {
171171
Serial.println(F("\n6th test - Deep Sleep for 10 seconds, wake with RF_DEFAULT"));
172172
init_WiFi(); // initialize WiFi since we turned it off in the last test
173173
init_OTA();
174-
resetLoop = 1; // advance to the next Deep Sleep test after the reset
174+
resetCount = 1; // advance to the next Deep Sleep test after the reset
175175
updateRTC(); // save the current test state in RTC memory
176176
volts = ESP.getVcc();
177177
Serial.printf("The internal VCC reads %1.3f volts\n", volts / 1000 );
@@ -192,12 +192,12 @@ void loop() {
192192
}
193193

194194
// 7th test - Deep Sleep for 10 seconds, wake with RFCAL
195-
if (resetLoop < 4) {
195+
if (resetCount < 4) {
196196
init_WiFi(); // need to reinitialize WiFi & OTA due to Deep Sleep resets
197197
init_OTA(); // since we didn't do it in setup() because of the first test
198198
}
199-
if (resetLoop == 1) { // second reset loop since power on
200-
resetLoop = 2; // advance to the next Deep Sleep test after the reset
199+
if (resetCount == 1) { // second reset loop since power on
200+
resetCount = 2; // advance to the next Deep Sleep test after the reset
201201
updateRTC(); // save the current test state in RTC memory
202202
Serial.println(F("\n7th test - in RF_DEFAULT, Deep Sleep for 10 seconds, wake with RFCAL"));
203203
float volts = ESP.getVcc();
@@ -212,8 +212,8 @@ void loop() {
212212
}
213213

214214
// 8th test - Deep Sleep Instant for 10 seconds, wake with NO_RFCAL
215-
if (resetLoop == 2) { // third reset loop since power on
216-
resetLoop = 3; // advance to the next Deep Sleep test after the reset
215+
if (resetCount == 2) { // third reset loop since power on
216+
resetCount = 3; // advance to the next Deep Sleep test after the reset
217217
updateRTC(); // save the current test state in RTC memory
218218
Serial.println(F("\n8th test - in RFCAL, Deep Sleep Instant for 10 seconds, wake with NO_RFCAL"));
219219
float volts = ESP.getVcc();
@@ -228,8 +228,8 @@ void loop() {
228228
}
229229

230230
// 9th test - Deep Sleep Instant for 10 seconds, wake with RF_DISABLED
231-
if (resetLoop == 3) { // fourth reset loop since power on
232-
resetLoop = 4; // advance to the next Deep Sleep test after the reset
231+
if (resetCount == 3) { // fourth reset loop since power on
232+
resetCount = 4; // advance to the next Deep Sleep test after the reset
233233
updateRTC(); // save the current test state in RTC memory
234234
Serial.println(F("\n9th test - in NO_RFCAL, Deep Sleep Instant for 10 seconds, wake with RF_DISABLED"));
235235
float volts = ESP.getVcc();
@@ -243,8 +243,8 @@ void loop() {
243243
Serial.println(F("What... I'm not asleep?!?")); // it will never get here
244244
}
245245

246-
if (resetLoop == 4) {
247-
resetLoop = 5; // start all over
246+
if (resetCount == 4) {
247+
resetCount = 5; // start all over
248248
updateRTC(); // save the current test state in RTC memory
249249
float volts = ESP.getVcc();
250250
Serial.printf("The internal VCC reads %1.3f volts\n", volts / 1000 );
@@ -299,10 +299,10 @@ uint32_t calculateCRC32(const uint8_t *data, size_t length) {
299299
}
300300

301301
void updateRTC() {
302-
rtcData.data[3] = resetLoop; // save the loop count for the next reset
302+
rtcData.data[3] = resetCount; // save the loop count for the next reset
303303
// Update CRC32 of data
304304
rtcData.crc32 = calculateCRC32((uint8_t*) &rtcData.data[0], sizeof(rtcData.data));
305-
if (resetLoop == 5) // wipe the CRC in RTC memory when we're done with all tests
305+
if (resetCount == 5) // wipe the CRC in RTC memory when we're done with all tests
306306
rtcData.crc32 = 0;
307307
// Write struct to RTC memory
308308
ESP.rtcUserMemoryWrite(64, (uint32_t*) &rtcData, sizeof(rtcData));

libraries/esp8266/examples/LowPowerDemo/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ This is typical for programs that don't use WiFi, and is a high current drain of
4848

4949
### Test 2 - Automatic Modem Sleep
5050

51-
This is the default power saving mode when you have an active WiFi connection. You don't need to add anything to your code to get it. However, it's not as wonderful as it may seem, as the only time the modem sleeps is when you spend a long time in delay(), with delay times over 50mS. The LED blinks more slowly during this test as I'm doing delay(350) to get the modem to sleep. While in delay() your sketch isn't doing anything interesting. Average current during long delay()s is 15 mA minimum. Without the delay() the average current is 67 mA with short spikes above 250 mA as transmissions occur. When the WiFi has traffic (even couple of pings), the modem can turn on for over 2 seconds continuous at 67 mA, and it may stay on for a second after the traffic. In a high traffic environment you won't get any power savings with either of the 2 Automatic modes. Automatic Modem Sleep turns on 7-8 seconds after an active connection is established.
51+
This is the default power saving mode when you have an active WiFi connection. You don't need to add anything to your code to get it. However, it's not as wonderful as it may seem, as the only time the modem sleeps is when you spend a long time in delay(), with delay times over 50mS. The LED blinks more slowly during this test as I'm doing delay(350) to get the modem to sleep. While in delay() your sketch isn't doing anything interesting. Average current during long delay()s is 15 mA minimum. Without the delay() the average current is 67 mA with short spikes above 250 mA as transmissions occur. When the WiFi has traffic (even a couple of pings), the modem can turn on for over 2 seconds continuous at 67 mA, and it may stay on for a second after the traffic. In a high traffic environment you won't get any power savings with either of the 2 Automatic modes. Automatic Modem Sleep turns on 7-8 seconds after an active connection is established.
5252

5353
### Test 3 - Forced Modem Sleep
5454

55-
Turns off the modem (losing the connection), and dropping the current by 50 mA. This uses the WiFi library function. It's good if there is a long interval with no expected traffic, as you can do other things while only drawing 15 mA.
55+
Turns off the modem (losing the connection), and dropping the current by 50 mA. This uses the WiFi library function. It's good if there is a long interval with no expected WiFi traffic, as you can do other things while only drawing 15 mA.
5656

5757
### Test 4 - Automatic Light Sleep
5858

@@ -68,7 +68,7 @@ In Deep Sleep almost everything is turned off, and the chip draws ~20 uA. If yo
6868

6969
### Test 7 - Deep Sleep, wake with RFCAL
7070

71-
Identical to the test above, but the modem does a power calibration when booting. In normal use, I'd likely do WAKE_RF_DEFAULT instead to save the extra RFCAL power burst if it's not needed.
71+
Identical to the test above, but the modem does a power calibration when booting. In normal use, I'd likely do WAKE_RF_DEFAULT instead to minimize the extra RFCAL power burst if it's not needed.
7272

7373
### Test 8 - Deep Sleep Instant, wake with NO_RFCAL
7474

0 commit comments

Comments
 (0)
0