コンテンツにスキップ

macOSからESP32をセットアップ

  • ESP32
    • ESP32-WROOM-32D
  • MacBook Air 2020
    • OS: macOS 12.0.1
    • CPU: Apple M1
    • RAM: 16GB
  • USB Type-C → USB Type-A変換アダプタ
    • DST-C02WH

esp32-console.png (577.2 kB)

手順

esptoolをインストール

pipのバージョンを確認

$ pip --version
pip 21.3.1 from /opt/homebrew/lib/python3.9/site-packages/pip (python 3.9)

esptoolをインストール

$ pip install esptool

esptoolがインストールされているか確認

$ which esptool.py
/opt/homebrew/bin/esptool.py

接続先のESP32を探索

esptoolのv2.4からは自動でシリアルポートへ接続を試行する.

$ esptool.py flash_id
esptool.py v3.2
Found 3 serial ports
Serial port /dev/cu.wlan-debug
/dev/cu.wlan-debug failed to connect: [Errno 16] could not open port /dev/cu.wlan-debug: [Errno 16] Resource busy: '/dev/cu.wlan-debug'
Serial port /dev/cu.usbserial-0001
Connecting..............
Detecting chip type... Unsupported detection protocol, switching and trying again...
Connecting........................
Detecting chip type... ESP32
Chip is ESP32-D0WDQ6 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: 4c:eb:d6:75:49:9c
Uploading stub...
Running stub...
Stub running...
Manufacturer: 5e
Device: 4016
Detected flash size: 4MB
Hard resetting via RTS pin...

ESP32へシリアルポートで接続

以下のコマンドでシリアル接続する.接続先は先の結果の Serial port /dev/cu.usbserial-0001 から /dev/cu.usbserial-0001 を使う.また,ボーレートは115200を使う.

screen /dev/cu.usbserial-0001 115200

スクリーンショット 2021-12-30 15.16.26.png (1.2 MB)

ESP32のフラッシュメモリを削除

$ esptool.py --chip esp32 --port /dev/cu.usbserial-0001 erase_flash
esptool.py v3.2
Serial port /dev/cu.usbserial-0001
Connecting..........
Chip is ESP32-D0WDQ6 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: 4c:eb:d6:75:49:9c
Uploading stub...
Running stub...
Stub running...
Erasing flash (this may take a while)...
Chip erase completed successfully in 12.8s
Hard resetting via RTS pin...

ファームウェアの書き込み

以下からファームウェアをダウンロードして,ESP32へ書き込む.

https://micropython.org/download/esp32/

今回はBLEとWi-Fiの両方を使いたいため,IDF 3.xの最新版をダウンロードする.

image.png (569.5 kB)

以下のコマンドで書き込みを行う.

$ esptool.py --chip esp32 --port /dev/cu.usbserial-0001 --baud 460800 write_flash -z 0x1000 ~/Downloads/esp32-idf3-20210202-v1.14.bin
esptool.py v3.2
Serial port /dev/cu.usbserial-0001
Connecting..............
Chip is ESP32-D0WDQ6 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: 4c:eb:d6:75:49:9c
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Flash will be erased from 0x00001000 to 0x00161fff...
Compressed 1445632 bytes to 925476...
Wrote 1445632 bytes (925476 compressed) at 0x00001000 in 22.8 seconds (effective 507.9 kbit/s)...
Hash of data verified.

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

ESP32のMicroPythonへシリアル接続

$ screen /dev/cu.usbserial-0001 115200

image.png (219.1 kB)

抜けるときは Ctrl + AK を押下する.

参考資料

MacでESP32のLチカ(MicroPython/ターミナル版) - Qiita