Post topics, source code that relate to the Arduino Platform

User avatar
By jankop
#54081
Code: Select allextern "C" {
#include "user_interface.h"
}
void setup() {
  rst_info *rsti;
  Serial.begin(115200);
  rsti = ESP.getResetInfoPtr();
  Serial.println("\r\nStart...");
  Serial.println(String("ResetInfo.reason = ") + rsti->reason);
  if (rsti->reason==0){Serial.println("CH_PD button from deep sleep = SW1");};
  // PowerOn from normal run, not from deep sleep is 0, the same as CH_PD from deep sleep !!!
  if (rsti->reason==5){Serial.println("Power ON from deep sleep!");};
  if (rsti->reason==6){Serial.println("RST button from deep sleep = SW2");};
 }
void loop() {
 
  Serial.println("going to sleep now...");
  system_deep_sleep_set_option(0);
  system_deep_sleep(1800000000);            // deep sleep for 1/2 hour
  delay(1000);
}


Code: Select allStart...
ResetInfo.reason = 0
CH_PD button from deep sleep = SW1
going to sleep now...


Start...
ResetInfo.reason = 6
RST button from deep sleep = SW2
going to sleep now...


Start...
ResetInfo.reason = 5
Power ON from deep sleep!
going to sleep now...
You do not have the required permissions to view the files attached to this post.
User avatar
By shoelessone
#54104 Wow, thank you all for the ideas / recommendations!

I really like the idea of using a resistor as it cuts down on the number of pins I have to use, I'm just hoping it would be reliable enough... this is probably a stupid question but if somebody just presses the button down for a fraction of a second will that be enough time for the esp to "boot up" and get a reading from the pin?

Also jankop serious thank you so much for posting that code / diagram - I have to admit though that I don't fully understand it. I'm not familiar with `getResetInfoPtr()` - I guess I'll have to look further into it!

Thanks again, I'm going to hopefully breadboard both of these up soon!!
User avatar
By schufti
#54111 due to "housekeeping" the esp is not the fastest to boot up. But in ~300ms it should be in your setup() and you should be able to check the button. Pressing a button for less than 300ms is pretty quick but hey, if you can't detect a presed button just go to sleep again.

the getResetInfoPtr() etc is code to determine what is the actual cause for the start, esp is pretty talkative about this: power up, watchdog, rst_pin, reset from deep_sleep, ...

shortly removing high on chpd (disregarding of former state) is the same as powering up,
aserting reset can be: just simple reset or wakeup from deep-sleep, depending on the former state.
User avatar
By picstart
#54121 Nice code but I'm still uncertain as to exactly what is needed in the way of complete wiring.
This is what I thought is the rule
MODE GPIO15 GPIO0 GPIO2
SDIO (BootSDCard) 1 x x
UART (UploadCode) 0 0 x or 1
FLASH (NormalRunning) 0 1 x or 1

So GPIO0 needs to be pulled high for normal running and low when UART flashing and GPIO15 needs to be pulled low.....probably this is omitted from the above schema since it is probably obvious or can the pins be left unattached as shown in the schema