[EN] How To Compile MicroPython To Use With ESP32.

This article outlines the steps for compiling MicroPython with an ESP32 board with Linux operating systems running on Windows 10 or WSL version 1 or 2 to write the resulting binary files onto the ESP32 board.


  1. Install WSL from the steps as written on this website.
    Windows Subsystem for Linux Installation Guide for Windows 10
  2. From the Windows Store, select to install Ubuntu 18.04.
  3. Open Ubuntu 18.04 and install what you need.
    sudo apt install build-essential git python3 python3-dev python3-pip python3-setuptools python3-venv
    1. sudo pip3 install –upgrade virtualenv==16.7.9
  4. Download MicroPython
    1. cd ~
    2. git clone –recurse-submodule https://github.com/micropython/micropython.git
  5. Find the ID of the ESP-IDF to use for the espressif web download and the version used for MicroPython.
    1. cd ~/micropython/ports/esp32
    2. make ESPIDF=
    3. Copy the text beghind supported git hash (V4.x): to use in the installation process.
  6. Download ESP-IDF
    1. export ESPIDF=$HOME/esp-idf
    2. mkdir -p $ESPIDF
    3. cd $ESPIDF
    4. git clone https://github.com/espressif/esp-idf.git $ESPIDF
    5. git checkout the text obtained from step 5
    6. git submodule update –init –recursive
  7. Install ESP-Tools
    1. ./install.sh
    2. Once the installation is complete, run export.sh to make the installed tools directory visible.
      . ./export.sh
  8. Compile mpy-cross, a Python interpretation tool into bytecode. This makes it possible to put it on the board without having to provide the source code. It Saves ROM space and reduce interpretation time.
    1. cd ~/micropython/mpy-cross
    2. make
  9. venv is required to install the Python system libraries used with MicroPython without affecting the base system libraries. The process of creating a virtual environment is as follows:
    1. In the case that the virtual environment system has never been built before
      1. cd ~/micropython/ports/esp32
      2. venv viren
      3. . viren/bin/activate
      4. pip install –upgrade pip
      5. pip install -r $ESPIDF/requirements.txt
    2. If it is already built, you can run the virtual environment from the following command.
      . viren/bin/activate
  10. Complie MicroPython
    1. For general boards
      1. cd ~/micropython/ports/esp32
      2. make clean
      3. make submodyles
      4. make BOARD=GENERIC
    2. or for boards with SPIRAM
      1. cd ~/micropython/ports/esp32
      2. make clean
      3. make submodyles
  11. Exporting firmware for general board to Drive D
    cp build-GENERIC/firmware.bin /mnt/d

    or for boards with SPIRAM
    cp build-GENERIC_SPIRAM/firmware.bin /mnt/D


From this article, it can be said that we’ve outlined the steps for compiling MicroPython to use on a DIY ESP32 board. Along with this, we have the mpy-cross tool for compiling MicroPython code to implement. This saves space and reduces interpreatation time as well.

Finally, we hope that this article will be useful to some readers. Have fun programming.

(C) 2020, By Jarut Busarathid and Danai Jedsadathitikul
Updated 2021-09-03