基于MicroPython的ESP32开发入门

MicroPython的ESP32开发

  1. Thonny安装

  2. Thonny烧录MicroPython固件(Run-配置解释器-安装或更新MicroPython-选择本地固件.bin)

代码测试

点亮LED灯

# 点亮BLUE LED
from machine import Pin

pin2 = Pin(2, Pin.OUT)
pin2.value(1)

闪烁LED

import machine
import time


pin2 = machine.Pin(2, machine.Pin.OUT)

while True:
    pin2.value(1)
    time.sleep(1)
    pin2.value(0)
    time.sleep(1)

PWM亮度控制

from machine import Pin, PWM
import time


led2 = PWM(Pin(2))
led2.freq(1000)
led2.duty(100)

PWM呼吸灯

from machine import Pin, PWM
import time


led2 = PWM(Pin(2))
led2.freq(1000)


while True:
    for i in range(0, 1024):
        led2.duty(i)
        time.sleep_ms(1)
        
    for i in range(1023, -1, -1):
        led2.duty(i)
        time.sleep_ms(1)

WIFI

代码连接

def do_connect():
    import network
    wlan = network.WLAN(network.STA_IF)
    wlan.active(True)
    if not wlan.isconnected():
        print('connecting to network...')
        wlan.connect('ssid', 'key')
        while not wlan.isconnected():
            pass
    print('network config:', wlan.ifconfig())



shell 命令

# Connect Wifi
import network
wlan = network.WLAN(network.STA_IF) # create station interface
wlan.active(True)       # activate the interface
wlan.scan()             # scan for access points
wlan.isconnected()      # check if the station is connected to an AP
wlan.connect('essid', 'pwd') # connect to an AP
wlan.config('mac')      # get the interface's MAC address
wlan.ifconfig()         # get the interface's IP/netmask/gw/DNS addresses


import network
wlan.isconnected()
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
True

wlan.scan()

[(b'ASUS', b'D\xf9q\x93>o', 11, -55, 4, False), (b'ASUS', b' e\x8e-I\xf4', 11, -63, 4, False), (b'CMCC-6u6c', b'H\x1ff\xaef\xd9', 1, -82, 4, False)]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值