Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By Kelrob
#58930 Hi,

I've used timer-controlled deep sleep successfully but run into limitations.
As stated in multiple documentations GPIO16 and nRST need to be connected for timer-controlled deep sleep. AFAIK if "system_deep_sleep(SLEEP_TIME_MS * 1000);" is called within an Arduino sketch this
- switches all GPIOs in tristate (except GPIO16)
- switches GPIO16 from normal GPIO behavior to direct access by RTC
- RTC switches GPIO16 active high immediately
- RTC switches GPIO16 active low after sleep time, which resets the ESP8266 due to the external connection to nRST.

Is it possible to change the current behavior, so that RTC does not output an ACTIVE HIGH state while sleep time is running but only a PASSIVE HIGH state e.g. like switching to input state with pullup enabled?
In this case less care has to be taken e.g. when connecting a reset button in parallel. Currently if no limiting resistor is used between nRST and GPIO16 the reset button switching to GND will draw excessive current from GPIO16.

Best regards,
Kelrob

FYI, timer-controlled deep sleep sketch is added below:
Code: Select all/*
 * Sleep modes and approx. current consumption:
 * MODEM-SLEEP: 15 mA
 * LIGHT_SLEEP: 400 uA
 * DEEP_SLEEP:  <20 uA
 * Documented in detail here: http://www.espressif.com/sites/default/files/9b-esp8266-low_power_solutions_en_0.pdf
 *
 * Limitation in deep sleep mode is that a complete reset has to be performed,
 * so only wakeup method is a connection from GPIO16 to RST, or an external reset signal...
 *
 * For testing purpose
 * - A LED is connected to GPIO4 (with series resistor to VCC, if connected to GND it will still be on as the GPIO is set to tristate + pullup during deepsleep).
 * - GPIO16 and nRST are tied together (better using a resistor in 1..10k range to allow RST button to reset device without drawing excessive current from GPIO16).
 */

#define EXTERNAL_LED    4
#define SLEEP_TIME_MS   15500

// SDK headers are in C, include them extern or else they will throw an error compiling/linking
// all SDK files required can be added between the { }
extern "C" {
#include "user_interface.h"
}

void setup()
{
  digitalWrite(EXTERNAL_LED, HIGH);
  pinMode(EXTERNAL_LED, OUTPUT);

  // Setup serial comm port for printing debug information
  Serial.begin(74880); // this baud rate of 74880 is the one used in boot loader...

  do { delay(1); } while (!Serial); // Wait at least a ms, or until connection is ready, to let the background tasks activate the correct speed set before
  Serial.print("\r\n\r\n"); // Now separate bootloader printings from the following ones
 
  Serial.println("Setup done ...");
}

void loop()
{
  Serial.println("Loop entered");
 
  for (int i = 0; i < 5; i++)
  {
    digitalWrite(EXTERNAL_LED, LOW);
    delay(250);
    digitalWrite(EXTERNAL_LED, HIGH);
    delay(250);
  }

  Serial.println("Wait 3 seconds before going to sleep...");
  delay(3000);
 
  Serial.print("... and going to sleep now for ");
  String timeStr = String(float(SLEEP_TIME_MS) / 1000.0,1);
  Serial.print(timeStr);
  Serial.println(" seconds ...");
 
  system_deep_sleep(SLEEP_TIME_MS * 1000);
  delay(1000); // a short delay to allow the system go to sleep without executing further code
}
User avatar
By mrburnette
#59077
Currently if no limiting resistor is used between nRST and GPIO16 the reset button switching to GND will draw excessive current from GPIO16.


I do not understand the concern over 1 little resistor, it could even be 10% since stability is not critical. That would be IMO the best engineering. Then the Reset button is free to do it's thing without fear of the current state of GPIO16.

Ray