10000 add Low-Power demo by Tech-TX · Pull Request #6989 · esp8266/Arduino · GitHub
[go: up one dir, main page]

Skip to content

add Low-Power demo #6989

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 69 commits into from
Feb 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
0c870ae
add Low-Power demo
Tech-TX Jan 6, 2020
fd1c366
add Low-Power demo
Tech-TX Jan 6, 2020
b912664
add Low-Power demo, remove OTA and add WiFi timeout
Tech-TX Jan 9, 2020
287bc2d
add Low-Power demo
Tech-TX Jan 6, 2020
7ea68d8
add Low-Power demo
Tech-TX Jan 6, 2020
f77a2c5
add Low-Power demo, remove OTA and add WiFi timeout
Tech-TX Jan 9, 2020
387e30d
add Low-Power demo, remove OTA and add WiFi timeout
Tech-TX Jan 9, 2020
0db9254
Merge branch 'master' into add_Low-Power_demo
Tech-TX Jan 9, 2020
3f3ab30
Merge branch 'add_Low-Power_demo' of https://github.com/Tech-TX/Ardui…
Tech-TX Jan 10, 2020
df75200
add Low-Power demo
Tech-TX Jan 10, 2020
ab30950
Merge branch 'master' into add_Low-Power_demo
Tech-TX Jan 10, 2020
11f1931
add Low-Power demo
Tech-TX Jan 10, 2020
7d6a03b
Merge branch 'add_Low-Power_demo' of https://github.com/Tech-TX/Ardui…
Tech-TX Jan 10, 2020
2003ef4
add Low-Power demo
Tech-TX Jan 10, 2020
acf3cec
add Low-Power demo
Tech-TX Jan 10, 2020
2f2c508
add Low-Power demo
Tech-TX Jan 11, 2020
47b73a2
add Low-Power demo
Tech-TX Jan 11, 2020
36a8dbb
add Low-Power demo
Tech-TX Jan 11, 2020
7178362
Merge branch 'master' into add_Low-Power_demo
Tech-TX Jan 11, 2020
5d16fca
add Low-Power demo
Tech-TX Jan 12, 2020
7a74da2
Merge branch 'add_Low-Power_demo' of https://github.com/Tech-TX/Ardui…
Tech-TX Jan 12, 2020
aa4feb2
add Low-Power demo
Tech-TX Jan 12, 2020
8f4448d
add Low-Power demo
Tech-TX Jan 12, 2020
b8e42e4
add Low-Power demo
Tech-TX Jan 12, 2020
068f4bd
add Low-Power demo
Tech-TX Jan 12, 2020
3118de5
add Low-Power demo
Tech-TX Jan 12, 2020
ac40b6e
add Low-Power demo
Tech-TX Jan 12, 2020
662b1f2
add Low-Power demo
Tech-TX Jan 13, 2020
5695626
add Low-Power demo
Tech-TX Jan 16, 2020
7627080
Merge branch 'master' into add_Low-Power_demo
Tech-TX Jan 17, 2020
7b0e515
add Low-Power demo
Tech-TX Jan 17, 2020
a41c381
Merge branch 'add_Low-Power_demo' of https://github.com/Tech-TX/Ardui…
Tech-TX Jan 17, 2020
b93c2e3
add Low-Power demo
Tech-TX Jan 17, 2020
f4d00c6
add Low-Power demo
Tech-TX Jan 18, 2020
841fa1b
add Low-Power demo
Tech-TX Jan 18, 2020
efe55a0
Merge branch 'master' into add_Low-Power_demo
Tech-TX Jan 18, 2020
ebc2b0a
add Low-Power demo
Tech-TX Jan 22, 2020
c9c073a
Merge branch 'add_Low-Power_demo' of https://github.com/Tech-TX/Ardui…
Tech-TX Jan 22, 2020
222b9e8
add Low-Power demo
Tech-TX Jan 25, 2020
9ef40f8
Merge branch 'master' into add_Low-Power_demo
Tech-TX Jan 25, 2020
3ffb8ec
add Low-Power demo
Tech-TX Jan 26, 2020
b902ed2
Merge branch 'add_Low-Power_demo' of https://github.com/Tech-TX/Ardui…
Tech-TX Jan 26, 2020
6ff566d
Merge branch 'master' into add_Low-Power_demo
Tech-TX Jan 26, 2020
c8a5955
add Low-Power demo
Tech-TX Jan 26, 2020
d9ea100
Merge branch 'add_Low-Power_demo' of https://github.com/Tech-TX/Ardui…
Tech-TX Jan 26, 2020
431f5dc
add Low-Power demo
Tech-TX Jan 28, 2020
9597a12
Merge branch 'master' into add_Low-Power_demo
Tech-TX Jan 28, 2020
7d3ee8d
add Low-Power demo
Tech-TX Jan 28, 2020
701634e
Merge branch 'add_Low-Power_demo' of https://github.com/Tech-TX/Ardui…
Tech-TX Jan 28, 2020
b618e6c
add Low-Power demo
Tech-TX Jan 29, 2020
3292f9b
add Low-Power demo
Tech-TX Jan 29, 2020
1e80279
8000 add Low-Power demo
Tech-TX Jan 29, 2020
93a527b
add Low-Power demo
Tech-TX Jan 29, 2020
6018d0b
add Low-Power demo
Tech-TX Jan 30, 2020
55d95e2
Merge branch 'master' into add_Low-Power_demo
Tech-TX Jan 30, 2020
b990e59
add Low-Power demo
Tech-TX Jan 31, 2020
c107c43
add Low-Power demo
Tech-TX Jan 31, 2020
fecacfd
add Low-Power demo
Tech-TX Jan 31, 2020
601a5ae
add Low-Power demo
Tech-TX Jan 31, 2020
a3ddde1
add Low-Power demo
Tech-TX Jan 31, 2020
535d483
add Low-Power demo
Tech-TX Jan 31, 2020
3775b1b
add Low-Power demo
Tech-TX Feb 1, 2020
56cb239
add Low-Power demo
Tech-TX Feb 1, 2020
c26ce4a
add Low-Power demo
Tech-TX Feb 1, 2020
a76ec12
add Low-Power demo
Tech-TX Feb 1, 2020
a79f48c
add Low-Power demo
Tech-TX Feb 1, 2020
ee4c701
add Low-Power demo
Tech-TX Feb 1, 2020
d378102
add Low-Power demo
Tech-TX Feb 1, 2020
df1a494
Merge branch 'master' into add_Low-Power_demo
Tech-TX Feb 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add Low-Power demo
  • Loading branch information
