MicroPython 开发ESP32应用教程 之 WIFI配置、连接及简单应用 WIFI及时间同步应用类的封装

ESP32刷入MicroPython以及连接WiFi 一、ESP32刷入MicroPython 1.ESP32驱动 2.下载MicroPython 3.刷入micropython 4.进入ESP32 二、连接WiFi,修改时间 1.写好代码 2.拷贝到环境里面 3.执行总结 阅读详情

ESP32的应用范围有多广,相信不用多说大家都明白,尤其是在物联网领域,所以今天我们就来讲解WIFI的配置、连接及其简单应用。

跟往常一样,我们还是先介绍WIFI的相关知识

一、硬件与软件基础

 1.1 ESP32-C3无线特性
ESP32-C3是乐鑫推出的RISC-V架构物联网芯片,配备:
- 2.4 GHz WiFi 4(802.11b/g/n)
- Bluetooth 5 LE
- 低功耗设计(仅22uA深度睡眠电流)

 1.2 MicroPython优势
- 交互式开发(REPL)
- 简化硬件操作
- 丰富的网络库支持
- 与CPython高度兼容

二、MicroPython WiFi模块详解

 2.1 核心对象说明

import network
wlan = network.WLAN(network.STA_IF)  # 创建工作站对象
wlan.active(True)                   # 激活接口
 

2.2 关键方法解析

方法参数说明
connect()ssid, password连接目标AP
disconnect()断开当前连接
scan()扫描可用网络
isconnected()返回连接状态
ifconfig()[(ip, mask, gw, dns)]获取/设置网络参数

三、WiFi连接实战

3.1 基础连接代码

    def  configwifi(self,ssid,password):
        if not self.wlan.isconnected():
            self.ssid = ssid
            self.password = password
            print(" 正在连接到",ssid)
            self.wlan.connect(ssid,password)
            
            max_wait = 10
            while max_wait > 0:
                if self.wlan.isconnected():
                    break
                max_wait -= 1
                print("等待连接……",max_wait)
                time.sleep(1)
            if not self.wlan.isconnected():
                return False
#                print("连接失败")
            else:
                return True
#                print("连接成功")
#                print("网络配置:",self.wlan.ifconfig())

3.2 增强型连接(含错误处理)

def smart_connect(ssid, password):
    wlan = network.WLAN(network.STA_IF)
    wlan.active(True)
    
    if wlan.isconnected():
        wlan.disconnect()
    
    visible_nets = {net[0].decode(): net for net in wlan.scan()}
    
    if ssid not in visible_nets:
        raise ValueError(f"{ssid} not found")
    
    authmode = visible_nets[ssid][4]
    print(f"Security: {authmode}")  # 0=OPEN, 1=WEP, etc.
    
    try:
        wlan.connect(ssid, password)
        for _ in range(15):
            if wlan.isconnected():
                print(f"IP: {wlan.ifconfig()[0]}")
                return True
            time.sleep(1)
        return False
    except OSError as e:
        print(f"Connection error: {e}")
        return False

3.3 增加网络配置保存、重启时自动连接功能

            self.wlan = network.WLAN(network.STA_IF)
            self.wlan.active(True)
            ssid,password = self.load_wificonfig()
            if ssid and password:
                print(ssid,password)
                self.wlan.connect(ssid,password)
                self.ssid = ssid
                self.password = password

    def save_wificonfig(self):
          with open ("wificonfig.txt","w") as f:
              f.write(self.ssid+"\n")
              f.write(self.password+"\n")
              
    def  load_wificonfig(self):
        try:
            with open("wificonfig.txt","r") as f:
                ssid = f.readline().strip()
                password = f.readline().strip()
                return ssid,password
        except:
            return None,None

 四、网络时间同步

4.1 NTP协议原理
- 使用UDP 123端口
- 支持时间服务器分层架构
- 精度通常在毫秒级

4.2 NTP服务器选择
- 国内推荐:ntp.aliyun.com
- 国际通用:pool.ntp.org

 4.3 MicroPython实现代码

    def sync_time_with_timezone(self,offset=8):
#    同步时间并设置时区
#    offset: 时区偏移(小时),东八区为8
        if not self.wlan.isconnected():
#            print("未连接到网络,请检测网络")
            return False
        try:
            ntptime.host = "ntp.aliyun.com"
            ntptime.settime()
            rtc = RTC()
            tm = list(rtc.datetime())
            
            # 调整时区
            tm[4] += offset  # 增加小时偏移
            if tm[4] >= 24:
                tm[4] -= 24
                tm[2] += 1  # 增加一天
            
            rtc.datetime(tuple(tm))
            self.is_time_sync = True
