2020年2月11日 星期二

MicroPython 1.12 釋出

好久沒摸 MicroPython 了, 上一次是去年暑假想教二哥物聯網開始使用 ESP32 開發板, 當時韌體還是 1.11 版, 半年沒接觸已升到 1.12, 參考 :

MicroPython version 1.12 released

版本異動紀錄參考 Change Log :

https://micropython.org/resources/micropython-ChangeLog.txt

主要更新摘要如下 :
  • a reduction in overall bytecode size
  • Bluetooth (BLE only) support is added via the "ubluetooth" module and provides the ability to implement the four BLE roles
  • Support for littlefs filesystems is added through the MicroPython VFS interface, and it works on the unix, stm32, esp8266 and esp32 ports
  • A new "machine.ADC.read_u16()" method is defined and implemented on stm32, esp8266, esp32 and nrf ports, providing a consistent way to read an ADC that returns a value in the range 0-65535
  • The esp32 port has the following new features: native code generation, machine.SDCard, hardware I2C, mDNS queries and responder, esp32.Partition, esp32.RMT, BLE (requires IDF v4), and built-in support for VfsLfs2
其中最重要也最吸引我注意的是對藍芽 BLE 的支持, 1.12 版提供了 ubluetooth 模組且支援四種藍芽角色 : Central, Peripheral, Broadcaster, 以及 Observer (可同時具有多重角色).

更多 ESP32 上的 MicroPython 測試參考 :

MicroPython on ESP32 學習筆記索引


1. 下載韌體 :

下載網址 :

http://micropython.org/download/#esp32

我下載的是最新的 esp32-idf3-20200211-v1.12-156-g0852acfc7.bin 檔, 將其放在工作目錄 d:\esp32 下.

ESP8266 韌體下載位置 :

http://micropython.org/download/#esp8266


2. 燒錄韌體 :

將 ESP32 板子插入筆電 USB 後先用裝置管理員查詢連接埠, 例如 COM8, ESP32 韌體燒錄參考 :

MicroPython on ESP32 學習筆記 (一) : 燒錄韌體

燒錄新韌體之前先清除舊韌體, 下指令前要按住 USB 槽右邊的 flash 鈕 (即 IO0), 直到 Connecting ... 後面的 Chip 編號出來才可放掉 :

D:\test>esptool.py --chip esp32 --port COM8 erase_flash 
esptool.py v2.6
Serial port COM8
Connecting........_____....._____....._____....._____....._____....._
Chip is ESP32D0WDQ6 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
MAC: 80:7d:3a:b7:a7:5c
Uploading stub...
Running stub...
Stub running...
Erasing flash (this may take a while)...
Chip erase completed successfully in 4.6s
Hard resetting via RTS pin...

燒錄韌體前一樣要按住 USB 槽右邊的 flash 鈕 (即 IO0), 直到 Connecting ... 後面的 Chip 編號出來才可放掉 :

D:\ESP32>esptool.py --chip esp32 --port COM8 write_flash -z 0x1000 esp32-idf3-20200211-v1.12-156-g0852acfc7.bin 
esptool.py v2.6
Serial port COM8
Connecting....
Chip is ESP32D0WDQ6 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
MAC: 80:7d:3a:b7:a7:5c
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Compressed 1433616 bytes to 912935...
Wrote 1433616 bytes (912935 compressed) at 0x00001000 in 81.3 seconds (effective 141.1 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...

這樣就燒錄完成了.


3. 用 PuTTY 連線 ESP32 :

開啟 PuTTY 以 Serial 串列 115200 速率連線 COM port 即進入 REPL 介面 :

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:0x3fff0018,len:4
load:0x3fff001c,len:5008
ho 0 tail 12 room 4
load:0x40078000,len:10600
ho 0 tail 12 room 4
load:0x40080400,len:5684
entry 0x400806bc
I (530) cpu_start: Pro cpu up.
I (530) cpu_start: Application information:
I (530) cpu_start: Compile time:     Feb 11 2020 00:37:56
I (534) cpu_start: ELF file SHA256:  0000000000000000...
I (540) cpu_start: ESP-IDF:          v3.3.1
I (544) cpu_start: Starting app cpu, entry point is 0x400836ec
I (0) cpu_start: App cpu up.
I (555) heap_init: Initializing. RAM available for dynamic allocation:
I (562) heap_init: At 3FFAFF10 len 000000F0 (0 KiB): DRAM
I (568) heap_init: At 3FFB6388 len 00001C78 (7 KiB): DRAM
I (574) heap_init: At 3FFB9A20 len 00004108 (16 KiB): DRAM
I (580) heap_init: At 3FFBDB5C len 00000004 (0 KiB): DRAM
I (586) heap_init: At 3FFCC810 len 000137F0 (77 KiB): DRAM
I (592) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (599) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (605) heap_init: At 40099A80 len 00006580 (25 KiB): IRAM
I (611) cpu_start: Pro cpu start user code
I (294) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
MicroPython v1.12-156-g0852acfc7 on 2020-02-11; ESP32 module with ESP32
Type "help()" for more information.
>>>


4. 藍芽模組 ubluetooth :

前一版的 v1.11 並未支援藍芽, 參考 :

MicroPython on ESP32 尚未支援藍芽

但到 v1.12 版就開始支援藍芽 (僅 BLE) 了, 模組名稱為 ubluetooth 或 bluetooth, 參考 :

https://docs.micropython.org/en/latest/library/ubluetooth.html

以下為依據官網 API 資料的簡單測試 :

MicroPython v1.12-156-g0852acfc7 on 2020-02-11; ESP32 module with ESP32
Type "help()" for more information.
>>> import ubluetooth as ub
>>> dir(ub) 
['__class__', '__name__', 'BLE', 'FLAG_NOTIFY', 'FLAG_READ', 'FLAG_WRITE', 'UUID']
>>> ub1=ub.BLE()    
>>> type(ub1)    
<class 'BLE'>
>>> dir(ub1)     
['__class__', 'active', 'config', 'gap_advertise', 'gap_connect', 'gap_disconnect', 'gap_scan', 'gattc_discover_characteristics', 'gattc_discover_descriptors', 'gattc_discover_services', 'gattc_read', 'gattc_write', 'gatts_notify', 'gatts_read', 'gatts_register_services', 'gatts_set_buffer', 'gatts_write', 'irq']
>>> ub1.active()    
False
>>> ub1.active(True)   
I (2569560) BTDM_INIT: BT controller compile version [5aed448]
I (2589284) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
W (2589294) phy_init: failed to load RF calibration data (0x1102), falling back to full calibration
I (2589424) phy: phy_version: 4102, 2fa7a43, Jul 15 2019, 13:06:06, 0, 2
GAP procedure initiated: stop advertising.
True 
>>> ub1.config('mac') 
b'\x00\x00\x00\x00@\x00'

果真有 ubluetooth 模組, 但還不會用.

關於藍芽技術參考 :

什麼是藍牙4.0何謂BLE? 藍牙4.0的特色、介紹、技術 

沒有留言 :