1 頁 (共 1 頁)

MicroPython + ESP32-S 測試LED

發表於 : 2023-11-17, 20:29
dtchang
本例使用 Mu Editor
1. 連接 ESP32-S 板子 (本版使用 CH340 故需先安裝 CH340 驅動程式)(安信可 Ai-Think原廠)(NodeMCU-32S)
2. 開啟 Mu Editor 會自動偵測到 ESP32, 並自動建議使用 MicroPython
3. 選擇Mu Editor右下角的設定圖示, 選取 ESP Firmware flasher 準備燒錄 MicroPython
4. https://micropython.org/download/ 下載最新版 (用: Port: esp32 過濾)
5. 選板子 ESP32/WROOM Espressif (依 Ai-Think的說法 ESP32-S 和 WROOM是一樣的模組)(MicroPython網站無 ESP32-S選項),下載 bin 檔
ESP32-S与ESP32-WROOM-32为通用类型的模组,软硬件部分,除了天线形式有差异,其他部分都一样,ESP32-A1S模组内置AC101音频解码芯片,可以进行音频相关的开发,支持播放音乐和录音。
6. 選擇 Erase & Write firmware 燒錄

7. 燒錄完成後即可測試

8. 點[Files](在[REPL]旁),可看到 ESP32和PC中的檔案.

9. 將主程式main.py(需用此檔名)拉或複製或Write to device,將PV端檔案上傳至 ESP32

10. 按 ESP32板的 RESET鍵, 即可重置並啟動ESP32的 main.py

以下為測試板子上的LED燈,一閃一閃為成功(按 ^C 中斷程式)

代碼: 選擇全部

from machine import Pin

import time                                #from time import sleep ,後面sleep(1)

led = Pin(2 , Pin.OUT)

while True:
    led.value(1)
    print("On")	#加註輸出文字以方便偵測
    time.sleep(1)     #等待1秒,也可用  time.sleep_ms(1000)
    led.value(0)
    print("Off")
    time.sleep(1)
關於 MicroPython/ESP32的說明:
>>> help()
Welcome to MicroPython on the ESP32!

For 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')
>>>
raw REPL; CTRL-B to exit
>
參考圖: 圖上偵測到為 HL340(COM4), 不是 CH340.
image001.jpg
image001.jpg (52.24 KiB) 已瀏覽 8433 次