#            print("时间同步成功(UTC+%d):" % offset, rtc.datetime())
            return True
        except Exception as e:
            self.is_time_sync = False
            print("时间同步失败:", e)
            return False    

4.4 增加时间日期格式化输出

    def get_datetime(self,rtc=None):
        if self.is_time_sync == False:
            if self.sync_time_with_timezone() == False:
                return ""                
        if rtc is None:
            rtc = RTC()
        return rtc.datetime()

    def format_datetime(self):
        t = self.get_datetime()
        if t == "":
            return ""
        else:
            return "{:04d}-{:02d}-{:02d} {:02d}:{:02d}:{:02d}".format(t[0],t[1],t[2],t[4],t[5],t[6])

    def format_date(self):
        t = self.get_datetime()
        if t == "":
            return ""
        else:
            return "{:04d}-{:02d}-{:02d}".format(t[0],t[1],t[2])

    def format_time(self):
        t = self.get_datetime()
        if t == "":
            return ""
        else:
            return "{:02d}:{:02d}:{:02d}".format(t[4],t[5],t[6])

4.5 增加定时同步时间功能

    def periodic_time_sync(self,interval=3600):
        #定期同步时间,interval :同步时间间隔(秒),默认1小时
        if interval != 0:
            self.time_sync = interval
        if self.is_time_sync:
            if self.last_synctime != None:
                rtc = RTC()
                if self.datetime_to_seconds(rtc.datetime()) - self.datetime_to_seconds(self.last_synctime) < self.time_sync:
                    return
                
        if self.auto_sync_time():
#            print("同步时间成功,当前时间:",self.format_time())
            rtc = RTC()
            self.last_synctime = rtc.datetime()
            print("同步时间:",self.format_datetime())

这个功能的实现方式比较多,我们后续的课程会探讨在中断处理程序中实现定时同步时间及获取天气信息。 

五、WIFI及时间同步的封装

有关知识点我们基本介绍了,直接上代码:(该部分代码包括上面全部的代码功能)

import network
import time
import ntptime
import urequests
from machine import RTC

class esp32_wifi(object):
    ssid=""
    password = ""
    last_synctime = None
    time_sync = 3600		#  自动同步时间间隔(秒)
    is_time_sync = False
    def __init__(self,mode="STA_MODE",esp32ssid="ESP32C3-AP",esp32psw = "",esp32authmode=network.AUTH_WPA_WPA2_PSK):
        if mode == "STA_MODE":
            self.wlan = network.WLAN(network.STA_IF)
            self.wlan.active(True)
            ssid,password = self.load_wificonfig()
            if ssid and password:
                print(ssid,password)
                self.wlan.connect(ssid,password)
                self.ssid = ssid
                self.password = password
        elif mode == "AP_MODE":
            self.ap = network.WLAN(network.AP_IF)
            self.ap.config(essid = esp32ssid,password = esp32psw,authmode = esp32authmode)
            self.ap.active(True)
            self.ssid = esp32ssid
            self.password = esp32psw
            self.authmode = esp32authmode
            print("ESP32C3 AP IP地址:",self.ap.ifconfig()[0])
        
        
    def  scanwifi(self):
        networks = self.wlan.scan()
        for net in networks:
                print(net[0],net[3])
    
    def  configwifi(self,ssid,password):
        if not self.wlan.isconnected():
            self.ssid = ssid
            self.password = password
            print(" 正在连接到",ssid)
            self.wlan.connect(ssid,password)
            
            max_wait = 10
            while max_wait > 0:
                if self.wlan.isconnected():
                    break
                max_wait -= 1
                print("等待连接……",max_wait)
                time.sleep(1)
            if not self.wlan.isconnected():
                return False
#                print("连接失败")
            else:
                return True
#                print("连接成功")
#                print("网络配置:",self.wlan.ifconfig())
            
    def  check_wifi(self):
        if self.wlan.isconnected():
            return True
#            print("已连接到网络")
#            print("IP地址:",self.wlan.ifconfig()[0])
#            print("子网掩码:",self.wlan.ifconfig()[1])
#            print("网关:",self.wlan.ifconfig()[2])
#            print("DNS:",self.wlan.ifconfig()[3])
        else:
            return False
