This posts shows how to flash MicroPython firmware on ESP32/ESP8266 boards using the esptool.py. It works on Windows, Mac OS X, and Linux. For the official documentation, you can visit the esptool.py GitHub page.

Tip: for an easier method to flash the ESP32/ESP8266 with MicroPython, we recommend reading this guide to flash MicroPython with uPyCraft IDE. However, we’ve recently received comments from our readers about having trouble installing/using uPyCraft IDE. For that reason, we’re posting an alternative method using the esptool.py software.
Installing esptool.py in your computer
To work with esptool.py, you’ll need either Python 2.7, Python 3.4 or a newer Python installation on your system. We recommend using Python 3.7.X, so go to Python’s website and install it in your computer.
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
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.py. In your Terminal window, run the following command:
esptool.py
If it was installed properly, it should display a similar message (regardless of your operating system):
With esptool.py installed in your computer, you can easily flash your ESP32 or ESP8266 boards with the MicroPython firmware. This post is divided in two parts, read Part 1 or Part 2 depending on your board:
- Part 1 – ESP32
- Part 2 – ESP8266
Note: after installing MicroPython firmware on your ESP32 or ESP8266, you can go back and use Arduino IDE again. You just need to upload code using Arduino IDE. Then, if you want to use MicroPython again, you need to flash MicroPython firmware.
[Part 1 – ESP32] Downloading and Flashing the MicroPython Firmware on ESP32
To download the latest version of MicroPython firmware for the ESP32, go to the MicroPython Downloads page and scroll all the way down to the ESP32 section.
You should see a similar web page (see figure below) with the latest link to download the ESP32 .bin file – for example: esp32-20181007-v1.9.4-631-g338635ccc.bin.

Note: if you’re using a different board (like a PyBoard, WiPy, or other), go to MicroPython Downloads page and download the right firmware for your board.
Finding the Serial Port Name
It’s a bit different to find the Serial port name in each operating system, so for simplicity reasons we recommend finding your ESP serial port name through the Arduino IDE. Follow these steps:
- Connect your board to your computer
- Open the Arduino IDE
- Go to Tools > Port
- Save your ESP32 serial port name (in our case it’s COM7)
- Close your Arduino IDE software

Important: if you plug your ESP32 board to your computer, but you can’t find the ESP32 Port available in your Arduino IDE, it might be one of these two problems: 1. USB drivers missing or 2. USB cable without data wires.
1. If you don’t see your ESP’s COM port available, this often means you don’t have the USB drivers installed. Take a closer look at the chip next to the voltage regulator on board and check its name.
The ESP32 DEVKIT V1 DOIT board uses the CP2102 chip.

Go to Google and search for your specific chip to find the drivers and install them in your operating system.

You can download the CP2102 drivers on the Silicon Labs website.

After they are installed, restart the Arduino IDE and you should see the serial port in the Tools > Port menu.
2. If you have the drivers installed, but you can’t see your device, double-check that you’re using a USB cable with data wires.
USB cables from powerbanks often don’t have data wires (they are charge only). So, your computer will never establish a serial communication with your ESP32. Using a proper USB cable should solve your problem.
Finding your MicroPython .bin file
After downloading the ESP32 .bin file, it should be in your Downloads folder. So, with your Terminal window, you’ll need to navigate to the Downloads folder using the cd command:
cd Downloads

List all files in your Downloads folder to ensure that’s where the .bin file is located. In Windows, you use:
dir
On Mac OS X or Linux, run the next command:
ls

As you can see in the preceding screenshot, the ESP32 .bin file is located in the Downloads folder: esp32-20190113-v1.9.4-779-g5064df207.bin.
Erasing ESP32 Flash Memory
Before flashing the MicroPython firmware, you need to erase the ESP32 flash memory. So, with your ESP32 connected to your computer, hold-down the “BOOT/FLASH” button in your ESP32 board:

While holding down the “BOOT/FLASH” button, run the following command to erase the ESP32 flash memory:
esptool.py --chip esp32 erase_flash
When the “Erasing” process begins, you can release the “BOOT/FLASH” button. After a few seconds, the ESP32 flash memory will be erased.

Note: if after the “Connecting …” message you keep seeing new dots appearing, it means that your ESP32 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 ESP32 goes into flashing mode and completes the erasing process successfully.

