这是我编写的一个简单的Micropython程序,用于测试ESP32 Vroom32开发板。几分钟后崩溃。我得到了大约38000个计数。
from time import sleep
n = 0
while 1:
print(n)
n += 1
sleep(0.02)
这是我用来阅读它的代码。
import serial, serial.tools.list_ports
import time
def find_port(): #Finds which port the arduino is plugged into
ports = list(serial.tools.list_ports.comports())
for p in ports:
if "EA60" in p[2]:
return(p[0])
usbport = find_port()
ser = serial.Serial(usbport, 115200) #setup serial
while 1:
try:
data = ser.readline()
ser.flushInput()
data = data.strip().decode()
print(data)
time.sleep(0.02)
except Exception as e:
print(e)
我尝试了不同的操作,例如使LED闪烁并将计时减慢到0.2秒。完成这两项操作后,它运行了大约8个小时,然后崩溃了。当它崩溃。我必须拔下设备并重新插入,然后在计算机上重新启动python程序,然后它才能再次运行。仅仅重置设备是行不通的。另外,在添加了LED闪烁代码(以上示例中未包括)之后,LED一直保持闪烁状态。好像它仍在运行,但没有通信。
闪烁的新micropython代码:
from time import sleep
from machine import Pin
n = 0
led = Pin(2, Pin.OUT)
while 1:
print(n)
n += 1
led.value(not led.value())
sleep(0.2)
更新:
昨晚我添加了一些代码来尝试捕获该错误。评估板仍然崩溃,并且未创建任何错误文件。
New main.py
from time import sleep
from machine import Pin
n = 0
led = Pin(2, Pin.OUT)
while 1:
try:
led.value(not led.value())
n += 1
print(n)
sleep(0.2)
except Exception as e:
print("ESP32: ", e)
新的桌面脚本:
import serial, serial.tools.list_ports
import time
def find_port(): #Finds which port the arduino is plugged into
ports = list(serial.tools.list_ports.comports())
for p in ports:
if "EA60" in p[2]:
return(p[0])
usbport = find_port()
ser = serial.Serial(usbport, 115200, timeout=10) #setup serial
while 1:
try:
data = ser.readline()
ser.flushInput()
data = data.strip().decode()
print(data)
if "ESP32" in data:
with open("errors.txt", "a") as f:
err = data + "\n"
f.write(err)
time.sleep(0.2)
except Exception as e:
print(e)