#            print("未连接到网络")
#            self.configwifi(self.ssid,self.password)
            
    def save_wificonfig(self):
          with open ("wificonfig.txt","w") as f:
              f.write(self.ssid+"\n")
              f.write(self.password+"\n")
              
    def  load_wificonfig(self):
        try:
            with open("wificonfig.txt","r") as f:
                ssid = f.readline().strip()
                password = f.readline().strip()
                return ssid,password
        except:
            return None,None

    def sync_ntp_time(self):
        if not self.wlan.isconnected():
            print("未连接到网络,请检测网络")
            return False
        
        try:
            ntptime.host = "ntp.aliyun.com"
            ntptime.settime()
            
            rtc = RTC()
            print("同步成功!当前时间:",rtc.datetime())
            self.is_time_sync = True
            return True
        except Exception as e:
            self.is_time_sync = False
            print("时间同步失败:",e)
            return False
        
    def sync_time_with_timezone(self,offset=8):
#    同步时间并设置时区
#    offset: 时区偏移(小时),东八区为8
        if not self.wlan.isconnected():
#            print("未连接到网络,请检测网络")
            return False
        try:
            ntptime.host = "ntp.aliyun.com"
            ntptime.settime()
            rtc = RTC()
            tm = list(rtc.datetime())
            
            # 调整时区
            tm[4] += offset  # 增加小时偏移
            if tm[4] >= 24:
                tm[4] -= 24
                tm[2] += 1  # 增加一天
            
            rtc.datetime(tuple(tm))
            self.is_time_sync = True
#            print("时间同步成功(UTC+%d):" % offset, rtc.datetime())
            return True
        except Exception as e:
            self.is_time_sync = False
            print("时间同步失败:", e)
            return False    

    def get_datetime(self,rtc=None):
        if self.is_time_sync == False:
            if self.sync_time_with_timezone() == False:
                return ""                
        if rtc is None:
            rtc = RTC()
        return rtc.datetime()

    def format_datetime(self):
        t = self.get_datetime()
        if t == "":
            return ""
        else:
            return "{:04d}-{:02d}-{:02d} {:02d}:{:02d}:{:02d}".format(t[0],t[1],t[2],t[4],t[5],t[6])

    def format_date(self):
        t = self.get_datetime()
        if t == "":
            return ""
        else:
            return "{:04d}-{:02d}-{:02d}".format(t[0],t[1],t[2])

    def format_time(self):
        t = self.get_datetime()
        if t == "":
            return ""
        else:
            return "{:02d}:{:02d}:{:02d}".format(t[4],t[5],t[6])

    def auto_sync_time(self,max_retries = 3,retry_delay=10):
        #max_retries: 最大重试次数
        #retry_delay:重试间隔(秒)
        retry = 0
        while retry < max_retries:
            if self.sync_time_with_timezone(8):
                return True
            retry += 1
            time.sleep(retry_delay)
        return False

    def days_in_month(self,year, month):
        # 返回某年某月的天数(修正闰年)
        if month == 2:
            return 29 if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0) else 28
        return [31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month-1]

    def datetime_to_seconds(self,dt):
        year, month, day, _, hour, minute, second, _ = dt
        total_days = 0
        for y in range(2000, year):
            total_days += 366 if (y % 4 == 0 and y % 100 != 0) or (y % 400 == 0) else 365
        for m in range(1, month):
            total_days += self.days_in_month(year, m)
        total_days += day - 1
        return total_days * 86400 + hour * 3600 + minute * 60 + second
        
    def periodic_time_sync(self,interval=3600):
        #定期同步时间,interval :同步时间间隔(秒),默认1小时
        if interval != 0:
            self.time_sync = interval
        if self.is_time_sync:
            if self.last_synctime != None:
                rtc = RTC()
                if self.datetime_to_seconds(rtc.datetime()) - self.datetime_to_seconds(self.last_synctime) < self.time_sync:
                    return
                
        if self.auto_sync_time():
#            print("同步时间成功,当前时间:",self.format_time())
            rtc = RTC()
            self.last_synctime = rtc.datetime()
            print("同步时间:",self.format_datetime())
            
    

 六、i2c驱动aht20并显示

aht20的介绍比较多,有兴趣的朋友可以参考:CH592F /CH582通过硬件IIC读写AHT10 /AHT20

直接上代码: 

# The MIT License (MIT)
#
# Copyright (c) 2020 Kattni Rembor for Adafruit Industries
# Copyright (c) 2020 Andreas Bühl
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
"""
MicroPython driver for the AHT10 and AHT20 Humidity and Temperature Sensor
Author(s): Andreas Bühl, Kattni Rembor
"""

import utime
from micropython import const


