上次購買的三片 LOLIN D32 開發板上週山陀兒颱風來襲當天到貨, 週五雨停後領回卻沒時間測試, 拆箱發現是未焊接的模組包, 於是晚上找出烙鐵與焊條把針腳排都焊好.
此款開發板基本規格與 ESP32-WROOM 類似, 同樣是 4MB Flash 無 PSRAM, 但 LOLIN D32 特色是內建電池管理模組, 支援使用 LiPo 電池進行供電. 並支援充電功能.
電源插槽左為 LiPo 右為 Micro USB, 均可分別供電, 同時供電時以 USB 為主電源並向 LiPo 電池進行充電, 非常適合農業物聯網應用. LiPo 插槽使用常見的 JST-PH 2.0mm 型號接頭, 可連接 3.7V 的 LiPo 電池包供電.
接著燒錄 MicroPython v1.23 韌體 :
D:\ESP32>esptool --port COM6 flash_id
esptool.py v4.6.2
Serial port COM6
Connecting.....
Detecting chip type... Unsupported detection protocol, switching and trying again...
Connecting....
Detecting chip type... ESP32
Chip is ESP32-D0WD-V3 (revision v3.1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: ec:64:c9:5d:ef:7c
Uploading stub...
Running stub...
Stub running...
Manufacturer: 68
Device: 4016
Detected flash size: 4MB
Hard resetting via RTS pin...
D:\ESP32>esptool --chip esp32 --port COM6 erase_flash
esptool.py v4.6.2
Serial port COM6
Connecting....
Chip is ESP32-D0WD-V3 (revision v3.1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: ec:64:c9:5d:ef:7c
Uploading stub...
Running stub...
Stub running...
Erasing flash (this may take a while)...
Chip erase completed successfully in 4.0s
Hard resetting via RTS pin...
D:\ESP32>esptool --chip esp32 --port COM6 write_flash -z 0x1000 ESP32_GENERIC-20240602-v1.23.0.bin
esptool.py v4.6.2
Serial port COM6
Connecting....
Chip is ESP32-D0WD-V3 (revision v3.1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: ec:64:c9:5d:ef:7c
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Flash will be erased from 0x00001000 to 0x001a8fff...
Compressed 1734240 bytes to 1142447...
Wrote 1734240 bytes (1142447 compressed) at 0x00001000 in 100.7 seconds (effective 137.8 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting via RTS pin...
最後測試用 xtools 函式庫連網與呼叫 LINE Notify 與 OpenAI API 功能 :
>>> import xtools
import config
ip=xtools.connect_wifi(config.SSID, config.PASSWORD)
line_token=config.LINE_NOTIFY_TOKEN
openai_api_key=config.OPENAI_API_KEY
message='test'
image_url='https://cdn.pixabay.com/photo/2024/03/15/17/50/dogs-8635461_1280.jpg'
xtools.line_msg(line_token, message)
xtools.line_sticker(line_token, message, 1, 4)
xtools.line_image_url(line_token, message, image_url)
prompt='Who are you'
print(xtools.ask_gpt(prompt, openai_api_key))
network config: ('192.168.50.102', '255.255.255.0', '192.168.50.1', '192.168.50.1')
Message has been sent.
'The sticker has been sent.'
'The image URL has been sent.'
I am an artificial intelligence language model created by OpenAI, designed to assist with a wide range of questions and provide information on various topics. How can I help you today?
LOLIN D32 開發板無內建任何感測器, 只有一個接在 GPIO5 的藍光 LED, 可用下列程式測試 :
MicroPython v1.23.0 on 2024-06-02; Generic ESP32 module with ESP32
Type "help()" for more information.
from machine import Pin
import time
# 定義 GPIO 5 為輸出, 控制板上 LED
led = Pin(5, Pin.OUT)
# 閃爍 LED
while True:
led.value(1) # 點亮 LED
time.sleep(1)
led.value(0) # 熄滅 LED
time.sleep(1)
OK, 三片經測試均功能正常.
2024-10-08 補充 :
為了配合每種開發板內建 LED 接在不同之 GPIO 腳, 所以修改了 xtools.py 中的 connect_wifi() 函式, 加入預設為 2 的參數 led, 不過要注意的是 LOLIN D32 的板上 LED 是 GPIO5, 因此呼叫 connect_wifi() 時要傳入 led=5 連線時才會閃爍 (連線中慢速閃爍, 連線成功快閃數秒後常亮) :
def connect_wifi(ssid=config.SSID, passwd=config.PASSWORD, led=2, timeout=20)
MicroPython v1.23.0 on 2024-06-02; Generic ESP32 module with ESP32
Type "help()" for more information.
>>> import config
>>> import xtools
>>> xtools.connect_wifi(led=5)
Connecting to network...
network config: ('192.168.192.225', '255.255.255.0', '192.168.192.92', '192.168.192.92')
'192.168.192.225'
測試板上 LED 連線時會閃.
沒有留言:
張貼留言