首次尝试ESP32过程

1.1 开局

淘宝30块买了个esp32-cam板子;
VSCode配置micropython开发环境(安装RT-Threat Micropyton插件);
micropython官方下载esp32 espressif固件;
通过esptool刷入固件,命令如下:

esptool --chip esp32 --port COM8 erase_flash
esptool --chip esp32 --port COM8 write_flash -z 0x1000 E:\Projects\esp32\ESP32_GENERIC-20240602-v1.23.0.bin

发现无法进入REPL,怀疑板子坏了;
用商家教程配置Arduino环境,烧录验证板子可用;
用Thonny尝试连接,提示板子处于忙碌状态或bootloader模式;
查资料发现GPIO0控制烧录和调试模式;
观察底板电路,发现CH240芯片,观察板子走线发现GPIO0连接芯片DTR引脚;
查找芯片手册发现"DTR and Multi-Mode MCUs Download"部分涉及这个问题;
底板芯片配置为DTR输出低电平,导致通过底板连接esp32只能烧录不能调试;
于是单独购买烧录器,通过杜邦线连接3.3v输出;
尝试连接板子成功,打印信息成功;
尝试esp32连接无线网失败,电压不够板子总重启;
更换烧录器5v输出,连接网络成功;
测试camera,发现没有camera库;
尝试用uip导入camera库,报错不存在uip;
尝试用mip导入camera库,报错找不到camera库;
找了两个开源项目 GitHub - shariltumin/esp32-cam-micropython: Micropython esp32-cam 和 GitHub - shariltumin/esp32-cam-micropython-2022: MicroPython esp32-cam firmware with camera support compiled with esp-idf-4.4.0. Python script files for live streaming 下载包含camera驱动的固件:
https://files.cnblogs.com/files/blogs/683126/esp32固件.zip?t=1721614583&download=true
烧录新固件,测试导入camera库成功;

1.2 点灯

学习教程 Quick reference for the ESP32 — MicroPython latest documentation ;
通过machine库的Pin方法引脚4输出高电平点亮闪光灯;
通过time库sleep_ms方法,使闪光灯间隔300ms闪烁;

1.3 网页控制点灯

try:
  import usocket as socket
except:
  import socket
 
from machine import Pin
import network
 
import esp
esp.osdebug(None)
 
import gc
gc.collect()
 
ssid = 'CIEM'
password = 'Ciem888888'
 
station = network.WLAN(network.STA_IF)
 
station.active(True)
station.connect(ssid, password)
 
while station.isconnected() == False:
  pass
 
print('Connection successful')
print(station.ifconfig())
 
led = Pin(4, Pin.OUT)
 
 
 
 
def web_page():
  if led.value() == 1:
    gpio_state="ON"
  else:
    gpio_state="OFF"
  
  html = """
  <html>
  
  <head>
    <title>ESP Web Server</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="icon" href="data:,">
    <style>
        html {
            font-family: Helvetica;
            display:inline-block; 
            margin: 0px auto; 
            text-align: center;
        } 
        
        h1 {
            color: #0F3376; 
            padding: 2vh;
        } 
        
        p {
            font-size: 1.5rem;
        } 
 
        .button {
            display: inline-block; 
            background-color: #e7bd3b; 
            border: none; 
            border-radius: 4px; 
            color: white; 
            padding: 16px 40px; 
            text-decoration: none; 
            font-size: 30px; 
            margin: 2px; 
            cursor: pointer;
        } 
 
        .button2 { 
            background-color: #4286f4;
        }
    </style>
  </head>
  
  <body>
    <h1>ESP Web Server</h1>
    <p>GPIO state:
      <strong>""" + gpio_state + """</strong>
    </p>
    <p>
      <a href="/?led=on">
        <button class="button">ON</button>
      </a>
    </p>
    <p>
      <a href="/?led=off">
        <button class="button button2">OFF</button>
      </a>
    </p>
  </body>
 
</html>
  """
 
  return html
 
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 80))
s.listen(5)
 
while True:
  conn, addr = s.accept()
  print('Got a connection from %s' % str(addr))  
  request = conn.recv(1024)
  request = str(request)
  print('Content = %s' % request)
  led_on = request.find('/?led=on')
  led_off = request.find('/?led=off')
  if led_on == 6:
    print('LED ON')
    led.value(1)
  if led_off == 6:
    print('LED OFF')
    led.value(0)
  response = web_page()
  conn.send('HTTP/1.1 200 OK\n')
  conn.send('Content-Type: text/html\n')
  conn.send('Connection: close\n\n')
  conn.sendall(response)
  conn.close()

完事!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值