class AHT10:
    """Interface library for AHT10/AHT20 temperature+humidity sensors"""

    AHTX0_I2CADDR_DEFAULT = const(0x38)  # Default I2C address
    AHTX0_CMD_INITIALIZE = 0xE1  # Initialization command
    AHTX0_CMD_TRIGGER = const(0xAC)  # Trigger reading command
    AHTX0_CMD_SOFTRESET = const(0xBA)  # Soft reset command
    AHTX0_STATUS_BUSY = const(0x80)  # Status bit for busy
    AHTX0_STATUS_CALIBRATED = const(0x08)  # Status bit for calibrated

    def __init__(self, i2c, address=AHTX0_I2CADDR_DEFAULT):
        utime.sleep_ms(20)  # 20ms delay to wake up
        self._i2c = i2c
        self._address = address
        self._buf = bytearray(6)
        self.reset()
        if not self.initialize():
            raise RuntimeError("Could not initialize")
        self._temp = None
        self._humidity = None

    def reset(self):
        """Perform a soft-reset of the AHT"""
        self._buf[0] = self.AHTX0_CMD_SOFTRESET
        self._i2c.writeto(self._address, self._buf[0:1])
        utime.sleep_ms(20)  # 20ms delay to wake up

    def initialize(self):
        """Ask the sensor to self-initialize. Returns True on success, False otherwise"""
        self._buf[0] = self.AHTX0_CMD_INITIALIZE
        self._buf[1] = 0x08
        self._buf[2] = 0x00
        self._i2c.writeto(self._address, self._buf[0:3])
        self._wait_for_idle()
        if not self.status & self.AHTX0_STATUS_CALIBRATED:
            return False
        return True

    @property
    def status(self):
        """The status byte initially returned from the sensor, see datasheet for details"""
        self._read_to_buffer()
        return self._buf[0]

    @property
    def relative_humidity(self):
        """The measured relative humidity in percent."""
        self._perform_measurement()
        self._humidity = (
            (self._buf[1] << 12) | (self._buf[2] << 4) | (self._buf[3] >> 4)
        )
        self._humidity = (self._humidity * 100) / 0x100000
        return self._humidity

    @property
    def temperature(self):
        """The measured temperature in degrees Celcius."""
        self._perform_measurement()
        self._temp = ((self._buf[3] & 0xF) << 16) | (self._buf[4] << 8) | self._buf[5]
        self._temp = ((self._temp * 200.0) / 0x100000) - 50
        return self._temp

    def _read_to_buffer(self):
        """Read sensor data to buffer"""
        self._i2c.readfrom_into(self._address, self._buf)

    def _trigger_measurement(self):
        """Internal function for triggering the AHT to read temp/humidity"""
        self._buf[0] = self.AHTX0_CMD_TRIGGER
        self._buf[1] = 0x33
        self._buf[2] = 0x00
        self._i2c.writeto(self._address, self._buf[0:3])

    def _wait_for_idle(self):
        """Wait until sensor can receive a new command"""
        while self.status & self.AHTX0_STATUS_BUSY:
            utime.sleep_ms(5)

    def _perform_measurement(self):
        """Trigger measurement and write result to buffer"""
        self._trigger_measurement()
        self._wait_for_idle()
        self._read_to_buffer()


class AHT20(AHT10):
    AHTX0_CMD_INITIALIZE = 0xBE  # Calibration command


利用aht20模块读取当前的温湿度并显示:

from ahtx0 import AHT20


i2c = I2C(0,scl=Pin(2),sda=Pin(3),freq=200000)
aht20_sensor = AHT20(i2c)
wendu = aht20_sensor.temperature
shidu = aht20_sensor.relative_humidity
oled.show_chinese("温",3,43,1)
oled.text("{:>4.1f}".format(wendu),23,48,1)
oled.show_chinese("湿",64,43,1)
oled.text("{:>4.1f}".format(shidu),84,48,1)

aht20的硬件连接 :

aht20ESPC3
sclIO2
sdaIO3

调用以上模块并显示的代码:


from machine import I2C,SPI,Pin,Timer
import time
from neopixel import NeoPixel
from ssd1306 import SSD1306_SPI
from esp32_wifi import esp32_wifi
from ahtx0 import AHT20

spi = SPI(1,baudrate = 8000000,
              polarity = 0,
              phase = 0,
              sck=Pin(4),
              mosi=Pin(5),
              miso=None)
dc = Pin(6,Pin.OUT)
cs = Pin(7,Pin.OUT)
rst= Pin(10,Pin.OUT)

