Getting Started with Thonny MicroPython (Python) IDE for ESP32 and ESP8266

If you want to program your ESP32 and ESP8266 with MicroPython firmware, it’s very handy to use an IDE. In this guide, we’ll introduce you to Thonny IDE. After completing this guide, you’ll have your first LED blinking using MicroPython and Thonny IDE.

We’ve experimented with several IDEs to program the ESP32 and ESP8266 boards using MicroPython, and Thonny seemed a good choice. Although there are some bugs, it is constantly being updated and improved.

It allows you to program your ESP32 and ESP8266 boards with MicroPython, and it is compatible with Windows, Mac OS X, and Linux. It even comes installed by default with Raspbian OS for Raspberry Pi. Additionally, it’s easy to install, so you shouldn’t have problems with the installation process.

Note: we’ve also experimented with uPyCraft IDE and it worked fine for us. However, some readers had trouble using uPycraft IDE. So, here we provide another great IDE to program your ESP32/ESP8266 boards using MicroPython.

If you want to use uPyCraft IDE instead, follow one of the installation tutorials below:

Downloading and Flashing MicroPython Firmware

Unlike other boards, MicroPython isn’t flashed onto the ESP32 or ESP8266 by default. That’s the first thing you need to do to start programming your boards with MicroPython: flash/upload the firmware.

Follow the next tutorial to flash MicroPython firmware on your board using

Installing Thonny IDE

In this guide, we provide instructions to install Thonny IDE in different operating systems, read the section that fits your needs:

  • A) Installing Thonny IDE – Windows PC
  • B) Installing Thonny IDE – Mac OS X
  • C) Installing Thonny IDE – Linux

Tip: Thonny IDE comes installed by default on Raspbian OS that is used with the Raspberry Pi board.

A) Installing Thonny IDE – Windows PC

To install Thonny on your Windows PC, follow the next instructions:

1. Go to

2. Download the version for Windows and wait a few seconds while it downloads.


3. Run the .exe file.

4. Follow the installation wizard to complete the installation process. You just need to click “Next”.

5. After completing the installation, open Thonny IDE. A window as shown in the following figure should open.


B) Installing Thonny IDE – Mac OS X

Since Thonny IDE is open source and downloaded from the Internet, it’s not a verified app in the App Store. For security reasons, Mac OS X blocks unknown apps to run on your computer. Follow these next instructions to enable any downloaded software to run in your Mac.

1. Open the “System Preferences...” menu.

2. Open the “Security & Privacy” menu.

3. At the bottom left corner, click the lock icon to modify your “Security & Privacy” settings:

4. Type your username/password and click the “Unlock” button.

5. Finally, select the option “Allow apps downloaded from: Anywhere“.

That’s it, you can close that window.

To install Thonny on Mac OS X, follow the next instructions:

1. Go to

2. Download the version for Mac OS X and wait a few seconds while it downloads.

3. Open the .dmg file.

4. Drag the “Thonny” application to your Desktop:

5. Thonny IDE is now installed and you can double-click to open it:

6. After the installation is completed, open Thonny IDE. A window as shown in the following figure should open.

C) Installing Thonny IDE – Linux

To install Thonny on your Linux computer, it depends on your Linux distribution and version, follow the next instructions for your system. First, we recommend installing these dependencies: python3, python3-pip, and python3-tk

If you’re in Ubuntu, you can install the Python dependencies like this:

sudo apt install python3 python3-pip python3-tk

After having Python3, pip3, and Python3 Tkinter, you can install Thonny IDE.

  • Ubuntu (after running that command, you’ll need to press Enter again to install the software):
