This tutorial shows hot to software reset ESP8266 in Arduino IDE. This sketch/example shows software reset using simple command ESP.restart() or ESP.reset().
Software reset for ESP8266 is required when you get trouble to connect WiFi router.
Lets see the use of software restart. This example program will show you software reset in a loop before it reaches to its max value.
ESP.reset()
is a hard reset and can leave some of the registers in the old state which can lead to problems, its more or less like the reset button on the PC.
ESP.restart()
tells the SDK to reboot, so its a more clean reboot.
/* * circuits4you.com * ESP8266 software reset demo * This program counts from 1 to 20 * and resets at 6 count before completing counting */ #include <ESP8266WiFi.h> // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin LED_BUILTIN as an output. Serial.begin(115200); pinMode(2, OUTPUT); } // the loop function runs over and over again forever void loop() { int i; for(i=0;i<20;i++) { digitalWrite(2, HIGH); // turn the LED on (HIGH is the voltage level) delay(500); // wait for a second digitalWrite(2, LOW); // turn the LED off by making the voltage LOW delay(500); // wait for a second Serial.print("count"); Serial.println(i); if(i==6) { Serial.println("Resetting ESP"); ESP.restart(); //ESP.reset(); } } }
Upload above program. after uploading open serial monitor you will find below reset
You will notice that it resets the ESP but wont start the program again. this is small but it is caused after only serial upload.
the boot mode:(1,7)
problem is known and only happens at the first restart after serial flashing. if you do one manual reboot by power or RST pin all will work.
After manual reset the program will work fine as expected.