oled = SSD1306_SPI(128, 64, spi,dc,rst,cs) #OLED显示屏初始化:128*64分辨率
i2c = I2C(0,scl=Pin(2),sda=Pin(3),freq=200000)
aht20_sensor = AHT20(i2c)

# 定义全局变量
WS2812_NUM = 1
WS2812_LED_LEVEL = 0x10
G = 0xff
R = 0
B = 0

pin = Pin(8, Pin.OUT)   #配置GPIO8为输出端口,控制ws2812灯珠的DIN信号
np = NeoPixel(pin, WS2812_NUM,3,1)

def ws2812_LED_On(phase):
    global G,R,B
    
    for i in range(WS2812_NUM - 1):
        np[WS2812_NUM -1 - i] = np[WS2812_NUM - 2 - i]
        
    if phase < WS2812_LED_LEVEL:
        G = int(G - (0xff / WS2812_LED_LEVEL))
        R = int(R + (0xff / WS2812_LED_LEVEL))
        phase += 1
        if phase == WS2812_LED_LEVEL:
            G = 0
            R = 0xff
    elif phase < (WS2812_LED_LEVEL * 2):
        R = int(R - (0xff / WS2812_LED_LEVEL))
        B = int(B + (0xff / WS2812_LED_LEVEL))
        phase += 1        
        if phase == (WS2812_LED_LEVEL * 2):
            R = 0
            B = 0xff
    elif  phase < (WS2812_LED_LEVEL * 3):
        B = int(B - (0xff / WS2812_LED_LEVEL))
        G = int(G + (0xff / WS2812_LED_LEVEL))
        phase += 1        
        if phase == (WS2812_LED_LEVEL * 3):
            phase = 0
            B = 0
            G = 0xff
    np[0] = (G,R,B)
    return phase


if __name__ == "__main__":
    
#    pin = Pin(36, Pin.OUT)
    p9 = Pin(9, Pin.IN) #配置GPIO9为输入端口
    WS2812_POWERON = 1
    WS2812_POWEROFF = 0
    ws2812_status = WS2812_POWEROFF
    offset = 0

    
    wlan = esp32_wifi("STA_MODE")
#    wlan.configwifi("weald2000","fkepln_730401")
#    wlan.save_wificonfig()
    while True:
        if wlan.check_wifi():
            wlan.periodic_time_sync(3600)
#        if wlan.sync_time_with_timezone():
#           print("当前时间:",wlan.format_time())
        
        if (p9.value() == 0):	#是否有按键?有,切换RGB灯的状态
            ws2812_status ^= 1
            while True:
                if (p9.value() == 1):  #等待按键释放
                    break
        datetimetxt = wlan.format_date()
        oled.Set_gb_font_name("GB18030P.BIN")
        oled.fill(0x0)
        oled.rect(0,0,128,64,1)
        oled.show_chinese("日期",3,3,1)
        oled.text(datetimetxt,40,8,1)
        oled.show_chinese("时间",3,23,1)
        datetimetxt = wlan.format_time()
        oled.text(datetimetxt,40,28,1)

        wendu = aht20_sensor.temperature
        shidu = aht20_sensor.relative_humidity
        oled.show_chinese("温",3,43,1)
        oled.text("{:>4.1f}".format(wendu),23,48,1)
        oled.show_chinese("湿",64,43,1)
        oled.text("{:>4.1f}".format(shidu),84,48,1)

#        oled.show_chinese("深圳源悦科技",3,3,1)
        oled.show()
        time.sleep_ms(100)
        
        

 完整的代码请参考:MicroPythonforesp32wifi配置,时间同步,获取天气信息并显示资源-优快云文库

通过本文的实践,您已掌握ESP32-C3的无线连接和时间同步核心技术。

ESP32-C3的WIFI连接的不仅仅是网络,更是通向智能世界星光大道——让我们用MicroPython在这条大道上狂飙!

ESP32 Micropython编程(Thonny)01----环境搭建&点灯 ESP32 Micropython编程(Thonny)01----环境搭建&点灯 micropython编程,python在硬件上使用,esp入门点亮你的led 阅读详情

相关推荐

MicroPython开发ESP32入门笔记 -- 蓝牙篇

博主希望下来学习用MicroPython来开发esp32,先从esp32的特色功能蓝牙和WiFi玩起,再接触一下之前没有玩过的传感器和外设:DHT11温湿度传感器、超声波传感器、MG60s舵机、PIR红外传感器等。整个过程中,我们都会通过MQTT、蓝牙、WiFi的形式让esp32和其他设备进行交互。

m0_55202222的博客 1万+

一文速通ESP32(基于MicroPython)——含示例代码