Tech-TX committed Jan 16, 2020
commit 56956263f409faa7afbda753911fe72305cbbd21
61 changes: 54 additions & 7 deletions libraries/esp8266/examples/LowPowerDemo/LowPowerDemo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ IPAddress dns1(0, 0, 0, 0);
IPAddress dns2(0, 0, 0, 0);
uint32_t wifiTimeout = 25E3; // 25 second timeout on the WiFi connection

//#define testPoint 4 // D2/GPIO4 used to track the timing of several test cycles, entirely optional

// This structure will be stored in RTC memory to remember the reset count (number of Deep Sleeps).
// First field is CRC32, which is calculated based on the rest of the structure contents.
// Any fields can go after the CRC32. The structure must be 4-byte aligned.
Expand All @@ -77,18 +79,25 @@ struct {
} rtcData;

byte resetCount = 0; // keeps track of the number of Deep Sleep tests / resets
String resetCause = "";

const uint32_t blinkDelay = 100; // fast blink rate for the LED when waiting for the user
const uint32_t longDelay = 350; // longer delay() for the two AUTOMATIC modes
esp8266::polledTimeout::periodicFastMs blinkLED(blinkDelay);
esp8266::polledTimeout::periodicMs blinkLED(blinkDelay);
esp8266::polledTimeout::oneShotFastMs altDelay(blinkDelay);
// use fully qualified type and avoid importing all ::esp8266 namespace to the global namespace

void wakeupCallback() { // unlike ISRs, you can do a print() from a callback function
#ifdef testPoint
digitalWrite(testPoint, LOW); // testPoint tracks latency from WAKE_UP_PIN LOW to testPoint LOW
#endif
Serial.println(F("Woke from Forced Light Sleep - this is the callback"));
}

