ESP32のファームウェアアップデート
新品のESP32を仕入れてあったので、microPython仕様にするためファームウェアのアップデートをしました。ファームウェアについてはhttp://micropython.org/download/esp32/に最新版がありますし、アップデートの仕方も説明がしてあります。
まずは元から入っているファームを消去します。ファームの入れ替えはesptool.pyを使用します。今日はUSBのポートはCOM4です。
C:\Users\>esptool.py --chip esp32 --port com4 erase_flash
esptool.py v2.2
Connecting....
Chip is ESP32D0WDQ5 (revision (unknown 0xa))
Uploading stub...
Running stub...
Stub running...
Erasing flash (this may take a while)...
Chip erase completed successfully in 10.3s
Hard resetting...
次にあらかじめダウンロードしているファームウェアを書き込みます。
C:\Users\>esptool.py --chip esp32 --port com4 write_flash -z 0x1000 c:\micropython\esp32-idf3-20210202-v1.14.bin
esptool.py v2.2
Connecting.....
Chip is ESP32D0WDQ5 (revision (unknown 0xa))
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Compressed 1445632 bytes to 925476...
Wrote 1445632 bytes (925476 compressed) at 0x00001000 in 82.8 seconds (effective 139.7 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting...
ampyで確認しようとしましたが、上手くいかず、TeraTermでシリアル接続してファームを確認しました。
ちゃんとファームウェアアップデートされています。
ts 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
MicroPython v1.14 on 2021-02-02; ESP32 module with ESP32
Type "help()" for more information.
>>>
上にあるように、help()コマンドをたたくと、一寸した例文が出ます。
>>> help()
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')
OSのリリース情報とディレクトリ構造を表示したところ、boot.py出来ています。
>> import os
>>> os.uname()
(sysname='esp32', nodename='esp32', release='1.14.0', version='v1.14 on 2021-02-02', machine='ESP32 module with ESP32')
>>> os.listdir()
['boot.py']
再度コマンドプロンプトから、ampyを用いてリスト表示をしたら無事にboot.pyも表示されており、無事にmicroPython仕様になっていることを確認しました。
C:\Users\>ampy -p com4 ls
boot.py

