如此簡單 MicroPython - ESP8266/ESP32 MCU 的檔案管理

by Yungger Chen in Circuits > Microcontrollers

1071 Views, 1 Favorites, 0 Comments

如此簡單 MicroPython - ESP8266/ESP32 MCU 的檔案管理

Header.png

使用 ampy 來管理 MCU 上的 MicroPython 檔案

安裝 Ampy

開啟 Terminal 視窗

  • pip install adafruit-ampy

確認安裝

ampy-ls.png

輸入 ampy –help, 出現以下畫面時, 表示已安裝成功


上傳

寫好你的程式, 確認好 board 與 port, 插上 MCU, 就可上傳程式碼了。

  • ampy --port 序列埠裝置名 put 檔案路徑/xxx.py

假設序列埠裝置名是 /dev/cu.usbserial-11440, 而 xxx.py 檔案是 main.py

則輸入 ampy --port /dev/cu.usbserial-11440 put 檔案路徑/main.py

查詢

ampy-ls.png

如果沒有出現任何錯誤訊息的話, 可使用 ls 指令來確認檔案是否已被上傳

  • ampy --port 序列埠裝置名 ls

執行

將 put 指令改為 run 即可

  • ampy --port 序列埠裝置名 put 檔案路徑/xxx.py

*** 若是你上傳的是 boot.py 或 main.py, 它們會自動執行, 所以, 直接按一下 MCU 的 RST 按鍵即可。

其他指令

  • get 下載檔案: ampy --port 序列埠裝置名 get 檔案路徑/xxx.py 本機路徑/xxx.py
  • rm 刪除檔案: ampy --port 序列埠裝置名 rm 檔案路徑/xxx.py
  • mkdir 新增目錄: ampy --port 序列埠裝置名 mkdir xxx
  • rmdir 刪除目錄: ampy --port 序列埠裝置名 rmdir xxx
  • reset 重啟MCU: ampy --port 序列埠裝置名 reset

如此而已, 就是這麼簡單, 希望能對你有一點點的幫助 !

作者:Yungger 勇哥

如果覺得此文對您有幫助, 也願意鼓勵勇哥的繼續創作, 點此加油一下 😘 😘 !!