bash <(wget -O -
  • Or you can install Thonny IDE with pip3:
sudo pip3 install thonny
  • Fedora since 27:
sudo dnf install thonny
  • Raspbian since Stretch (installed by default):
sudo apt install python3-thonny

After installing Thonny IDE and depending on your installation method, to open Thonny IDE:

  • You either need go to the search bar and type “Thonny” to find it
  • Or if you installed Thonny IDE using pip3, you can type in your terminal window:

Then, it should open Thonny IDE:

Testing the Installation

Important: before testing the installation, your ESP32/ESP8266 board needs to be flashed with MicroPython firmware.

Connect the board to your computer using an USB cable. To test the installation, you need to tell Thonny that you want to run MicroPython Interpreter and select the board you are using.

1. Go to Tools > Options and select the Interpreter tab.

2. Choose MicroPython on a generic device.

3. Then, select your device serial port (recommended).

You can also select the “Try to detect automatically” option, but only if you just have one board connected to your computer at a time. Otherwise, select the specific port for the board you’re using.

4. Thonny IDE should now be connected to your board and you should see the prompt on the Shell.

5. Type the command help() in the Shell and see if it responds back.

If it responded back, everything is working fine. Now, you can send a few more commands to test.

Send the following commands to light up the on-board LED

>>> from machine import Pin
>>> Pin(2, Pin.OUT).value(1)

If you’re using an ESP8266, the logic to turn on the LED works the other way around, so you should send the following command instead:

>>> Pin(2, Pin.OUT).value(0)

The on-board LED should light up.

Then, turn off the led:

>>> Pin(2, Pin.OUT).value(0)

Congratulations! Your installation was successful!

Thonny IDE Overview

At this point, you should have:

  • Thonny IDE installed on your computer
  • ESP32/ESP8266 flashed with MicroPython firmware

Open Thonny IDE. There are two different sections: the Editor and the MicroPython Shell/Terminal:

  • The Editor section is where you write your code and edit your .py files. You can open more than one file, and the Editor will open a new tab for each file.
  • On the MicroPython Shell you can type commands to be executed immediately by your ESP board without the need to upload new files. The terminal also provides information about the state of an executing program, shows errors related with upload, syntax errors, prints messages, etc…

You can also customize Thonny IDE to show other useful tabs. Go to View and you can select several tabs that provide more information.

Something that could be very useful is the Variables tab. It lists all available variables in your program and their corresponding values.

Running Your First Script

To get you familiar with the process of writing a file and executing code on your ESP32/ESP8266 boards, we’ll upload a new script that simply blinks the on-board LED of your ESP32 or ESP8266.

Creating the file on your board

1. When you open Thonny IDE for the first time, the Editor shows an untitled file. Save that file as Simply, click the save icon and name the file

2. The Editor should now have a tab called

3. Copy the following code to the file:

from machine import Pin
from time import sleep
led = Pin(2, Pin.OUT)
while True:
  led.value(not led.value())

Uploading the Script

Go to Device and select Upload current script as main script.

It should write the following on the Shell.

Note: uploading the code as main script will save the current file with the name on the ESP, even if you have saved it in your computer with a different name. The same happens for the file.

Important: when the ESP restarts, first it runs the file and afterwards the

After uploading the script, press the ESP EN/RESET button.

The ESP on-board LED should be blinking.

Congratulations, you’ve successfully uploaded a new script to your ESP32/ESP8266 using Thonny IDE.

List Files Saved on ESP32/ESP8266

To list all files saved on the ESP board, type in the Shell:


Show File Content

To show the file content, use %cat / followed by the file path. For example:

%cat /

Alternatively, to show the and scripts, you can also go to Device and select one of the options: Show device’s main script or Show device’s boot script.

Uploading Files/Libraries

To upload a file with a unique name to your ESP using Thonny IDE, follow these next steps:

  • Create a new file
  • Save it in your computer with the exact name that you want, for example “”

  • Go to Device > Upload current script with current name

  • The file should be saved on the ESP with the name “”
  • You can list the files stored in your ESP board with the command %lsdevice:

That’s it! The file was uploaded to your board. You can see the file content using the %cat / command:

Removing/Deleting File from ESP

At the moment, Thonny IDE doesn’t have a command to remove a file from the ESP. So, in order to remove/delete all files completely from your ESP, you need to re-flash it with MicroPython firmware.

Note: you can upload a blank script to the ESP board to remove/delete code.

Troubleshooting Tips for Thonny IDE

We’ve discovered some common problems and error messages that occur with Thonny IDE. Usually restarting your ESP with the on-board EN/RST button fixes your problem. Or pressing the Thonny IDE “Stop/Restart backend” button and repeating your desired action. In case it doesn’t work for you, read these next common errors and discover how to solve them.

Error #1: You get one of the following messages:

========================= RESTART =========================
Unable to connect to COM4
Error: could not open port 'COM4': FileNotFoundError(2, 'The system cannot find the file specified.', None, 2)

Check the configuration, select Run → Stop/Restart or press Ctrl+F2 to try again. (On some occasions it helps to wait before trying again.)


========================= RESTART =========================
Could not connect to REPL.
Make sure your device has suitable firmware and is not in bootloader mode!


========================= RESTART =========================
Lost connection to the device (EOF).

Unplug, and plug back your ESP board. Then, double-check that you’ve selected the right serial port in the Tools > Options > Interpreter > Port. Then, click the “Stop/Restart backend” button to establish a serial communication. You should now be able to upload a new script or re-run new code.

These errors might also mean that you have your serial port being used in another program (like a serial terminal or in the Arduino IDE). Double-check that you’ve closed all the programs that might be establishing a serial communication with your ESP board. Then, unplug and plug back your ESP board. Finally, restart Thonny IDE.

Error #2: Thonny IDE fails to respond or gives an Internal Error:

When this happens, you can usually close that window and it will continue to work. If it keeps crashing, we recommend restarting the Thonny IDE software.

Error #3: Thonny IDE hangs when pressing “Stop/Restart backend” button:

When you press the “Stop/Restart backend” button, you need to wait a few seconds. The ESP needs time to restart and establish the serial communication with Thonny IDE. If you press the “Stop” button multiple times or if you press the button very quickly, the ESP will not have enough time to restart properly and it’s very likely to crash Thonny IDE.

Error #4: Problem restarting your ESP board, running a new script or opening the serial port:

Brownout detector was triggered

Or if the ESP keeps restarting and printing the ESP boot information:

ets Jun 8 2016 00:22:57 

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) 
configsip: 0, SPIWP:0xee 
mode:DIO, clock div:2 

