ESP8266 NodeMCU: Erase Flash Memory (Factory Reset)

This quick guide provides instructions on how to erase the ESP8266 NodeMCU flash memory to restore it to its original state. We’ll be using a tool called esptool.py. Restoring the ESP8266 to its factory settings might be useful if you want to delete any changes made to the firmware or configuration settings; if the system is crashing constantly and you can’t upload new code; to clear data that is no longer needed, and other applications.

ESP8266 NodeMCU Erase Flash Memory Factory Reset esptool.py

Installing esptool.py

To perform an ESP8266 factory reset, we’ll use esptool, which is “a Python-based, open-source, platform-independent utility to communicate with the ROM bootloader in Espressif chips.

To install esptool, you need Python 3.7 or newer installed on your system. You can download and install Python at the following link (make sure you download the right package for your system):

With Python 3 installed, open a Terminal window and install the latest stable esptool.py release with pip:

pip install esptool

Note: with some Python installations that command may not work and you’ll receive an error. If that’s the case, try to install esptool.py with:

  • pip3 install esptool
  • python -m pip install esptool
  • pip2 install esptool

Setuptools is also a requirement that is not available on all systems by default. You can install it with the following command:

pip install setuptools

After installing, you will have esptool.py installed into the default Python executables directory and you should be able to run it with the command esptool. In your Terminal window, run the following command:

python -m esptool

If it was installed properly, it should display a similar message (regardless of your operating system):

esptool utility

Erasing the ESP8266 NodeMCU Flash

Follow the next steps to erase the ESP8266 flash:

1) Connect the ESP8266 board to your computer;

2) Open a Terminal window on your computer;

3) Hold the ESP8266 BOOT/FLASH button;

ESP8266 BOOT button

4) Copy the following command to your terminal window and press Enter (continue holding the FLASH/BOOT button).

python -m esptool --chip esp8266 erase_flash

5) When the “Erasing” process begins, you can release the “BOOT/FLASH” button. After a few seconds, the ESP8266 flash memory will be erased.

esptool esp8266 erase flash

Note: if after the “Connecting …” message you keep seeing new dots appearing, it means that your ESP8266 board is not in flashing mode. You need to repeat all the steps described earlier and hold the “BOOT/FLASH” button again to ensure that your ESP8266 goes into flashing mode and completes the erasing process successfully.

Troubleshooting

If you encounter a permission error while trying to run the esptool command, open the command prompt as a administrator (or as sudo on Linux).

run commands as an administrator command prompt

Wrapping Up

In this quick guide, we’ve shown you how to erase the ESP8266 flash to perform a factory reset. We hope this tutorial is useful.

If you’re using an ESP32 board, you can follow the instructions in the following tutorial:

If you would like to learn more about the ESP8266 board and IoT, make sure you take a look at our resources:

Thanks for reading.



Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »
Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »

Enjoyed this project? Stay updated by subscribing our newsletter!

7 thoughts on “ESP8266 NodeMCU: Erase Flash Memory (Factory Reset)”

  1. sadly all of the python commands did nothing other than produce an “Invalid syntax” warning in Terminal like this

    pip install esptool
    File “”, line 1
    pip install esptool
    ^^^^^^^
    SyntaxError: invalid syntax
    This is on an iMac running OS 12.6.7.
    So I am all at sea unable to to clear the flash memory in case it is that that is stopping the ESP8266 from connecting to wifi.

    Reply
  2. Following my first post:
    This is only a problem for folk who use “The Most Advanced Operating System in the World”.
    The pip command is unknown if a Mac owner goes through the palaver of navigating terminal into the Python directory and running the commands from in there.
    For the poorer 99% of us using (the superseded) Windows10 OS, the instructions on this page work wonderfully and my Flash memory was deleted in a flash.

    Reply
    • Hi.
      Try to keep pressing the BOOT and reset button several times while you try to run the command to run the command to erase flash, so that you can catch it on boot mode.
      Regards,
      Sara

      Reply
  3. Hi,

    Thanks for all those amazing tutorials. I would like to perform this flash in a Wemos D1 ESP8266. This board only has a RESET button, so how can I put it in flash mode?

    Regards,
    Gabriel

    Reply

Leave a Comment

Download Our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.