ESP32 Micropython Programming (Thonny) 01----Environment Construction & Lighting

为什么使用 Micropython编进行变成呢,在我初步使用后有一下的体悟:

Ok, let's start learning Micropython next (because I am recording while studying, so there will definitely be some mistakes, everyone is welcome to correct me, let's learn and progress together)

Step 1: Micropython programming environment setup

1. Thonny installation


Download address: Thonny
chooses the corresponding version, all the way next is OK

  This is the interface after installation

2. Flash the micropython firmware for your esp32

Download address: Micropython
Select your corresponding hardware type, download the firmware, and then connect your board to the computer.

1. Click to select the interpreter
insert image description here
2. Select the interpreter is ESP32, and select the port, click install or update below
insert image description here
3. Add the firmware you just downloaded in Firmware, click install and wait for ok
insert image description here
to pull this step, your esp32 hardware is ready The micropython language is already supported, let's test it with a light.

The second step of the old actor - lighting

  1. If you have a little python foundation and a little hardware foundation, you should be able to understand what the code means, without explaining it.
  2. When we first came into contact with micropython, we were not very clear about some of its functions, and the compiler did not prompt, so it was very uncomfortable. At this time, it is very important to use the micropython development manual. You can find it on the official website of micropython.
# IO2对应led
import machine
import time
pin2 = machine.Pin(2, machine.Pin.OUT)
while True:

Pay attention to change it to your hardware led, but esp32 is generally IO2, take a look at your schematic diagram.

pwm output: realize the breathing light, the code is as follows

from machine import Pin, PWM
import time

pwm0 = PWM(Pin(2))      # create PWM object from a pin
pwm0.freq(1000)         # set frequency
while True:
    for i in range(0,1024,1):
        pwm0.duty(i)          # 0-1023
    for i in range(1023,-1,-1):
        pwm0.duty(i)          # 0-1023

If you are just getting started, try the code above, and you will have a general understanding of micropython. This is the end of this article. Welcome to communicate~~~

Supongo que te gusta