很久沒關注 MicroPython了, 今日追蹤發現 v1.17 已在 9/2 發布, 而我居然跳過了 v1.16!
映像檔下載位址如下 :
此次更新主要的新增功能如下 :
- 支援 f 字串語法糖 (部分受限)
- 新增 machine 模組的 I2S 類別 (支援 ESP32 與 STM32 板)
- json 模組的 dump/dumps 函數支援 separators 引數
- 檔案目錄重構, 第三方套件均放在 /lib 目錄下, 原本在 /lib 的第一方套件改放至 /shared
- ESP8266/ESP32 的 WLAN 掃描結果支援顯示隱藏之網路
我用 esptools 燒錄映像檔到 4MB 的 NodeMCU (ESP32) OK (先按住右下角的 IO0 鈕) :
D:\ESP32>esptool.py --chip esp32 --port COM9 erase_flash
esptool.py v2.6
Serial port COM9
Connecting....
Chip is ESP32D0WDQ6 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
MAC: 80:7d:3a:b7:c0:8c
Uploading stub...
Running stub...
Stub running...
Erasing flash (this may take a while)...
Chip erase completed successfully in 5.2s
Hard resetting via RTS pin...
D:\ESP32>esptool.py --chip esp32 --port COM9 write_flash -z 0x1000 esp32-20210902-v1.17.bin
esptool.py v2.6
Serial port COM9
Connecting....
Chip is ESP32D0WDQ6 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
MAC: 80:7d:3a:b7:c0:8c
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Compressed 1527504 bytes to 987584...
Wrote 1527504 bytes (987584 compressed) at 0x00001000 in 88.0 seconds (effective 138.9 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting via RTS pin...
燒錄完畢用 Putty 連線 ESP32, 使用 os 模組的 uname() 函數檢查韌體版本 :
ets Jun 8 2016 00:22:57
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:5656
load:0x40078000,len:12696
load:0x40080400,len:4292
entry 0x400806b0
MicroPython v1.17 on 2021-09-02; ESP32 module with ESP32
Type "help()" for more information.
>>> import os
>>> os.uname()
(sysname='esp32', nodename='esp32', release='1.17.0', version='v1.17 on 2021-09-02', machine='ESP32 module with ESP32')
用 sys 模組的 version 屬性檢查 Python 版本 :
>>> import sys
>>> print("Version Python ", sys.version)
Version Python 3.4.0
跟以前一樣還是 Python 3.4.0.
測試 f 字串嵌入功能 :
>>> name="Tony"
>>> age=21
>>> print(f"My name is {name} and I am {age} years old")
My name is Tony and I am 21 years old
果然已有支援 F 字串. 參考 :
2021-09-22 補充 :
在 "用 Python 玩硬體:MicroPython 簡介與實作" 這篇文章中, 作者使用一個 config.sys 檔來儲存 WiFi 網路設定與 Firebase 線上資料庫設定資訊, 這做法值得借鏡 :
SSID = '<ssid>'
PASSWORD = '<password>'
URL = 'https://<project-name>.firebaseio.com/data.json'
沒有留言:
張貼留言