void setup() {
#ifdef testPoint
pinMode(testPoint, OUTPUT); // test point for Forced Light Sleep and Deep Sleep tests
digitalWrite(testPoint, LOW); // Deep Sleep reset doesn't clear GPIOs, testPoint falling shows boot time
#endif
pinMode(LED, OUTPUT); // activity and status indicator
digitalWrite(LED, LOW); // turn on the LED
pinMode(WAKE_UP_PIN, INPUT_PULLUP); // polled to advance tests, interrupt for Forced Light Sleep
Expand Down Expand Up @@ -131,7 +140,13 @@ void loop() {
volts = ESP.getVcc();
Serial.printf("The internal VCC reads %1.3f volts\n", volts / 1000);
Serial.println(F("press the button to continue"));
waitPushbutton(true, longDelay);
waitPushbutton(true, 90); /* This is using a special feature: below 100 mS blink delay,
the LED blink delay is padding the time with 'program cycles' to fill the 100 mS. At 90 mS
delay, 90% of the blink time is delay(), and 10% is 'your program running'. Below 90% you
will see a difference in the average amperage, less delay() = more amperage. At 100 mS
and above it's essentially all delay() time. On an oscilloscope you'll see the time
between beacons at > 67 mA more often with less delay() percentage. You can change the
'90' mS to other values to see the effect it has on Automatic Modem Sleep. */
} else {
Serial.println(F("no WiFi connection, test skipped"));
}
Expand All @@ -144,7 +159,10 @@ void loop() {
volts = ESP.getVcc();
Serial.printf("The internal VCC reads %1.3f volts\n", volts / 1000);
Serial.println(F("press the button to continue"));
waitPushbutton(true, longDelay);
waitPushbutton(true, 99); /* Using the same < 100 mS feature. If you drop the delay below 100, you
will see the effect of program time vs. delay() time on minimum amperage. Above ~ 97 (97% of the
time in delay) there is little change in amperage, so you need to spend maximum time in delay()
to get minimum amperage. At a high percentage of delay() you will see minimum amperage. */

// 4th test - Automatic Light Sleep
Serial.println(F("\n4th test - Automatic Light Sleep"));
Expand All @@ -161,7 +179,9 @@ void loop() {
volts = ESP.getVcc();
Serial.printf("The internal VCC reads %1.3f volts\n", volts / 1000);
Serial.println(F("press the button to continue"));
waitPushbutton(true, longDelay);
waitPushbutton(true, 350); /* Below 100 mS delay it only goes into 'Automatic Modem Sleep',
and below ~ 350 mS delay() the 'Automatic Light Sleep' is less frequent. Above 350 mS
delay() doesn't make much improvement in power savings. */
} else {
Serial.println(F("no WiFi connection, test skipped"));
}
Expand All @@ -171,6 +191,9 @@ void loop() {
WiFi.mode(WIFI_OFF); // you must turn the modem off; using disconnect won't work
yield();
digitalWrite(LED, HIGH); // turn the LED off so they know the CPU isn't running
#ifdef testPoint
digitalWrite(testPoint, HIGH); // testPoint LOW in callback tracks latency from WAKE_UP_PIN LOW to testPoint LOW
#endif
volts = ESP.getVcc();
Serial.printf("The internal VCC reads %1.3f volts\n", volts / 1000);
Serial.println(F("CPU going to sleep, pull WAKE_UP_PIN low to wake it (press the button)"));
Expand Down Expand Up @@ -198,8 +221,13 @@ void loop() {
delay(50); // debounce time for the switch, button released
waitPushbutton(false, blinkDelay); // set true if you want to see Automatic Modem Sleep
digitalWrite(LED, LOW); // turn the LED on, at least briefly
//WiFi.mode(WIFI_SHUTDOWN); // Forced Modem Sleep for a more Instant Deep Sleep, and no long
// RFCAL as it goes into Deep Sleep
Serial.println(F("going into Deep Sleep now..."));
Serial.flush(); // needs a delay(10) or Serial.flush() else it doesn't print the whole message
#ifdef testPoint
digitalWrite(testPoint, HIGH); // testPoint set HIGH to track Deep Sleep period, cleared at startup()
#endif
ESP.deepSleep(10E6, WAKE_RF_DEFAULT); // good night! D0 fires a reset in 10 seconds...
delay(10);
// if you do ESP.deepSleep(0, mode); it needs a RESET to come out of sleep (RTC is off)
Expand All @@ -221,8 +249,13 @@ void loop() {
Serial.printf("The internal VCC reads %1.3f volts\n", volts / 1000);
Serial.println(F("press the button to continue"));
waitPushbutton(false, blinkDelay); // set true if you want to see Automatic Modem Sleep
//WiFi.mode(WIFI_SHUTDOWN); // Forced Modem Sleep for a more Instant Deep Sleep, and no RFCAL
// as it goes into Deep Sleep
Serial.println(F("going into Deep Sleep now..."));
Serial.flush(); // needs a delay(10) or Serial.flush() else it doesn't print the whole message
#ifdef testPoint
digitalWrite(testPoint, HIGH); // testPoint set HIGH to track Deep Sleep period, cleared at startup()
#endif
ESP.deepSleep(10E6, WAKE_RFCAL); // good night! D0 fires a reset in 10 seconds...
delay(10);
Serial.println(F("What... I'm not asleep?!?")); // it will never get here
Expand All @@ -237,8 +270,13 @@ void loop() {
Serial.printf("The internal VCC reads %1.3f volts\n", volts / 1000);
Serial.println(F("press the button to continue"));
waitPushbutton(false, blinkDelay); // set true if you want to see Automatic Modem Sleep
//WiFi.mode(WIFI_SHUTDOWN); // Forced Modem Sleep for a more Instant Deep Sleep, and no RFCAL
// as it goes into Deep Sleep
Serial.println(F("going into Deep Sleep now..."));
Serial.flush(); // needs a delay(10) or Serial.flush() else it doesn't print the whole message
#ifdef testPoint
digitalWrite(testPoint, HIGH); // testPoint set HIGH to track Deep Sleep period, cleared at startup()
#endif
ESP.deepSleepInstant(10E6, WAKE_NO_RFCAL); // good night! D0 fires a reset in 10 seconds...
delay(10);
Serial.println(F("What... I'm not asleep?!?")); // it will never get here
Expand All @@ -253,8 +291,12 @@ void loop() {
Serial.printf("The internal VCC reads %1.3f volts\n", volts / 1000);
Serial.println(F("press the button to continue"));
waitPushbutton(false, blinkDelay); // set true if you want to see Automatic Modem Sleep
// WiFi.mode(WIFI_SHUTDOWN); // Forced Modem Sleep for a more Instant Deep Sleep
Serial.println(F("going into Deep Sleep now..."));
Serial.flush(); // needs a delay(10) or Serial.flush() else it doesn't print the whole message
#ifdef testPoint
digitalWrite(testPoint, HIGH); // testPoint set HIGH to track Deep Sleep period, cleared at startup()
#endif
ESP.deepSleepInstant(10E6, WAKE_RF_DISABLED); // good night! D0 fires a reset in 10 seconds...
delay(10);
Serial.println(F("What... I'm not asleep?!?")); // it will never get here
Expand All @@ -272,7 +314,7 @@ void loop() {
}

void waitPushbutton(bool usesDelay, unsigned int delayTime) { // loop until they press the button
// note: 2 different modes, as both of the AUTOMATIC power saving modes need a long delay()
// note: 2 different modes, as 3 of the power saving modes need a delay() to activate fully
if (!usesDelay) { // quick interception of button press, no delay() used
blinkLED.reset(delayTime);
while (digitalRead(WAKE_UP_PIN)) { // wait for a button press
Expand All @@ -281,10 +323,15 @@ void waitPushbutton(bool usesDelay, unsigned int delayTime) { // loop until the
}
yield(); // this would be a good place for ArduinoOTA.handle();
}
} else { // long delay() for the 2 AUTOMATIC modes, but it misses quick button presses
} else { // long delay() for the 3 modes that need it, but it misses quick button presses
while (digitalRead(WAKE_UP_PIN)) { // wait for a button press
digitalWrite(LED, !digitalRead(LED)); // toggle the activity LED
delay(delayTime); // another good place for ArduinoOTA.handle();
if (delayTime < 100) {
altDelay.reset(100 - delayTime); // pad the time < 100 mS with some real CPU cycles
while (!altDelay) { // this simulates 'your program running', not delay() time
}
}
}
}
delay(50); // debounce time for the switch, button pressed
Expand Down
Loading
0