Notifications
Clear all

ESP8266 Deep Sleep - The Darkness Returns

47 Posts
3 Users
4 Likes
2,006 Views
Inq
 Inq
(@inq)
Member
Joined: 2 years ago
Posts: 1900
Topic starter  

Posted by: @zander

@inq What is the issue with an ESP-01 and LORA?

Not enough pins.  They don't expose the SPI pins on the ESP-01 and the LoRa require them and I haven't found an I2C version of LoRa.  

image

3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide


   
ReplyQuote
Inq
 Inq
(@inq)
Member
Joined: 2 years ago
Posts: 1900
Topic starter  

@zander,

Found a voltage regulator that only uses 4 uA when the MPU is in sleep mode.  If I can get the ESP8266 to its supposed 20 uA sleep mode, that means on a single 18650, it could sleep for 9 years!

https://forum.dronebotworkshop.com/help-wanted/hardware-problem-powering-confusion/#post-43689

Now, to determine the run time with the LoRa, but I imagine, I'll easily exceed my several months goal.

3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7076
 

@inq You might find something of interest here https://www.electronicshub.org/esp8266-deep-sleep-mode/

I did not know about the needed wire but noticed when I return from sleep the print produced garbage. I will try again to see if the wire fixes it.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7076
 

@inq You probably know about this book, but for the benefit of all I am posting it here. 

NOTE: This book says deep sleep max time is uint32_t while the header file says uint64_t. I did a test and thought I proved it was 64 bit but now I find I need a jumper from pin D0 to RST so I will test again today. I will post results later.

Screenshot 2023 11 07 at 10.06.44

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1123
 

Its been one of those days when I've not been motivated to pick up my tools for my house project and I've been perusing some forums.  A quick read of this topic reminded me of one I just read from another place - quote

" I suggest looking at the FeatherS3. (from Unexpected Maker) The ESP32-S3 has extremely low deepsleep current (unlike ESP32) and the board is well designed. I haven't managed to get a measurement of deepsleep current for the entire board powered from LiPo, but it's below 1μA. "

So I pass this on in case its of interest.

 


   
Inq reacted
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7076
 

@byron I do have a couple S3's and C3's. When I get a chance, I will check the datasheets and do a test or three, but since I doubt I will use any of those boards for my planned projects, it will be a lower-priority task. If/when you get a reading, please update us. For really low current levels, the standard VOM is a problem. Here are VIDEO  and website for the proper test instrument.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
Inq
 Inq
(@inq)
Member
Joined: 2 years ago
Posts: 1900
Topic starter  

Got a circuit that works.  

I haven't run all the tests, but here are the ones more important for my immediate project.  I'm using a bare ESP8266-12E.  I've disabled the WiFi in software.  There is a momentary glitch to fairly high current ~180mA as the power-on state always turns on the WiFi.  It is very quick on my volt meter.  (Don't have an oscilloscope).  The Sketch:

 #include <ESP8266WiFi.h>
 
void setup() 
{
    //  https://www.instructables.com/ESP8266-Pro-Tips/ 
    // According to this article...
    // There is no way to turn off WiFi via software from a power-on state.
    // We can, however, turn it off immediately.  Note all 3 statements are
    // required.  In this project, I will not be using the WiFi capabilities
    // of the ESP8266.  Will be using LoRa
    WiFi.mode(WIFI_OFF);
    WiFi.forceSleepBegin();
    delay(1);
  
    // 1 second delay with LED On so we can see it's started.
    pinMode(LED_BUILTIN, OUTPUT);
    delay(1000);
    
    // 10 second delay with LED Off to measure current.
    digitalWrite(LED_BUILTIN, HIGH);
    delay(10000);

    // 10 second delay with LED On to measure current.
    digitalWrite(LED_BUILTIN, LOW);
    delay(20000);
    
    // 30 second delay in sleep mode to measure current.
    u32 SLEEP = 30E6; // UINT_MAX;

    // This puts it to sleep, but also disables the radio from automatically
    // starting up when it awakes.
    ESP.deepSleep(SLEEP, WAKE_RF_DISABLED); 
}

void loop() {}

 

I imagine the LED Off/On readings are fairly useless except to say what the MPU is actually using.  It's not running anything, has no sensors on it, no WiFi or the eventual LoRa I plan to use.  I also read that input voltage on the ESP8266 has an effect on the sleep current reading.  I found that to be true.

image

15 milli-Amp running load

15 mA Running Load

15 micro-Amp Sleep load

15uA Sleep Load

3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7076
 

@inq Now try pulling the resistor out of the EN pin, that should yield about 3uA and is called hibernate mode. That's all I know, I do NOT know if it will come out of sleep. The 8266 has to be a model with NO S on the end as they have a hardwired 12K which can be desoldered unless it's inside the can.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7076
 

@inq Try printing something after it wakes up, I only get garbage. I have tried everything I know.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
Inq
 Inq
(@inq)
Member
Joined: 2 years ago
Posts: 1900
Topic starter  

Posted by: @zander

@inq Try printing something after it wakes up, I only get garbage. I have tried everything I know.

Here it ran through two sleeps...

******** I get a full line of garbage here that is the normal initialization crap.
Full, LED Off, 10 seconds
Full, LED On, 10 seconds
Sleep for 30 seconds
******** I get a full line of garbage here that is the normal initialization crap.
Full, LED Off, 10 seconds
Full, LED On, 10 seconds
Sleep for 30 seconds
******** I get a full line of garbage here that is the normal initialization crap.
Full, LED Off, 10 seconds
Full, LED On, 10 seconds
Sleep for 30 seconds

 