是一款集成 2.4 GHz Wi-Fi 和 Bluetooth 5 (LE) 的 MCU 芯片,支持远距离模式 (Long Range)。ESP32-S3 搭载 Xtensa® 32 位 LX7 双核处理器,主频高达 240 MHz,内置 512 KB SRAM (TCM),具有 45 个可编程 GPIO 管脚和丰富的通信接口。ESP32-S3 支持更大容量的高速 Octal SPI flash 和片外 RAM,支持用户配置数据缓存与指令缓存。——乐鑫官网。

m0_63235356的博客 2万+

物联网开发笔记(19)- 使用Micropython开发ESP32开发板之连接WIFI热点

使用Micropython开发ESP32开发板之连接WIFI热点

zhusongziye的博客 5165

micropython基础入门(esp32/esp8266单片机开发)

2022 / 01/ 30: 新版esptool 刷micropython固件指令不是 esptool.py cmd... 而是 esptool cmd... 即可;另外rshell 在 >= python 3.10 的时候出错解决方法可以查看:  已于2022年发布的: 第二章:修复rshell在python3.10出错 免费内容: https://edu.youkuaiyun.com/course/detail/29666 2025/07/07: 由于该视频在2019年制作,当时py3.7;现在py3.13 由于pyreadline冲突rshell已不能用;如果仍要使用rshell请安装py3.12并用我修改的rshell: https://github.com/gamefunc/rshell/releases micropython语法和python3一样,编写起来非常方便。如果你快速入门单片机玩物联网而且像轻松实现各种功能,那绝力推荐使用micropython。方便易懂易学。 同时如果你懂C语音,也可以用C写好函数并编译进micropython固件里然后进入micropython调用(非必须)。 能通过WIFI联网(2.1章),也能通过sim卡使用2G/3G/4G/5G联网(4.5章)。 为实现语音控制,本教程会教大家使用tensorflow利用神经网络训练自己的语音模型并应用。为实现通过网页控制,本教程会教大家linux(debian10 nginx->uwsgi->python3->postgresql)网站前后台入门。为记录单片机传输过来的数据, 本教程会教大家入门数据库。  本教程会通过通俗易懂的比喻来讲解各种原理与思路,并手把手编写程序来实现各项功能。 本教程micropython版本是 2019年6月发布的1.11; 更多内容请看视频列表。  学习这门课程之前你需要至少掌握: 1: python3基础(变量, 循环, 函数, 常用库, 常用方法)。 本视频使用到的零件与淘宝上大致价格:     1: 超声波传感器(3)     2: MAX9814麦克风放大模块(8)     3: DHT22(15)     4: LED(0.1)     5: 8路5V低电平触发继电器(12)     6: HX1838红外接收模块(2)     7:红外发射管(0.1),HX1838红外接收板(1)     other: 电表, 排线, 面包板(2)*2,ESP32(28)  

MicroPython 开发ESP32应用教程 之 WIFI配网 Web页面配网 softAP 配网 web页面控制WS2812灯珠

MicroPython 开发ESP32应用教程 之 WIFI配网 Web页面配网 softAP 配网 web页面控制WS2812灯珠

weald2000的专栏 2084

ESP32 MicroPython教程:自动连接WiFi

模块调用型连接 connect函数连接程序 def connect(): 导入网络模块 并将网络凭据(ssid和密码)存储在两个变量上。 import network ssid = "yourNetworkName" password = "yourNetworkPassword" 获取站点WiFi接口的实例 并将其存储在变量上,然后,检查我们是否已连接到WiFi网络。 如已连接,则打印警告,完成执行。 station = network.WLAN(network.STA_IF) if stati

zhazhawoaini的博客 4355

ESP32 / ESP8266 MicroPython教程:自动连接WiFi

上一篇:ESP32 MicroPython教程:编码JSON 本MicroPython教程旨在阐释如何在MicroPython上自动连接WiFi网络,且无需在提示符中插入所有独立命令。本教程在ESP32和ESP8266上均进行了测试。 简介 本MicroPython教程旨在阐释如何在MicroPython上自动连接WiFi网络,且无需在提示符中插入所有独立命令。此程序在ESP32和ESP82...

xatsoft的博客 3273

ESP32+MicroPython实现WiFi连接与网络配置

