一、下载MicroPython
????????到MicroPython的官网下载基于ESP8266的MicroPython固件,目前最新稳定版本为esp8266-20210618-v1.16.bin
二、烧写MicroPython固件
? ? ? ? 烧写工具下载:flash_download_tool_3.8.8
? ? ? ? 烧写之前最好先擦除一下FLASH
????????
三、打开串口终端,波特率为115200,重启输出以下信息说明烧写成功
MicroPython v1.16 on 2021-06-18; ESP module with ESP8266
Type "help()" for more information.
>>>
四、连接网络
import network
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect('SSID', 'PASSWORD')
wlan.ifconfig()
?
五、使用webrepl上传文件
输入import webrepl_setup进行使能并设置密码
>>> import webrepl_setup
WebREPL daemon auto-start status: enabled
Would you like to (E)nable or (D)isable it running on boot?
(Empty line to quit)
> E
Would you like to change WebREPL password? (y/n) y
New password (4-9 chars): 12345678
Confirm password: 12345678
No further action required
>>>
打开webrepl客户端工具,上传main.py
WebREPL在线版http://micropython.org/webrepl/ 下载地址:https://codeload.github.com/micropython/webrepl/zip/master
?
?
# main.py
import network
import webrepl
import utime
from machine import Pin
SSID = "xxxx"
PASSWORD = "xxxx"
def do_connect():
import network
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
if not wlan.isconnected():
print('connecting to network')
wlan.connect(SSID,PASSWORD)
start = utime.time()
while not wlan.isconnected():
utime.sleep(1)
if utime.time()-start > 5:
print("connect timeout")
break;
if wlan.isconnected():
print('network config', wlan.ifconfig())
def led_test():
p2 = Pin(2, Pin.OUT)
for i in range(10):
p2.value(1)
utime.sleep(1)
p2.value(0)
utime.sleep(1)
do_connect()
led_test()
|