Thonny Development Environment Configuration

Thonny is a free and open source software platform with small size, simple interface, simple operation and rich functions. It is a Python IDE suitable for beginners. In this tutorial, we use this IDE to develop a ESP32. Thonny supports multiple operating systems including Windows, Mac OS, Linux.

1. Download Thonny:

(1) Enter the website:https://thonny.org to download the latest version of Thonny.

⚠️ Note: This tutorial uses the thonny IDE version 3.3.13. Please keep it consistent to avoid code incompatibility issues.

2 Windows System

(1) The downloaded Thonny icon is as follows:

(2) Double-click“thonny-3.3.13.exe”and select install mode. You can choose .

(3) You can also keep selecting “Next” to finish install.

(4) If you want to change the route of installing Thonny,just clic “Browse…”to select a new route and click “OK”.

(5) Click “Create desktop icon” , you will view Thonny on your desktop.

(6) Click“Install”.

(7) Wait for a while but don’t click “Cancel”.

(8) Click“Finish”.

3 Basic Setting:

Double-click Thonny, choose lanuage and initial settings and click “Let’s go!”.

Click“View”→“File”and“Shell”.

4 Install the CP2102 driver:

Before using the Thonny, we need to install the CP2102 driver in the computer.

Windows system

Check if the CP2102 driver has been installed

(1) Interface the ESP32 with your PC with a USB cable.

(2) Click“This PC”and right-click “Manage”.

(3) Click“Device Manager”, if the CP2102 driver has been installed,Silicon Labs CP210x USB to UART Bridge(COMx) will be shown.

If the CP2102 has not been installed.

Click“CP2102USB to UART Bridge Controller”and “Update driver”.

Click“Browse my computer for drivers”.

Click “Browse…” to choose Python Tutorials\1. Get started with Python\CP2102 Driver File-Windows and click “Next”.

The CP2102 driver will be installed.

MAC System

You can refer to Arduino Tutorial.

5 Burn Micropython firmware

⚠️ Note: This tutorial uses the Micropython firmware version 1.17 (2019-09-02). Please keep it consistent to avoid code incompatibility issues.

To run a Python program on the ESP32 board, we need to burn the firmware to the ESP32 board first.

Download Micropython firmware microPython website:http://micropython.org/

ESP32 firmware:https://micropython.org/download/esp32/

The firmware we use:esp32-20210902-v1.17.bin

Download firmware:https://micropython.org/resources/firmware/esp32-20210902-v1.17.bin

Firmware:“Python\MicroPython\Python_Firmware”.

Burn the Micropython firmware

Connect the ESP32 to your PC with a USB cable.

Make sure the driver has been installed successfully and the COM port can be identified correctly. Open “Device Manager” and  expand “Ports”.

Open Thonny,click“run”and“Select interpreter…

Select “Micropython (ESP32)” and “Silicon Labs CP210x USB to UART Bridge(COM3)” and click “Install or update firmware”.

Select“Silicon Labs CP210x USB to UART Bridge(COM3)”,click “Browse…”and choose the firmware “esp32-20210902-v1.17.bin.”. Check“Erase flash before installing”and“Flash mode”,then click“Install”.

Note: if you fail to install the firmware,press the Boot button on the ESP32 board and click“Install”.)

Then click “Close” and “OK”.

Note:During installation, you can press and hold the Boot button on the ESP32 mainboard. When the upload progress percentage appears, release the button for a while to complete the installation.

Turn off all windows and turn to the main page and click STOP”.

Test Code

Test the Shell commander

Input print(‘hello world’) in the“Shell”and press “Enter”.

Run the test code(online)

Connect the ESP32 to your PC. Users can program and debug programs withThonny.

Open Thonny and click “Open”.

When a new window pops up, click“This computer”.

Select the file“lesson_01_HelloWorld.py”.

Click , “Hello World”will be printed in the“Shell”monitor.

Note: Press the reset button to reboot.
Run the test code(offline)

After rebooting the ESP32, run the “boot.py” file under the root directory first then run your code file.

So, we need to add a guide program to run the code of users.

Move the file KS5007(KS5008)Keyestudio ESP32 24 in 1 Sensor Kit\Windows\MicroPython\2. ESP32_code_MicroPython to the disk(D),the route is“D:/2. ESP32_code_MicroPython”.

Click lesson 00. Boot file and double-click “boot.py”, then the code under MicroPython device can run offline.

If you want to run the code offline, you nee to upload “boot.py” and program code to MicroPython device, then press the ESP32’s reset button. We will take the lesson 00 and lesson 01 as an example. Select “boot.py” and right-click “Upload to /”.

Similarly, upload the lesson 01.HelloWorld.py file to the “MicroPython device”.

Press the Reset button, you will view code running in the Shell monitor.

Upload the code to the ESP32

We take the “boot.py” as an example. If we add a “boot.py” in each code directory, reboot the ESP32, the “boot.py” will run first.

Select “boot.py”in the file lesson 02. LED, right-click to select“Upload to /”. Then the code will be uploaded to the root directory of the ESP32 and click “OK”.

Download the code to your PC

left-click “boot.py” of MicroPython device, then right-click “Download to…”.

Delete files of the ESP32

For example, click“boot.py”in the MicroPython device and right-click “Delete”.

Select “boot.py” in the lesson 02. LED folder, right-click “Move to Recycle Bin” to delete it.

Create and save code

Click“File”→“New”to create and edit code.

Enter the code in the new file. We take the lesson 02. LED.py as an example.

Click to save the code to your PC or the ESP32.

Select “MicroPython device” and enter “main.py” in the new page and click “OK”.

Then the code will be uploaded to the ESP32.

Disconnect the USB cable and connect it, you can see the effect of the LED flashing continuously in the circuit on a cycle.
Img