WiFi连接是嵌入式设备接入物联网的基础能力,其本质是遵循IEEE 802.11协议完成物理层同步、链路层关联、安全认证(如WPA2四次握手)及网络层DHCP地址分配的完整状态机过程。ESP32凭借高度集成的双模WiFi射频与LwIP协议栈,配合MicroPython的network模块抽象,可将底层驱动封装为简洁的Python接口,显著降低开发门槛。该方案兼顾工程可靠性与资源效率,广泛应用于智能家居终端、工业传感器节点和低功耗远程监控等场景;尤其适合需要快速验证网络连通性、动态获取IP配置并集成HTTP/

weixin_34456923的博客 632

MicroPython 开发ESP32应用教程 之 WIFI简单应用 :时间同步、天气信息获取,ST7735 TFT屏驱动及任意中文字符显示

提供中文字库支持的模块帮我们完善了显示字符的接口函数,支持中英字符混合,支持换行符及tab符 MicroPython for esp32C3,st7735 TFT显示屏,中文字库支持,WIFI连接,时间同步,天气信息获取,aht20测温湿度 中文字库内含编码转换表,可以任意显示中文字符(应该只支持GB2312-80部分的汉字),支持中英字符混合,支持换行符及tab符

weald2000的专栏 1557

ESP32上电自动连接WiFi的实现指南

本文介绍了在MicroPython环境下实现ESP32自动连接WiFi的完整方案。核心内容包括:1) 使用network模块封装WiFi连接功能,提供状态LED指示和超时处理;2) 通过main.py实现开机自启动连接;3) 提供详细的状态反馈和错误处理机制。文章还给出了代码实现示例,包括WiFi连接模块和主程序配置,并探讨了多网络支持、配置保存等优化建议。该方案为ESP32物联网项目提供了可靠的网络连接基础,支持快速部署和扩展开发。

Ven%的博客 1269

【雕爷学编程】MicroPython手册之 ESP32-S3 通用控制 esp32

这样就实现了对温度传感器数据的读取和显示。强大的功能集成:ESP32-S3芯片上的esp32外设集成了丰富的功能,包括Wi-Fi、蓝牙、TCP/IP协议栈、GPIO、I2C、SPI等。MicroPython的ESP32-S3通用控制esp32模块提供了对这些外设的高级控制接口,使开发人员能够方便地配置和操作这些功能,实现各种应用需求。MicroPython的ESP32-S3通用控制esp32是基于MicroPython语言的一种开发模块,用于对ESP32-S3芯片上的esp32外设进行控制和交互。

雕爷学编程 2870

esp32 MicroPython WiFi 测试

【代码】esp32 MicroPython WiFi 测试。

weixin_46158019的博客 1501

「 网络安全常用术语解读 」软件成分分析SCA详解:从发展背景到技术原理再到业界常用检测工具推荐

软件成分分析(Software Composition Analysis,SCA)是一种用于识别和分析软件内部组件及其关系的技术,旨在帮助开发人员更好地了解和管理其软件的构建过程,同时可帮助安全人员揭秘软件内部结构的神秘面纱。SCA技术的发展与软件行业的快速发展密不可分,下面将介绍SCA的发展背景、技术原理以及当前主流SCA工具。

所有成功的背后,都是痛苦的坚持,所有的痛苦,都是傻瓜般的不放弃! 5638

使用micropython+pycharm开发ESP32

使用micropython+pycharm开发ESP32 1.安装pycharm 此步骤略去,优快云上有大量参考文章。 2.配置pycharm环境 1.进入file->setting->plugins安装BetterInterllij和micropython模块 2.进入language里找到micropython选择Enable micropython support,devicetype选择pybord。将ESP32使用数据线连接电脑,在device path里选择esp32对应的com

qq_43533383的博客 1万+

[uboot] (第一章)uboot流程——概述

[uboot] uboot流程系列: [project X] tiny210(s5pv210)上电启动流程(BL0-BL2)建议先看《[project X] tiny210(s5pv210)上电启动流程(BL0-BL2)》,根据例子了解一下上电之后的BL0\BL1\BL2阶段,以及各个阶段的运行位置,功能。==============================================

ooonebook的博客 1万+

openlayers6【十九】vue HeatmapLayer热力图层实现热力图效果详解