The “Brownout detector was triggered” error message or constant reboots  means that there’s some sort of hardware problem. It’s often related to one of the following issues:

  • Poor quality USB cable;
  • USB cable is too long;
  • Board with some defect (bad solder joints);
  • Bad computer USB port;
  • Or not enough power provided by the computer USB port.

Solution: try a different shorter USB cable (with data wires), try a different computer USB port or use a USB hub with an external power supply.

Important: if you keep having constant problems or weird error messages, we recommend re-flashing your ESP board with the latest version of MicroPython firmware: Flash/Upload MicroPython Firmware to ESP32 and ESP8266.

Error #5: When I try to establish a serial communication with the ESP32/ESP8266 in Thonny IDE, I can’t get it to connect.

We think this is what’s happening: when you’re running a script in your board, sometimes it’s busy running that script and performing the tasks.

So, you need to try start the connection by pressing “Stop/Restart backend” button multiple times or restart the ESP to catch available to establish the serial communication.

Warning: don’t press the “Stop/Restart backend” button multiple times very quickly. After pressing that button, you need to be patient and wait a few seconds for the command to run.

If you’re running a script that uses Wi-Fi, deep sleep, or it’s doing multiple tasks, I recommend trying 3 or 4 times to establish the communication. If you can’t, I recommend re-flash the ESP with MicroPython firmware.

Error #6: debug tools are grayed out:

Thonny IDE debug tools aren’t available for MicroPython. The debug tools are only available for the Python Interpreter, so being grayed out is the expected behavior.

Wrapping Up

Thonny IDE is a great IDE to program the ESP32 and ESP8266 boards using MicroPython. It is compatible with Windows, Mac OS X, and Linux and it easy to install.

We have other tutorials to program the ESP32 and ESP8266 boards with MicroPython using uPyCraft IDE. If you want to experiment with uPyCraft IDE, you can take a look at some of the following tutorials:

More tutorials about MicroPython with ESP32 and ESP8266:

Learn more about MicroPython with our eBook:

Thanks for reading.

Build Web Server projects with the ESP32 and ESP8266 boards to control outputs and monitor sensors remotely. Learn HTML, CSS, JavaScript and client-server communication protocols DOWNLOAD »

Build Web Server projects with the ESP32 and ESP8266 boards to control outputs and monitor sensors remotely. Learn HTML, CSS, JavaScript and client-server communication protocols DOWNLOAD »

Enjoyed this project? Stay updated by subscribing our newsletter!

