https://medium.com/@ronald.dehuysser/micropython-ota-updates-and-github-a-match-made-in-heaven-45fde670d4eb
https://pythonforundergradengineers.com/flask-iot-server-upload-code-to-esp8266.html
lister les ports usb sur mac os
ls /dev/t
ty.*
Probleme sur mac ne fonctionne pas!!!!
Installer le driver ch340/ch341 pour l'esp
NOn http://www.wch-ic.com/search?q=ch340&t=downloads
Installer esptool
python -m pip install esptool
Connaitre la taille mémoire esp
python -m esptool --port COM5 flash_id
Erase flash
python -m esptool --chip esp8266 --port COM5 erase_flash
installer firmware
python -m esptool --chip esp8266 --port COM5 write_flash --flash_mode dio --flash_size detect 0x0 esp8266o.bin
https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers
Télécharger firmware micropython ota:
https://micropython.org/download/esp8266/
Sources :
https://projetsdiy.fr/installer-le-drivers-ch340x-sur-macos-pour-wemos-d1-mini/
Flashing MicroPython Firmware with esptool.py on ESP32 and ESP8266
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.
If you liked this post, you might like our next ones, so make sure you subscribe to the RNT blog and download our free electronics eBooks.
9 thoughts on “Flashing MicroPython Firmware with esptool.py on ESP32 and ESP8266”
Leave a Comment
Worked perfectly while using Thonny 3.1.2 on Ubuntu; watch out for the micro USB cable without the data wires!! (luckily I have like 10 cables)
A way to check if your issue is with your cable is before you plug in the ESP, type in terminal lsusb and then plug in your ESP and type lsusb again and compare the two. If nothing changes try another cable.
Using USB without data wires is a frequent mistake.
Thanks for sharing that tip.
Regards,
Sara
Your tutorials are great! Thank you!
Thanks
Great ! I tried once and work perfectly
For me as beginner I suggest to add commands “pip install rshell” then “rshell -p COMx repl” once flashing completed, so beginner can test the micropython firmware on their board.
Thanks
Thank you worked first time. Good job
Hi,
When trying to flash ESP32, get the following result:
‘could not open port 17 FileNotFound Error (2, The system cannot find the file specified, None, 2)’
Have checked & port 17 is the correct port.
Hello and thank you.
This is the tutorial that works on the first connection.
Only info to USB cables, I will confirm what has already been mentioned and all USB cables need to be sorted and marked, or for example divided into plastic bags, together only charging and together data and some older ones can also be thrown away in separate collection.
The firmware download page for the ESP32, https://micropython.org/download/esp32/ offers multiple versions of the firmware. The most current version at this time, esp32-20210418-v1.15.bin, is missing some standard modules, including urequests. You can install the urequests module (from PyPI) in the /lib folder of your ESP32 using “Manage packages…” under the “Tools” tab of Thonny. You will be offered multiple choices. I’m currently testing micropython-urequests, version 0.9.1 from Paul Sokolovsky.
Furthermore, in some situations, such as using the _thread module for multithreading, you can expect problems that differ depending on the firmware that you are using on the ESP32. In my situation, using firmware: esp32-idf4-20210202-v1.14.bin or esp32-idf3-20210202-v1.14.bin results in corruption of the WiFi DNS settings and OSErrors in the urequest modules packaged in those firmware versions. Others see this on other boards: https://github.com/micropython/micropython/issues/6492