需要準(zhǔn)備
- MicroPython 固件
- python 環(huán)境
第一步 下載固件
- 進(jìn)入MicroPython的官網(wǎng)
- 選擇上方的DOWNLOAD跳轉(zhuǎn)到下載頁面
- 這里會(huì)有很多設(shè)備的固件版本纵柿,選擇自己的版本递递,這里我下載的是:
【Firmware for ESP32 boards】
esp32-20171114-v1.9.2-443-g236297f4.bin (latest)
第二步 安裝Python環(huán)境
- 再Python官網(wǎng)下載Python安裝包,安裝即可.
第三步 燒錄固件
插上開發(fā)板后查看,在設(shè)備管理器中查看端口(Windows+R 輸入devmgmt.msc)帚湘,如果未識(shí)別需要下載安裝驅(qū)動(dòng),記住這里的端口號(hào)(如:COM3).
打開命令行依次執(zhí)行
(1) 安裝esptool 輸入:
pip install esptool
- (2)擦除FLASH,把原來芯片程序擦除
( COM3 替換為自己的端口)
esptool.py --port COM3 erase_flash
- (2)寫入固件
(COM3 替換為自己的端口,C:\esp32-20171102-v1.9.2-443-g236297f4.bin替換為自己的固件路徑)
esptool.py --port COM3 --baud 115200 write_flash -z 0x1000 C:\esp32-20171102-v1.9.2-443-g236297f4.bin --verify
第四步 使用串口工具調(diào)試
- 連接串口工具輸入help()雷恃,輸出以下內(nèi)容說明固件已經(jīng)燒錄成功了
Welcome to MicroPython on the ESP32!
For generic online docs please visit http://docs.micropython.org/
For access to the hardware use the 'machine' module:
import machine
pin12 = machine.Pin(12, machine.Pin.OUT)
pin12.value(1)
pin13 = machine.Pin(13, machine.Pin.IN, machine.Pin.PULL_UP)
print(pin13.value())
i2c = machine.I2C(scl=machine.Pin(21), sda=machine.Pin(22))
i2c.scan()
i2c.writeto(addr, b'1234')
i2c.readfrom(addr, 4)
Basic WiFi configuration:
import network
sta_if = network.WLAN(network.STA_IF); sta_if.active(True)
sta_if.scan() # Scan for available access points
sta_if.connect("<AP_name>", "<password>") # Connect to an AP
sta_if.isconnected() # Check for successful connection
Control commands:
CTRL-A -- on a blank line, enter raw REPL mode
CTRL-B -- on a blank line, enter normal REPL mode
CTRL-C -- interrupt a running program
CTRL-D -- on a blank line, do a soft reset of the board
CTRL-E -- on a blank line, enter paste mode
For further help on a specific object, type help(obj)
For a list of available modules, type help('modules')
- 上面micropython輸出的歡迎界面內(nèi)容仔細(xì)看下會(huì)發(fā)先,不僅列出了文檔地址费坊,還提供了幾個(gè)示例代碼倒槐,注意在最后兩行的幫助命令
For further help on a specific object, type help(obj)
For a list of available modules, type help('modules')
- help('modules') #會(huì)列出所有的模塊
help('modules')
main framebuf re upip
_boot gc select upip_utarfile
_onewire hashlib socket upysh
_thread heapq ssl urandom
apa106 inisetup struct ure
array io sys urequests
binascii json time uselect
btree machine ubinascii usocket
builtins math ucollections ussl
cmath micropython uctypes ustruct
collections neopixel uerrno utime
dht network uhashlib utimeq
ds18x20 ntptime uheapq uzlib
errno onewire uio zlib
esp os ujson
flashbdev random uos
Plus any modules on the filesystem
- help(obj) #會(huì)列出這個(gè)對(duì)象的提供方(help(obj)前需要先import obj 這個(gè)模塊).
help(network)
object <module 'network'> is of type module
name -- network
init -- <function>
WLAN -- <function>
LAN -- <function>
phy_mode -- <function>
STA_IF -- 0
AP_IF -- 1
MODE_11B -- 1
MODE_11G -- 2
MODE_11N -- 4
AUTH_OPEN -- 0
AUTH_WEP -- 1
AUTH_WPA_PSK -- 2
AUTH_WPA2_PSK -- 3
AUTH_WPA_WPA2_PSK -- 4
AUTH_MAX -- 6
PHY_LAN8720 -- 0
PHY_TLK110 -- 1
- 具體模塊請(qǐng)參考源碼 GitHub
- 最后我們需要熟悉python語法結(jié)合help()給我們的提示,就可以簡單的使用MicroPython來操作NodeMCU-32S了