【DigiKey好物畅享】ESP32-C6无线温度计

【DigiKey好物畅享】ESP32-C6无线温度计

DFR1117 DFRobot | 开发板,套件,编程器 | DigiKey

本文介绍了 ESP32-C6 开发板使用 MicroPython 编程实现内部温度传感器读取,并通过 WiFi 网页显示的项目设计。

硬件介绍

ADC 温度计

ESP32-C6 内置传感器,用于测量芯片内部的温度。

代码

Thonny IDE 新建工程文件,并添加如下代码

import esp32
import time

try:
    while True:
        temp = esp32.mcu_temperature()
        print(f"mcu: {temp:.1f}°C")
        time.sleep(1)
except KeyboardInterrupt:
    print('Stop Print.')
finally:
    print('Terminate Program.')

保存代码。

效果

  • 运行 mcu_temp_print.py 程序;
  • Shell 终端打印 MCU 内部温度,间隔为 1 秒;

WiFi

通过板载 WiFi 模块连接局域网,设计网页实现芯片内部温度的远程监控。

代码

Thonny IDE 新建工程文件,并添加如下代码

import network, socket, esp32, time
from machine import reset


# 连接WiFi
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(WIFI_SSID, WIFI_PASS)
while not wlan.isconnected():
    time.sleep(0.5)
ip = wlan.ifconfig()[0]
print(f"IP: {ip}:{PORT}")


while True:
    try:
        cl, _ = s.accept()
        cl.recv(1024)
        temp = esp32.mcu_temperature()
        cl.send(HTML % f"{temp:.1f}")
        cl.close()
    except:
        pass

保存代码。

效果

  • 运行 mcu_temp_web.py 程序;

  • Shell 终端输出网页对应地址 http://192.168.2.162:80

  • 浏览器输入网页对应地址,访问网页服务器,获取实时 MCU 温度信息;

  • 温度每秒更新,包括当前温度、时刻、极值、平均值、历史曲线等。

总结

本文介绍了 Beetle ESP32-C6 开发板使用 MicroPython 编程,实现内部温度读取和 WiFi 网页显示的项目设计,为相关产品的快速开发和应用设计提供了参考。