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.
- Python 3.x (On windows it will need to be added to system path)
- Adafruit HUZZAH32, SparkFun ESP32 Thing, Beetle ESP32, or any other variant of the Espressif ESP32.
- USB Cable
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.
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.
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.
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.