Flash MicroPython Onto An ESP32

Updated 08 February 2019

The ESP32 family of microcontrollers are incredibly powerful (2 Cores on a Microcontroller!) and when combined with the awesome writability of MicroPython can be used for all kinds of projects.

The ESP32 generally does not come with MicroPython flashed onto it (You can also program them with C in the Arduino IDE!), so before we can start coding in Python we need to install the MicroPython firmware.

What we need.

Install esptool

The Python Community has created a tool for the ESP family of boards, creatively named esptool, this tool will allow us to do a bunch of things with the esp boards including flash the MicroPython Firmware onto the boards. The easiest way to install it is to use the PyPi repositories to install it with the command. 

pip install esptool

Once it has finished downloading it will let you know it was successfully installed or not.

Note: If you are on a Linux system and you get permission errors, run the command again with sudo.

Download the Latest Firmware.

Now that we have the tools we need to write the firmware image to the ESP32 we need to get the image to write onto the board. The images are available directly from the MicroPython Website in the downloads section.  Choose the latest version of the ESP32 firmware and download it somewhere that you will be able to remember. I am going to download a folder on a thumb drive D:\MicroPython because user folders in windows are annoying to navigate to in the terminal.

Firmware saved onto flash drive

Connect the ESP32

This step is easy all you need to do is plug the USB cable into the ESP32, most of the Dev boards can automatically put themselves into write mode. There may be some variants that need special steps but they should be provided by the Manufacturer of your dev board. 

Plug USB cable into the ESP 32

Update the Firmware

We can now open a terminal window and use the command mode in windows or ls /dev/serial in Linux.

Now that we have the tools, the firmware and everything connected we can install the firmware. To do this we move our working directory to where the firmware file is located.

We can then run the esptool.py command below (make sure you change the Port Number and Firmware name)

esptool.py --chip esp32 --port COM45 write_flash -z 0x1000 D:/micropython/esp32Firmware.bin

Hint: If you start typing in the firmware name and press tab it will autocomplete. 

We will have a quick look at what the options we for this command are doing: 

--chip Selects the type of ESP board you will be interacting with we will choose the ESP32 though this tool can work with any esp family board

--port Selects the port that the ESP board is connected to in windows it will usually be COM## and on Linux, it will look more like /dev/tty####

write_flash This is the operation we want to run. 

-z 0x1000 This will tell the tool where to start writing the firmware in the memory on the chip. For the ESP32 we need to start writing at address number 0x1000.

esp32Firmware.bin The name of the firmware file you downloaded in the earlier step. This will change with every version they release. 

If you want to find out more about the available functions and options in the esptool you can have a look at the documentation on the esptool project GitHub page

 Terminal output for flashing MicroPython to ESP32

Once the tool has run you will be able to send Python code to your esp32 or connect to it using REPL.

Thanks for following this tutorial and if you want to know more about Coding in MicroPython we have a MicroPython Workshop as well as MicroPython Tutorials that you can follow.

That is everything we need to do to start programming on the ESP32!

If you have any questions on anything covered in this article, or just want to share your own ideas, please, join in the discussion with our community of dedicated makers.

Have a question? Ask the Author of this guide today!

Please enter minimum 20 characters

Your comment will be posted (automatically) on our Support Forum which is publicly accessible. Don't enter private information, such as your phone number.

Expect a quick reply during business hours, many of us check-in over the weekend as well.

Comments


Loading...
Feedback

Please continue if you would like to leave feedback for any of these topics:

  • Website features/issues
  • Content errors/improvements
  • Missing products/categories
  • Product assignments to categories
  • Search results relevance

For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.

Makers love reviews as much as you do, please follow this link to review the products you have purchased.