AMPY–ESP32との通信方法
ESP32をMicroPythonで使用する際には、ファイルのアップロード、ダウンロード、削除などが必要になってくる。
AMPYはコマンドライン(Windowsではコマンドプロンプト)にて対話的に行える。
コマンドプロンプトでampyと入力すると下のような説明が出てくる。
C:\Users\>ampy
Usage: ampy-script.py [OPTIONS] COMMAND [ARGS]...
ampy - Adafruit MicroPython Tool
Ampy is a tool to control MicroPython boards over a serial connection.
Using ampy you can manipulate files on the board's internal filesystem and
even run scripts.
Options:
-p, --port PORT Name of serial port for connected board. Can optionally
specify with AMPY_PORT environemnt variable. [required]
-b, --baud BAUD Baud rate for the serial connection (default 115200).
Can optionally specify with AMPY_BAUD environment
variable.
-d, --delay DELAY Delay in seconds before entering RAW MODE (default 0).
Can optionally specify with AMPY_DELAY environment
variable.
--version Show the version and exit.
--help Show this message and exit.
Commands:
get Retrieve a file from the board.
ls List contents of a directory on the board.
mkdir Create a directory on the board.
put Put a file or folder and its contents on the...
reset Perform soft reset/reboot of the board.
rm Remove a file from the board.
rmdir Forcefully remove a folder and all its...
run Run a script and print its output.
当方のPC環境ではUSBがCOM3ポートになっているので、次のような使い方となる。
ESP32内のファイル表示する場合は -p com3(comポート番号) ls(ファイル表示)を入力する。
C:\Users\>ampy -p com3 ls
boot.py
test.py
main.py
ssd1306.py
hcsr04.py
temp.py
display.py
test3.py
test4.py
distance.py
test_ave.py
test5.py
ESP32上のファイルをPCにダウンロードする場合はgetコマンドを使用する。c:以下はダウンロードするディレクトリとファイル名
C:\Users\>ampy -p com3 get main.py c:\micropython\new\main1.py
ファイルをアップロードするにはputコマンドを使用する。
C:\Users\>ampy -p com3 put c:\micropython\new\main1.py
C:\Users\>ampy -p com3 ls
boot.py
test.py
main.py
ssd1306.py
hcsr04.py
temp.py
display.py
test3.py
test4.py
distance.py
test_ave.py
test5.py
main1.py
ファイルを削除する場合は、rmコマンドを使用する。
C:\Users\>ampy -p com3 rm main1.py
C:\Users\>ampy -p com3 ls
boot.py
test.py
main.py
ssd1306.py
hcsr04.py
temp.py
display.py
test3.py
test4.py
distance.py
test_ave.py
test5.py