Flashing MicroPython Firmware on ESP32 with esptool.py
With your ESP32 flash memory erased, you can finally flash the MicroPython firmware. You need your serial port name (COM7 in our case) and the ESP32 .bin file location. Replace the next command with your details:
esptool.py --chip esp32 --port <serial_port> write_flash -z 0x1000 <esp32-X.bin>
In our case, the final command looks like this:
esptool.py --chip esp32 --port COM7 write_flash -z 0x1000 esp32-20190113-v1.9.4-779-g5064df207.bin
Hold down the “BOOT/FLASH“, before running the flash command. After a few seconds this is what you should see:
Your ESP32 was successfully flashed with MicroPython firmware!
Note: if you receive an error trying to flash the firmware, run the command again and make sure you are holding down the ESP32 “BOOT/FLASH” button.

[Part 2 – ESP8266] Downloading and Flashing the MicroPython Firmware on ESP8266
To download the latest version of MicroPython firmware for the ESP8266, go to the MicroPython Downloads page and scroll all the way down to the ESP8266 section.
You should see a similar web page (see figure below) with the latest link to download the ESP8266 .bin file – for example: esp8266-20180511-v1.9.4.bin.

Note: if you’re using a different board (like a PyBoard, WiPy, or other), go to MicroPython Downloads page and download the right firmware for your board.
Finding the Serial Port Name
It’s a bit different to find the Serial port name in each operating system, so for simplicity reasons we recommend finding your ESP serial port name through the Arduino IDE. Follow these steps:
- Connect your board to your computer
- Open the Arduino IDE
- Go to Tools > Port
- Save your ESP8266 serial port name (in our case it’s COM4)
- Close your Arduino IDE software

Important: if you plug your ESP8266 board to your computer, but you can’t find the ESP8266 Port available in your Arduino, it might be one of these two problems: 1. USB drivers missing or 2. USB cable without data wires.
1. If you don’t see your ESP’s COM port available, this often means you don’t have the USB drivers installed. Take a closer look at the chip next to the voltage regulator on board and check its name.
The ESP8266 ESP-12E NodeMCU board uses the CP2102 chip.

Go to Google and search for your specific chip to find the drivers and install them in your operating system.

You can download the CP2102 drivers on the Silicon Labs website.

After they are installed, restart the Arduino IDE and you should see the serial port in the Tools > Port menu.
2. If you have the drivers installed, but you can’t see your device, double-check that you’re using a USB cable with data wires.
USB cables from powerbanks often don’t have data wires (they are charge only). So, your computer will never establish a serial communication with your ESP8266. Using a proper USB cable should solve your problem.
Finding your MicroPython .bin file
After downloading the ESP8266 .bin file, it should be in your Downloads folder. So, with your Terminal window, you’ll need to navigate to the Downloads folder using the cd command:
cd Downloads

List all files in your Downloads folder to ensure that’s where the .bin file is located. In Windows, you use:
dir
On Mac OS X or Linux, run the next command:
ls

As you can see in the preceding screenshot, the ESP8266 .bin file is located in the Downloads folder: esp8266-20180511-v1.9.4.bin.
Erasing ESP8266 Flash Memory
Before flashing the MicroPython firmware, you need to erase the ESP8266 flash memory. So, with your ESP8266 connected to your computer, hold-down the “BOOT/FLASH” button in your ESP8266 board:

While holding down the “BOOT/FLASH” button, run the following command to erase the ESP8266 flash memory:
esptool.py --chip esp8266 erase_flash
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 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.
Flashing MicroPython Firmware on ESP8266 with esptool.py
With your ESP8266 flash memory erased, you can finally flash the MicroPython firmware. You need your serial port name (COM7 in our case) and the ESP8266 .bin file location. Replace the next command with your details:
esptool.py --chip esp8266 --port <serial_port> write_flash --flash_mode dio --flash_size detect 0x0 <esp8266-X.bin>
In our case, the final command looks like this:
esptool.py --chip esp8266 --port COM4 write_flash --flash_mode dio --flash_size detect 0x0 esp8266-20180511-v1.9.4.bin
Hold down the “BOOT/FLASH“, before running the flash command. After a few seconds this is what you should see:
Your ESP8266 was successfully flashed with MicroPython firmware!
Note: if you receive an error trying to flash the firmware, run the command again and make sure you are holding down the ESP8266 “BOOT/FLASH” button.
Wrapping Up
We hope you’ve found this tutorial useful. Your ESP32/ESP8266 should now be flashed with MicroPython firmware. To learn more about MicroPython read: Getting Started with MicroPython on ESP32 and ESP8266.
Reference of this projec is taken from https://randomnerdtutorials.com/
19 thoughts on “Flashing MicroPython Firmware with esptool.py on ESP32 and ESP8266”