ESP32探索记录

1 ESP32-CAM板

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库;
找了两个开源项目 https://github.com/shariltumin/esp32-cam-micropythonhttps://github.com/shariltumin/esp32-cam-micropython-2022 下载包含camera驱动的固件:
https://files.cnblogs.com/files/blogs/683126/esp32固件.zip?t=1721614583&download=true
烧录新固件,测试导入camera库成功;

1.2 点灯

学习教程 http://micropython.com.cn/en/latet/esp32/quickref.html
通过machine库的Pin方法引脚4输出高电平点亮闪光灯;
通过time库sleep_ms方法,使闪光灯间隔300ms闪烁;

1.3 连接wifi

1.4 网页控制电灯

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()
posted @ 2024-07-22 10:22  工大鸣猪  阅读(15)  评论(0编辑  收藏  举报