27 thoughts on “Getting Started with Thonny MicroPython (Python) IDE for ESP32 and ESP8266”

  1. Thonny 3.1.2 – The run current script button (the green circle with ‘play’ symbol) works instead of having to “upload current script as main script” and then having to reset the board.

  2. Hello ! The function >>> %lsdevice doesn’t work on Thonny installed on RaspBian, but it works on my MacOS. Do you know what’s the problem ?

    • Hi Vincent.
      I’m sorry but I don’t know why that happens.
      I use Thonny IDE on windows.
      Make sure your Thonny IDE is configured properly to use micropython and not Python.

  3. Python 38 on Windows 10
    Thonny 3.27 in Python
    MicroPython 1.12

    It seems to be a big difference against the versions are used in your tutorial:
    %lsdevice >>> not working
    %cat / >>> not working
    Device doesn’t show “commands”

  4. Hi Sara, help me please.
    I’m using the Thonny IDE in Raspbian. I can connect to ESP32 and run the script. But when I try to upload the “” script on ESP32 by clicking on “device” the option “Upload current script as main script” does not exist. When I click on “device” appears “Where are all the commands?” And the following message appears: “MicroPython commands have been moved or replaced:”
    Can you help me?

    • Hi Bruno.
      That happens on the most recent versions of Thonny.
      You need to go to File > Save Copy and then select MicroPython device.
      Give the file a name, in this case and then save it.
      I hope this helps.

  5. I am using pyboard micropython V1.1
    Can’t get it to recognize Ctrl-E or any of the other REPL commands.
    Also, fails with

      • Yes. But after reading about and experimenting with Thonny, it’s really designed for ESP32. It’s not suited for STM32.
        Frustrating to me is that another IDE, Mu, is the same–ideal for ESP32 or CircuitPython, but not for any MicroPython running on a STM32. I’m an EE with 45 years of experience. I’ve used MicroPython on ESP32, STM32, and CircuitPython on ATSAM’s. Of all of them, only the STM32 with MicroPython is adequate for industrial use because of advanced professional features such as: interrupt handling, embedded assembly code, direct register addressing, asyncio task scheduling, and industrial/automotive rated hardware. The others are GREAT for teaching and learning programming and basic hardware interfacing. And Thonny is wonderful to use with my ESP32 boards.

        • I’m sorry about that.
          We don’t have any tutorials about the Pyboard.
          I haven’t experimented with that board, so I can’t recommend any particular IDE.
          Have you experimented, for example: PyCharm with MicroPython plugin or VSCode with MicroPython Plugin?

          • Tried them all. Hundreds of megabytes of disk space just to edit software? Still have to copy and paste into the REPL or manually save the file to Flash. PyCraft is probably the best so far, but it can cause exception errors and a Windows “blue screen of death”. And it’s interface could use some work. Notpad++ has a plug-in as well. Seems stable.

  6. Hi Sara,

    Since a year I am following your great tutorials and, of course I am doing hand-ons myself.
    I have an 4MB ESP32 board, flashed MicroPython firmware on it, using esptool and started Thonny IDE to do some programming. It connects to my board, I can read the default contents, but the (%cat stucks in an error (Error 21 EISDIR). I cannot upload even the most simple .py program, whatever I try. Typing the python program manually into REPL terminal makes it run however. I tried some micropython firmware versions, but all have the same problem. The .bin file used in your Micropython course version 1.2 is not available on the internet. There is only generic ESP32 firmware. I am working on debian 10 linux and have Python 3.8 installed.
    What can I do to start programming?

    • Thanks for the info Aivar, I was searching from a long time that why device menu is not available for me only. But I have two problems the one is %lsdevice or %cat / is not working with me.
      The second is when I upload a forever loop program to my esp32 there is no way to stop or overwrite with a new program. Any advice ?


      • %lsdevice and %cat are also gone, because the file browser (View => Files) and the ability to load files from the device have taken their place.

        Can’t you stop your loop program with Ctrl+C?

  7. Good evening. I have followed all the steps of the book and the tutorial but I often get this error in the shell when I try to connect my esp32 CAM IA Thinker to my computer:

    Device is busy or does not respond. Your options:

    wait until it completes current work;
    use Ctrl + C to interrupt current work;
    use Stop / Restart to interrupt more and enter REPL.

    do you have any solutions for me please?

    • Hi.
      Check that your board is not running any code (click the STOP button on the IDE) and that it is not being used in another program (like Arduino IDE for example).


Leave a Comment

Download our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.