ESP32 Arduino: Software reset

The objective of this post is to explain how to perform a software reset on the ESP32, using the Arduino core. The tests of this ESP32 tutorial were performed using a DFRobot’s ESP-WROOM-32 device integrated in a ESP32 FireBeetle board.

Introduction

The objective of this post is to explain how to perform a software reset on the ESP32, using the Arduino core.

The tests of this ESP32 tutorial were performed using a DFRobot’s ESP-WROOM-32 device integrated in a ESP32 FireBeetle board.

If you prefer a video version of this tutorial, please check my YouTube channel below.

The Arduino code

We will start our Setup function code by opening a Serial connection, so we can output a message indicating the program has started.

Serial.begin(115200);

We will then print the mentioned message to the serial port, so we can know when the ESP32 has been restarted and is running again from the beginning.

Serial.println("Restarting in 10 seconds");

After that we will do a small 10 seconds delay before we actually restart the device. To do so, we simply call the delay function, which receives as input the number of microseconds to wait.

delay(10000);

Finally, we will restart the ESP32 with a call to the restart method on the ESP object. This method receives no parameters and returns void.

This ESP object is an extern variable of class EspClass, defined here. You can check at the previous link some other interesting system functions exposed by this object.

Note that we don’t need to perform any library include to access this object, which is available by default.

ESP.restart();

The final full Arduino code can be seen below.

void setup() {
  Serial.begin(115200);
  Serial.println("Restarting in 10 seconds");

  delay(10000);

  ESP.restart();

}

void loop() {}

Testing the code

To test the code, simply compile it and upload it to your ESP32 board. Then, open the Arduino IDE serial monitor.

You should get an output similar to figure 1, which shows the initial serial print of the program multiple times, meaning that the ESP32 is indeed being reset and the program is running again from the beginning.

ESP32 Arduino software restart

Figure 1 – Restarting the ESP32 via software.

17 thoughts on “ESP32 Arduino: Software reset”

  1. Hi all,
    I have an ESP32 Cam with streaming Web server. After 8 to 10 hours the web server stops responding. Maybe it is a heap problem or something but the only way I can get it to work again is to reset or cycle power. I’m using the example camera Web server sketch from arduino.

    Do you guys have any idea what can be done to solve this problem?

    Thanks.
    Mike.

    1. Hi Mike,
      Did you find a solution for your problem? I’m struggling with the same issue…
      Thanks in advance,
      Geert

      1. Not totally.
        I put in code to make it reconnect to the Wi-Fi. I also utilised the red LED when it attempts to connect to the Wi-Fi. After reset the red light will come on and then it will connect and the light would go off. But I saw a case when I tried to reconnect and the LED would stay and it would never connect until I did a reset.
        But with this reconnect scheme it would keep working for a week or so longer than it did before. But occasionally it would fail to connect.
        I also thought about connecting a GPIO pin to the reset button so it could do a hard reset when things really go bad.

        1. I have a situation where the ESP.restart does not properly reset the ESP32 NodeEMU board. It does do a restart, but some of the data is corrupted instead of being cleared out when the sketch runs anew. However, if I press the hard EN/RST button, all is fine. Unfortunately this board does not allow use of the ESP.reset function which would clear all data and start a “fresh” run of the sketch.

          I tried to use the GPIO2 pin, and others, to force the EN/RST to LOW and it does reset the ESP, B-U-T it will keep the EN/RST LOW and does not go back HIGH on reboot as stated, so it’s caught in a restart loop. Also, if GPIO2 is connected to EN/RST the button is nonfunctional as it’s being held HIGH by GPIO2.

          And in either of these situations, I am unable to upload any modified sketch until I remove the connection from GPIO2 to EN/RST.

          1. I have exactly the same problem. Any GPIO pin when taken LOW will keep the EN/RST in a continuous reboot loop. It does not get initialized back to HIGH when set to do so on a reboot. Some GPOI pins keep the EN/RST logic HIGH making the reset button become useless. And the ESP.reset does not clear old data.

            1. void resetFireBeetle() {
              pinMode(RESET_PIN, OUTPUT);
              digitalWrite(RESET_PIN, LOW);
              }

              The RESET_PIN is in my case GPIO21. It is wired by a jumper to the FireBeetle RST:pin.

              GPIO21 ——-o o——- RST

              On uploading the arduino sketch, the jumper must be removed.
              After uploading, the jumper must be inserted, otherwise, uploading is not possible.

              It is important, that GPIO21 stays in INPUT Mode from SETUP() until resetFireBeetle() is called.

            2. What if you were to use GPIO3 (RX)? That is High at boot by default. As long as you’re not sending anything to the board over serial, that should work, shouldn’t it?

Leave a Reply

Discover more from techtutorialsx

Subscribe now to keep reading and get access to the full archive.

Continue reading