ESP32 environment construction (Thonny+MicroPython+ESP32)

1. Description of development environment

Hardware: ESP32

Interpreter: MicroPython (a Python interpreter with special processing for hardware)

IDE: Thonny (similar to pycharm, which is also an IDE, it supports ESP32 better, so choose it)

The ESP32 pin diagram is as follows:
ESP32 pin diagram

2. Download and install Thonny

Download address: https://thonny.org/

It can also be downloaded from the link below, including Thonny, MicroPython firmware and ESP32 driver installation packages.

ESP32 installation related files

Select the latest version, as shown in Figure 2-1 below, the local system is win11, so the Windows system is selected.

Thonny installation interface

Open the editor after the installation is successful.

Thonny interface

3. Download MicroPython

Download address: https://micropython.org/download/esp32/

MicroPython download interface

What it looks like after downloading:

MicroPython package

4. Download the ESP32 driver

In order to ensure that the program is burned into the ESP32, the driver needs to be installed.

Download address: https://doc.itprojects.cn/0006.zhishi.esp32/01.download/esp32usbDriver.zip

After downloading, you can install the driver. Choose x64 for 64-bit systems and x86 for 32-bit systems.

Driver Installation

5. Burn MicroPython to ESP32

The first step is to select "Run -> Configure Interpreter"

Select configuration interpreter

Click the position shown in the figure below in the pop-up box:

Install and update MicroPython

A box will pop up again:

ESP32 installation library interface

Note: At this point, the ESP32 needs to be connected to the USB port of the computer.

Port refers to the serial port where the USB is plugged into the computer from the ESP32, and it can be displayed as long as the provided driver is installed.

Firmware refers to the selected downloaded MicroPython firmware.

ESP32 Installation Guide

Click "Install". You will see a progress bar in the lower left corner during the installation. When "Done" appears, it means completion, just close the window.

ESP32 firmware installation process

ESP32 installation firmware is complete

At this point, MicroPython has been burned into ESP32.

[Special case] Error: Failed to connect to ESP32: No serial data received.

For the problem that the ESP32 cannot burn the program, just press the BOOT button of the development board during the burning process (when the progress bar is loading).

6. Interaction between Thonny and ESP32

Select the corresponding interpreter and serial port.

Thonny option

Follow these steps to see the following interface.

installed interface

It means that you can interact with ESP32, write a simple Python program, or you can simply turn on the lights and try it out.

7. Write code

7-1. Write a simple program

By default, there is only one boot.py file. This file is the startup boot file. This file is generally used to run some functions that need to be started when the system is turned on. Generally speaking, do not write anything in it.

West. We create a new python file, such as HelloWord.py.

write a piece of code

Select the MicroPython device

Click to save the file

Thonny running interface

Appendix: Lighting experiment

Principle: Call value(1) and delay for a while, then call value(0) for a while, and then repeat the above operations.

import machine
import time


pin2 = machine.Pin(2, machine.Pin.OUT)

while True:
    pin2.value(1)
    time.sleep(1)
    pin2.value(0)
    time.sleep(1)

The running effect is as follows:

lighting experiment

8. Summary

So far, we have built the whole process. You can start the python journey of ESP32~!

Guess you like

Origin blog.csdn.net/Little_Carter/article/details/128597071