文章目录1. 写在前面2. Heatmap 类实现热力图2.1 Heatmap 参数2.2 实现热力图3. 完整代码4. 添加删除map图层的方法5. 热力图自身的get,set方法 1. 写在前面 我们主要看热力图的效果,区域绘制效怎么设置详细内容可以访问 openlayers6【十七】vue VectorLayer矢量图层画地图省市区,多省市区(粤港澳大湾区)效果详解 在 openlayers 中,图层是使用 layer 对象表示的,主要有 WebGLPoints Layer、热度图(HeatMap L

@必意玲 1万+

MicroPython+ESP32:四.ESP32连接WIFI

使用ESP32连接WIFI

weixin_74769854的博客 1752

STM32F407用FSMC+DMA驱动LVGL,3.5寸屏流畅度翻倍实战(附CubeMX配置避坑)

本文详细介绍了如何在STM32F407上通过FSMC+DMA驱动LVGL,显著提升3.5寸屏的显示流畅度。从FSMC与DMA的配置原理到LVGL驱动层适配,提供了完整的优化方案和实测数据,帮助开发者解决界面卡顿问题,实现流畅度翻倍的效果。

weixin_30872499的博客 559

MicroPython 链接WiFi ESP32连WiFi

这里---->>>> MicroPython 教程写的非常好强烈推荐 import network import socket import time SSID = "abc" #修改为你的WiFi名称 PASSWORD = "123456789" #修改为你WiFi密码 port = 10000 #端口号 wlan = None #wlan listenSock...

freedom_fd的博客 4595

【多模态大模型】GLIP:零样本目标检测新范式与视觉语言理解

本文深入解析了多模态大模型GLIP在零样本目标检测和视觉语言理解领域的创新应用。GLIP通过统一目标检测与自然语言理解任务,实现了零样本学习能力,能够精准定位复杂文本描述对应的图像区域。文章详细介绍了GLIP的核心技术、数据策略及实战表现,并对比了与其他多模态模型的差异,为AI视觉理解提供了新范式。

weixin_29186249的博客 264

DSSAT模型建模教程

随着数字农业和智慧农业的发展,基于过程的作物生长模型(Process-based Crop Growth Simulation Model)在模拟作物对气候变化的响应与适应、农田管理优化、作物品种和株型筛选、农业碳中和、农田固碳减排等领域扮演着越来越重要的作用。现有版本V4.7能模拟27种主要农作物的生长发育和产量形成过程,被广泛应用于精细农业、水肥管理、气候变化、粮食安全、土壤碳周转、环境影响、农业可持续性、农业生态等诸多与农业生产和科研有关的领域。如果你是个模型入门者,这次将让你体验一键模拟的乐趣。

weixin_55561616的博客 1415

micropython+ESP32入门教程——连接wifi

学习ESP32的很大一部分原因就是看重其wifi功能,本节将讲述如何用esp32连接wifi

一世杀闪博客 1364

python中有趣的库 freegames 的详细使用

freegames 是一个包含多个简单 Python 游戏的开源库,适合初学者学习 Python 编程和游戏开发。以下是 freegames 的详细介绍和用法示例。

数据知道的博客 3万+

17-MicroPython+ESP32实现WiFi连接无线网

通过本实验,学会了使用MicroPython编程语言控制ESP32模块连接WiFi路由器。

weixin_42255154的博客 5049

万字数据仓库面试题及参考答案

星型模型由一个中心的事实表和多个外围的维度表组成,事实表存储度量值和事实,维度表存储描述性属性和维度。星型模型和雪花模型的区别在于雪花模型将维度表进一步细化,形成多层次的结构,而星型模型由一个中心事实表和多个维度表组成,适用于查询较为简单的情况。维度建模通常采用星型模型或雪花模型,将数据分为事实表和维度表,其中事实表存储度量值和事实,维度表存储描述事实的属性。三者之间的关系可以这样理解:数据仓库主要关注历史数据的存储和分析,数据中台则关注数据的服务化和资产化,而数据湖则关注原始数据的存储和多样性。

大模型大数据攻城狮的专栏 560

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

ESP32开发之旅——MicroPython介绍

什么是ESP32 ESP32是由我国乐鑫公司继ESP8266芯片后推出的又一款集成WiFi 功能的微控制器。与ESP8266相比,有着更强大的性能,ESP32具有以下几个特点: 处理器:Tensilica LX6 双核处理器(一核处理高速连接;一核独立应用开发) 主频:32 位双核处理器,CPU 正常工作速度为 80 MHz,最高可达 240 MHz SRAM:520KB,最大支持 8 MB 片外 SPI SRAM Flash:最大支持 16 MB 片外 SPI Flash WiFi 协议:支

weixin_44186593的博客 8233

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

上一篇: MicroPython 开发ESP32应用教程 之 BLE通信及BLE类的封装
下一篇: MicroPython 开发ESP32应用教程 之 WIFI简单应用 :时间同步、天气信息获取,ST7735 TFT屏驱动及任意中文字符显示
永远的元子
博客等级 码龄16年 330粉丝 44原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

永远的元子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值