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.
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):
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;
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.
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).
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:
- Home Automation using ESP8266
- Build Web Servers with ESP32 and ESP8266
- Firebase Web App with ESP32 and ESP8266
- Free ESP8266 Projects and Tutorials
Thanks for reading.
can you please upload a project based on canteen management using EM-18 module by ESP32
sadly all of the python commands did nothing other than produce an “Invalid syntax” warning in Terminal like this
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.
After a program mistake, I blocked serial – so no chance to write again
Any tips are welcome
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
By default it is taking as COM3. May I please know how do I change it?
Go to Device Manager and then Right Click the option ending with (COM3) listed under
Ports (COM & LPT) while your esp8266/esp32 is connected with your PC. Then in the dialog box select properties. Then in the Properties menu tab click Port Settings then click on Advanced… then in the Advanced Setting tab Select your desired COM which you want to set it to under COM Port number . After setting your desired COM Port number click ok to exit the Advanced Setting tab and then click ok to exit the Properties tab .Then exit the Device Manager.
And with this you will be able to change your COM3 to your desired COM port number.
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
Have the same issue with a Wemos D1R2
same case with me
Let’s wait for @rui santos’ answer