Here is the code I'm using:

 #include <ESP8266WiFi.h>
 
void setup() 
{
    //  https://www.instructables.com/ESP8266-Pro-Tips/ 
    // According to this article...
    // There is no way to turn off WiFi via software from a power-on state.
    // We can, however, turn it off immediately.  Note all 3 statements are
    // required.  In this project, I will not be using the WiFi capabilities
    // of the ESP8266.  Will be using LoRa
    WiFi.mode(WIFI_OFF);
    WiFi.forceSleepBegin();
    delay(1);
  
    // 1 second delay with LED On so we can see it's started.
    pinMode(LED_BUILTIN, OUTPUT);
    digitalWrite(LED_BUILTIN, LOW);
    Serial.begin(115200);
    Serial.setTimeout(2000);
    delay(1000);
    
    // 10 second delay with LED Off to measure current.
    Serial.println("\nFull, LED Off, 10 seconds");
    digitalWrite(LED_BUILTIN, HIGH);
    delay(10000);

    // 10 second delay with LED On to measure current.
    Serial.println("Full, LED On, 10 seconds");
    digitalWrite(LED_BUILTIN, LOW);
    delay(20000);
    
    // 10 second delay in sleep mode to measure current.
    u32 SLEEP = 30E6;
    Serial.printf("Sleep for %u seconds\n", SLEEP / 1000000);
    // This puts it to sleep, but also disables the radio from automatically
    // starting up when it awakes.
    ESP.deepSleep(SLEEP, WAKE_RF_DISABLED); 
}

void loop() 
{
}

 

3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide


   
Inst-Tech reacted
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7076
 

@inq Excellent. I only was using

Serial.flush();
Serial.println(" Sleep ended");
Serial.println(" Sleep ended");
Serial.println(" Sleep ended");
and never saw any of those. I suspect it has something to do with Serial, maybe it needs to be initialized again. OR, the working code must be done prior to sleep. I will run another test, I think I misunderstood something.
Are you seeing 3uA during Hibernate now?

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
Inq
 Inq
(@inq)
Member
Joined: 2 years ago
Posts: 1900
Topic starter  

Posted by: @zander

I suspect it has something to do with Serial, maybe it needs to be initialized again.

Yes, waking is basically the same a fresh boot.  It comes in at the Setup... not where the sleep is.  Also... a lot of people use 

Serial.begin();

while(!Serial) delay(xxxx);

That doesn't work on an ESP8266...  That is why I just do the delay(1000); and assume the serial monitor has finally been attached.

Posted by: @zander

Are you seeing 3uA during Hibernate now?

Unless you know of a way to make the MPU un-hibernate, I won't be using it.  I don't want to use external components to re-start it.

VBR,

Inq

 

3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7076
 

@inq Until I get some 8266 boards to test with I do not know for sure, but my current understanding is there are no other components, the hibernate timer expires and the board resets same as deepSleep. The ESP32 has a documented Hibernate mode that uses 2.5uA, deepSleep is 10uA.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
Inq
 Inq
(@inq)
Member
Joined: 2 years ago
Posts: 1900
Topic starter  

Posted by: @zander

I really don't understand the math of going from 19uA to 3uA

Sorry, I think I really did gloss over that and it might be useful to someone in the future.  Also, I had two threads going... this one - progress on using sleep timer and the other just getting the ESP to power on.  

To calculate battery life, first, we need to find the average power usage over one hour.  I'll use my numbers as an example.

Time Running in One Hour

12 seconds (It wakes every 15 minutes for 3 seconds - A complete WAG until I get the actual LoRa)

150 mA (A complete WAG until I get the actual LoRa)

Time Sleeping in One Hour

3588 seconds (Seconds in an hour not used by 12 seconds)

0.019 mA (From experiment above for deep sleep at 3.3V, In the hibernation case, this is 0.003 mA)

Average Power Usage in One Hour

0.518937 mA/h = (12 * 150 + 3588 * 0.19) / 3600.  In the hibernation case:  0.50299 mA/h = (12 * 150 + 3588 * 0.003) / 3600

Battery Life using 2000 mAh LiIon 18650 cell

160.6 days = 2000 mAh / 0.518937 mA/h / 24 h/day.   In the hibernation case:  165.7 days = 2000 / 0.50299 / 24 

The slight difference between 161 days and 166 days is not that important in my case where I'd be happy with 30 days.  For that matter, I'll either up the number samples per hour or do a lot more sensors and thus increase the awake time and power usage.

I don't see how the software sleep timer can cause the resistor to be used/not used in the hibernation case and it is not worth it to me to add a secondary timing circuit (basically another MPU with its own battery source???) just to get that extra 3% of time.  However, I can fully understand you and others do have other design requirements.  

3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7076
 

@inq I think maybe a math error?

0.019 mA (From experiment above for deep sleep at 3.3V, In the hibernation case, this is 0.003 mA)

Average Power Usage in One Hour

0.518937 mA/h = (12 * 150 + 3588 * 0.19) / 3600.  In the hibernation case:  0.50299 mA/h = (12 * 150 + 3588 * 0.003) / 3600

Shouldn't it be 

0.019 A (From experiment above for deep sleep at 3.3V, In the hibernation case, this is 0.003 A)

Average Power Usage in One Hour

 (12 * 150 + 3588 * 19) / 3600.  In the hibernation case:  (12 * 150 + 3588 * 3) / 3600

I make that as 19.4 and 3.49

Battery life is then 4 days vs 24 days.

I don't trust my brain to do even this simple math, so please check me.

Your error was in using mA when in fact it's Amps. i.e. 19mA and 0.019 A is the same.

 

 

 

 

 

 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
Page 2 / 4