hardware:microcontroller:esp32:install_micropython

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン 前のリビジョン
最新のリビジョン両方とも次のリビジョン
hardware:microcontroller:esp32:install_micropython [2024/01/05 13:40] – 削除 - 外部編集 (Unknown date) 非ログインユーザーhardware:microcontroller:esp32:install_micropython [2024/01/05 13:40] – ↷ hardware:arduino:esp32:install_micropython から hardware:microcontroller:esp32:install_micropython へページを移動しました。 ともやん
行 1: 行 1:
 +====== ESP32 MicroPython ======
 +
 +===== インストール =====
 +Raspberry Pi Zero で ESP32-WROVER-B に MicroPython をフラッシュする。\\
 +Fedora で ESP32-WROOM-32 をフラッシュする手順も追記。\\
 +参考: [[https://micropython-docs-ja.readthedocs.io/ja/latest/esp32/tutorial/intro.html|1. ESP32 での MicroPython の始め方 — MicroPython 1.18 ドキュメント]]\\
 +
 +==== Python 仮想環境の作成 ====
 +<WRAP color_term>
 +<WRAP color_command><html><pre>
 +<b class=GRN>$</b> <b class=HIY>python</b> <b class=HIK>-m</b> venv pyMicroPython
 +<b class=GRN>$</b> . pyMicroPython/bin/<b class=HIY>activate</b>
 +<b class=YEL>(pyMicroPython)</b> <b class=GRN>$</b>
 +</pre></html></WRAP>
 +<WRAP color_result><html><pre>
 +</pre></html></WRAP>
 +</WRAP>
 +
 +==== esptool のインストール ====
 +<WRAP color_term>
 +<WRAP color_command><html><pre>
 +<b class=YEL>(pyMicroPython)</b> <b class=GRN>$</b> <b class=HIY>pip</b> install esptool
 +</pre></html></WRAP>
 +<WRAP color_result><html><pre>
 +Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple/
 +Collecting esptool
 +  Downloading https://www.piwheels.org/simple/esptool/esptool-3.3-py3-none-any.whl (345 kB)
 +     <b style="color:#87af5f;">━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━</b> <b class=GRN>345.0/345.0 KB</b> <b class=RED>282.0 kB/s</b> eta <b class=CYN>0:00:00</b>
 +Collecting pyserial>=3.0
 +  Downloading https://www.piwheels.org/simple/pyserial/pyserial-3.5-py2.py3-none-any.whl (90 kB)
 +     <b style="color:#87af5f;">━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━</b> <b class=GRN>90.6/90.6 KB</b> <b class=RED>109.1 kB/s</b> eta <b class=CYN>0:00:00</b>
 +Collecting reedsolo<=1.5.4,>=1.5.3
 +  Downloading https://www.piwheels.org/simple/reedsolo/reedsolo-1.5.4-cp39-cp39-linux_armv6l.whl (921 kB)
 +     <b style="color:#87af5f;">━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━</b> <b class=GRN>921.3/921.3 KB</b> <b class=RED>536.7 kB/s</b> eta <b class=CYN>0:00:00</b>
 +Collecting cryptography>=2.1.4
 +  Downloading https://www.piwheels.org/simple/cryptography/cryptography-36.0.2-cp39-cp39-linux_armv6l.whl (2.7 MB)
 +     <b style="color:#87af5f;">━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━</b> <b class=GRN>2.7/2.7 MB</b> <b class=RED>453.0 kB/s</b> eta <b class=CYN>0:00:00</b>
 +Collecting bitstring>=3.1.6
 +  Downloading https://www.piwheels.org/simple/bitstring/bitstring-3.1.9-py3-none-any.whl (39 kB)
 +Collecting ecdsa>=0.16.0
 +  Downloading https://www.piwheels.org/simple/ecdsa/ecdsa-0.17.0-py2.py3-none-any.whl (119 kB)
 +     <b style="color:#87af5f;">━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━</b> <b class=GRN>119.3/119.3 KB</b> <b class=RED>186.5 kB/s</b> eta <b class=CYN>0:00:00</b>
 +Requirement already satisfied: cffi>=1.12 in ./pyJupyterLab/lib/python3.9/site-packages (from cryptography>=2.1.4->esptool) (1.15.0)
 +Requirement already satisfied: six>=1.9.0 in ./pyJupyterLab/lib/python3.9/site-packages (from ecdsa>=0.16.0->esptool) (1.16.0)
 +Requirement already satisfied: pycparser in ./pyJupyterLab/lib/python3.9/site-packages (from cffi>=1.12->cryptography>=2.1.4->esptool) (2.21)
 +Installing collected packages: reedsolo, pyserial, bitstring, ecdsa, cryptography, esptool
 +Successfully installed bitstring-3.1.9 cryptography-36.0.2 ecdsa-0.17.0 esptool-3.3 pyserial-3.5 reedsolo-1.5.4
 +</pre></html></WRAP>
 +</WRAP>
 +
 +==== ESP32 の接続ポートを確認 ====
 +**ESP32-WROVER-B**\\
 +<WRAP color_term>
 +<WRAP color_command><html><pre>
 +<b class=YEL>(pyMicroPython)</b> <b class=GRN>$</b> <b class=HIY>lsusb</b>
 +</pre></html></WRAP>
 +<WRAP color_result><html><pre>
 +Bus 001 Device 004: ID 056e:0063 Elecom Co., Ltd Laser mouse M-SODL
 +Bus 001 Device 003: ID 05af:0908 Jing-Mold Enterprise Co., Ltd Wireless Keyboard
 +Bus 001 Device 009: ID 1a86:55d4 QinHeng Electronics USB Single Serial
 +Bus 001 Device 002: ID 1a40:0101 Terminus Technology Inc. Hub
 +Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
 +</pre></html></WRAP>
 +
 +<WRAP color_command><html><pre>
 +<b class=YEL>(pyMicroPython)</b> <b class=GRN>$</b> <b class=HIY>lsusb</b> <b class=HIK>-t</b>
 +</pre></html></WRAP>
 +<WRAP color_result><html><pre>
 +/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=dwc_otg/1p, 480M
 +    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 480M
 +        |__ Port 1: Dev 9, If 1, Class=CDC Data, Driver=cdc_acm, 12M
 +        |__ Port 1: Dev 9, If 0, Class=Communications, Driver=cdc_acm, 12M
 +        |__ Port 2: Dev 3, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
 +        |__ Port 2: Dev 3, If 1, Class=Human Interface Device, Driver=usbhid, 1.5M
 +        |__ Port 3: Dev 4, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
 +</pre></html></WRAP>
 +
 +<WRAP color_command><html><pre>
 +<b class=YEL>(pyMicroPython)</b> <b class=GRN>$</b> <b class=HIY>ls</b> <b class=HIK>-l</b> /dev/serial/by-path/
 +</pre></html></WRAP>
 +<WRAP color_result><html><pre>
 +total 0
 +lrwxrwxrwx 1 root root 13 Apr 22 14:02 platform-20980000.usb-usb-0:1.1:1.0 -> ../../ttyACM0
 +</pre></html></WRAP>
 +</WRAP>
 +
 +**ESP32-WROOM-32 (cp210x)**\\
 +<WRAP color_term>
 +<WRAP color_command><html><pre>
 +<b class=YEL>(pyMicroPython)</b> <b class=GRN>$</b> <b class=HIY>lsusb</b> <b class=HIK>-t</b>
 +</pre></html></WRAP>
 +<WRAP color_result><html><pre>
 +/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/3p, 480M
 +    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/8p, 480M
 +        |__ Port 1: Dev 3, If 0, Class=Hub, Driver=hub/4p, 480M
 +            |__ Port 2: Dev 5, If 0, Class=Human Interface Device, Driver=usbhid, 12M
 +            |__ Port 2: Dev 5, If 1, Class=Human Interface Device, Driver=usbhid, 12M
 +            |__ Port 2: Dev 5, If 2, Class=Human Interface Device, Driver=usbhid, 12M
 +        |__ Port 6: Dev 4, If 0, Class=Video, Driver=uvcvideo, 480M
 +        |__ Port 6: Dev 4, If 1, Class=Video, Driver=uvcvideo, 480M
 +/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/3p, 480M
 +    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/6p, 480M
 +(pyMicroPython) [tomoyan@highway-x ~]$ lsusb -t
 +/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/3p, 480M
 +    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/8p, 480M
 +        |__ Port 1: Dev 3, If 0, Class=Hub, Driver=hub/4p, 480M
 +            |__ Port 2: Dev 5, If 0, Class=Human Interface Device, Driver=usbhid, 12M
 +            |__ Port 2: Dev 5, If 1, Class=Human Interface Device, Driver=usbhid, 12M
 +            |__ Port 2: Dev 5, If 2, Class=Human Interface Device, Driver=usbhid, 12M
 +            |__ Port 3: Dev 6, If 0, Class=Vendor Specific Class, Driver=<b class=DiYE>cp210x</b>, 12M
 +        |__ Port 6: Dev 4, If 0, Class=Video, Driver=uvcvideo, 480M
 +        |__ Port 6: Dev 4, If 1, Class=Video, Driver=uvcvideo, 480M
 +/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/3p, 480M
 +    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/6p, 480M
 +</pre></html></WRAP>
 +
 +<WRAP color_command><html><pre>
 +<b class=YEL>(pyMicroPython)</b> <b class=GRN>$</b> <b class=HIY>ls</b> <b class=HIK>-l</b> /dev/serial/by-path/
 +</pre></html></WRAP>
 +<WRAP color_result><html><pre>
 +合計 0
 +lrwxrwxrwx 1 root root 13 10月 18 15:37 <b class=HIC>pci-0000:00:1d.0-usb-0:1.1.3:1.0-port0</b> -> <b class=BYEL>../../ttyUSB0</b>
 +</pre></html></WRAP>
 +</WRAP>
 +
 +==== ESP32 のフラッシュを消去 ====
 +**ESP32-WROVER-B**\\
 +<WRAP color_term>
 +<WRAP color_command><html><pre>
 +<b class=YEL>(pyMicroPython)</b> <b class=GRN>$</b> <b class=HIY>esptool.py</b> <b class=HIK>--port</b> /dev/ttyACM0 erase_flash
 +</pre></html></WRAP>
 +<WRAP color_result><html><pre>
 +esptool.py v3.3
 +Serial port /dev/ttyACM0
 +Connecting....
 +Detecting chip type... Unsupported detection protocol, switching and trying again...
 +Connecting.....
 +Detecting chip type... ESP32
 +Chip is ESP32-D0WD (revision 1)
 +Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
 +Crystal is 40MHz
 +MAC: 4c:75:25:xx:xx:xx
 +Uploading stub...
 +Running stub...
 +Stub running...
 +Erasing flash (this may take a while)...
 +Chip erase completed successfully in 17.8s
 +Hard resetting via RTS pin...
 +</pre></html></WRAP>
 +</WRAP>
 +
 +**ESP32-WROOM-32**\\
 +※ BOOT ボタンを少し長く押し続けないと、接続に失敗するモデルもある🤔\\
 +<WRAP color_term>
 +<WRAP color_command><html><pre>
 +<b class=YEL>(pyMicroPython)</b> <b class=GRN>$</b> <b class=HIY>esptool.py</b> <b class=HIK>--chip</b> esp32 <b class=HIK>--port</b> /dev/ttyUSB0 erase_flash
 +</pre></html></WRAP>
 +<WRAP color_result><html><pre>
 +esptool.py v4.3
 +Serial port /dev/ttyUSB0
 +Connecting......................
 +Chip is ESP32-D0WDQ6 (revision v1.0)
 +Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
 +Crystal is 40MHz
 +MAC: 7c:9e:bd:36:81:8c
 +Uploading stub...
 +Running stub...
 +Stub running...
 +Erasing flash (this may take a while)...
 +Chip erase completed successfully in 12.5s
 +Hard resetting via RTS pin...
 +</pre></html></WRAP>
 +</WRAP>
 +
 +==== MicroPython ファームウェアのダウンロード ====
 +MicroPython のファームウェアを [[https://micropython.org/download/|MicroPython - Python for microcontrollers]] よりダウンロードする。\\
 +**ESP32-WROVER-B**\\
 +※ここでは [[https://micropython.org/download/esp32spiram/|ESP32 with SPIRAM]] の最新リリースをダウンロードする。\\
 +<WRAP color_term>
 +<WRAP color_command><html><pre>
 +<b class=YEL>(pyMicroPython)</b> <b class=GRN>$</b> <b class=HIY>curl</b> <b class=HIK>-O</b> https://micropython.org/resources/firmware/esp32spiram-20220117-v1.18.bin
 +</pre></html></WRAP>
 +<WRAP color_result><html><pre>
 +  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
 +                                 Dload  Upload   Total   Spent    Left  Speed
 +100 1592k  100 1592k    0       264k      0  0:00:06  0:00:06 --:--:--  380k
 +</pre></html></WRAP>
 +</WRAP>
 +
 +**ESP32-WROOM-32**\\
 +※ここでは [[https://micropython.org/download/esp32/|ESP32]] の最新リリースをダウンロードする。\\
 +<WRAP color_term>
 +<WRAP color_command><html><pre>
 +<b class=YEL>(pyMicroPython)</b> <b class=GRN>$</b> <b class=HIY>curl</b> <b class=HIK>-O</b> https://micropython.org/resources/firmware/esp32-20220618-v1.19.1.bin
 +</pre></html></WRAP>
 +<WRAP color_result><html><pre>
 +  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
 +                                 Dload  Upload   Total   Spent    Left  Speed
 +100 1524k  100 1524k    0       440k      0  0:00:03  0:00:03 --:--:--  441k
 +</pre></html></WRAP>
 +</WRAP>
 +
 +==== MicroPython のファームウェアを ESP32 にフラッシュ ====
 +**ESP32-WROVER-B**\\
 +<WRAP color_term>
 +<WRAP color_command><html><pre>
 +<b class=YEL>(pyMicroPython)</b> <b class=GRN>$</b> <b class=HIY>esptool.py</b> <b class=HIK>--chip</b> esp32 --port /dev/ttyACM0 write_flash -z 0x1000 esp32spiram-20220117-v1.18.bin
 +</pre></html></WRAP>
 +<WRAP color_result><html><pre>
 +esptool.py v3.3
 +Serial port /dev/ttyACM0
 +Connecting......
 +Chip is ESP32-D0WD (revision 1)
 +Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
 +Crystal is 40MHz
 +MAC: 4c:75:25:xx:xx:xx
 +Uploading stub...
 +Running stub...
 +Stub running...
 +Configuring flash size...
 +Flash will be erased from 0x00001000 to 0x0018ffff...
 +Compressed 1631216 bytes to 1052559...
 +Wrote 1631216 bytes (1052559 compressed) at 0x00001000 in 99.2 seconds (effective 131.5 kbit/s)...
 +Hash of data verified.
 +
 +Leaving...
 +Hard resetting via RTS pin...
 +</pre></html></WRAP>
 +</WRAP>
 +
 +**ESP32-WROOM-32**\\
 +<WRAP color_term>
 +<WRAP color_command><html><pre>
 +<b class=YEL>(pyMicroPython)</b> <b class=GRN>$</b> <b class=HIY>esptool.py</b> <b class=HIK>--chip</b> esp32 <b class=HIK>--port</b> /dev/ttyUSB0 <b class=HIK>--baud</b> 460800 write_flash <b class=HIK>-z</b> 0x1000 esp32-20220618-v1.19.1.bin
 +</pre></html></WRAP>
 +<WRAP color_result><html><pre>
 +esptool.py v4.3
 +Serial port /dev/ttyUSB0
 +Connecting.........
 +Chip is ESP32-D0WDQ6 (revision v1.0)
 +Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
 +Crystal is 40MHz
 +MAC: 7c:9e:bd:xx:xx:xx
 +Uploading stub...
 +Running stub...
 +Stub running...
 +Changing baud rate to 460800
 +Changed.
 +Configuring flash size...
 +Flash will be erased from 0x00001000 to 0x0017efff...
 +Compressed 1560976 bytes to 1029132...
 +Wrote 1560976 bytes (1029132 compressed) at 0x00001000 in 24.2 seconds (effective 515.7 kbit/s)...
 +Hash of data verified.
 +
 +Leaving...
 +Hard resetting via RTS pin...
 +</pre></html></WRAP>
 +</WRAP>
 +==== シリアルコンソールに接続する前に、ポートへのアクセス権限を設定 ====
 +**/dev/ttyACM0** の権限を調べる。\\
 +<WRAP color_term>
 +<WRAP color_command><html><pre>
 +<b class=YEL>(pyMicroPython)</b> <b class=GRN>$</b> <b class=HIY>ls</b> <b class=HIK>-l</b> /dev/ttyACM0
 +</pre></html></WRAP>
 +<WRAP color_result><html><pre>
 +crw-rw---- 1 root dialout 166, 0 Apr 23 01:09 <b class=YEL>/dev/ttyACM0</b>
 +</pre></html></WRAP>
 +</WRAP>
 +または、**/dev/ttyUSB0** の権限を調べる。\\
 +<WRAP color_term>
 +<WRAP color_command><html><pre>
 +<b class=YEL>(pyMicroPython)</b> <b class=GRN>$</b> <b class=HIY>ls</b> <b class=HIK>-l</b> /dev/ttyUSB0
 +</pre></html></WRAP>
 +<WRAP color_result><html><pre>
 +crw-rw---- 1 root dialout 188, 0 10月 18 16:26 <b class=YEL>/dev/ttyUSB0</b>
 +</pre></html></WRAP>
 +</WRAP>
 +
 +ユーザーを **dialout** グループに所属させる。\\
 +[[:linux:manage_user_group|Linux ユーザー・グループ管理]] 参照のこと\\
 +<WRAP color_term>
 +<WRAP color_command><html><pre>
 +<b class=YEL>(pyMicroPython)</b> <b class=GRN>$</b> <b class=HIY>id</b> dietpi
 +</pre></html></WRAP>
 +<WRAP color_result><html><pre>
 +uid=1000(dietpi) gid=1000(dietpi) groups=1000(dietpi)
 +</pre></html></WRAP>
 +<WRAP color_command><html><pre>
 +<b class=YEL>(pyMicroPython)</b> <b class=GRN>$</b> <b class=HIY>sudo</b> usermod <b class=HIK>-a -G</b> dialout $USER
 +</pre></html></WRAP>
 +</WRAP>
 +
 +<html><code>dialout</code></html> グループへの所属を再ログインせずに反映するには <html><code>newgrp dialout</code></html> コマンドを実行する🤔\\
 +<WRAP color_term>
 +<WRAP color_command><html><pre>
 +<b class=YEL>(pyMicroPython)</b> <b class=GRN>$</b> <b class=HIY>newgrp</b> dialout
 +<b class=YEL>(pyMicroPython)</b> <b class=GRN>$</b> <b class=HIY>id</b>
 +</pre></html></WRAP>
 +<WRAP color_result><html><pre>
 +uid=1000(dietpi) gid=1000(dietpi) groups=1000(dietpi),20(dialout)
 +</pre></html></WRAP>
 +</WRAP>
 +
 +==== ESP32 MicroPython のシリアルコンソールに接続 ====
 +<WRAP color_term>
 +<WRAP color_command><html><pre>
 +<b class=YEL>(pyMicroPython)</b> <b class=GRN>$</b> <b class=HIY>screen</b> /dev/ttyACM0 115200
 +</pre></html></WRAP>
 +<WRAP color_result><html><pre>
 +</pre></html></WRAP>
 +</WRAP>
 +または\\
 +接続後に本体の EN ボタンを押すと MicroPython バージョンが表示される🤔\\
 +<WRAP color_term>
 +<WRAP color_command><html><pre>
 +<b class=YEL>(pyMicroPython)</b> <b class=GRN>$</b> <b class=HIY>screen</b> /dev/ttyUSB0 115200
 +</pre></html></WRAP>
 +<WRAP color_result><html><pre>
 +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:0x3fff0030,len:4540
 +ho 0 tail 12 room 4
 +load:0x40078000,len:12344
 +ho 0 tail 12 room 4
 +load:0x40080400,len:4124
 +entry 0x40080680
 +MicroPython v1.19.1 on 2022-06-18; ESP32 module with ESP32
 +Type "help()" for more information.
 +<b class=GRN>&gt;&gt;&gt;</b> 
 +</pre></html></WRAP>
 +</WRAP>
 +※接続を終了するには<html><code>Ctrl + a</code> -> <code>k</code></html> **Really kill this window [y/n]** に **y** で答える。\\
 +
 +=== ESP32 MicroPython の help() ===
 +<WRAP color_term>
 +<WRAP color_command><html><pre>
 +<b class=GRN>&gt;&gt;&gt;</b> <b class=HIY>help</b>()
 +</pre></html></WRAP>
 +<WRAP color_result><html><pre>
 +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')
 +<b class=GRN>&gt;&gt;&gt;</b> 
 +</pre></html></WRAP>
 +</WRAP>
 +
 +===== ampy - Adafruit MicroPython Tool =====
 +<WRAP round alert 90%>
 +**ampy は Adafruit が今後サポートしなくなる...🤔**\\
 +[[https://learn.adafruit.com/micropython-basics-load-files-and-run-code/install-ampy|MicroPython Basics: Load Files & Run Code - Adafruit]] より\\
 +\\
 +Adafruit は CircuitPython のみをサポートするので、MicroPython 用の ampy は今後メンテされない😱😇\\
 +ampy での実行例を載せているサイトは古い情報なので、MicroPython 公式ドキュメントに記載されている <html><code>mpremote</code></html> [[https://micropython-docs-ja.readthedocs.io/ja/latest/reference/mpremote.html|MicroPython のリモート制御: mpremote]] での操作に置き換える😉\\
 +<code>
 +The examples in this guide are no longer supported and may not work.
 +We are only supporting CircuitPython on our boards.
 +For more information about using CircuitPython, check out Welcome to CircuitPython: https://learn.adafruit.com/welcome-to-circuitpython
 +</code>
 +<code>
 +このガイドの例はサポートされなくなり、機能しない可能性があります。
 +ボードでは CircuitPython のみをサポートしています。
 +CircuitPython の使用に関する詳細については、CircuitPython へようこそ: https://learn.adafruit.com/welcome-to-circuitpython を参照してください。
 +</code>
 +</WRAP>
 +
 +**ampy のインストール**\\
 +<WRAP color_term>
 +<WRAP color_command><html><pre>
 +<b class=YEL>(pyMicroPython)</b> <b class=GRN>$</b> <b class=HIY>pip</b> install adafruit-ampy
 +</pre></html></WRAP>
 +<WRAP color_result><html><pre>
 +Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple/
 +Collecting adafruit-ampy
 +  Downloading https://www.piwheels.org/simple/adafruit-ampy/adafruit_ampy-1.1.0-py2.py3-none-any.whl (16 kB)
 +Collecting python-dotenv
 +  Downloading https://www.piwheels.org/simple/python-dotenv/python_dotenv-0.20.0-py3-none-any.whl (17 kB)
 +Collecting click
 +  Downloading https://www.piwheels.org/simple/click/click-8.1.2-py3-none-any.whl (96 kB)
 +     <b style="color:#87af5f;">━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━</b> <b class=GRN>96.6/96.6 KB</b> <b class=RED>128.8 kB/s</b> eta <b class=CYN>0:00:00</b>
 +Requirement already satisfied: pyserial in ./pyJupyterLab/lib/python3.9/site-packages (from adafruit-ampy) (3.5)
 +Installing collected packages: python-dotenv, click, adafruit-ampy
 +Successfully installed adafruit-ampy-1.1.0 click-8.1.2 python-dotenv-0.20.0
 +</pre></html></WRAP>
 +</WRAP>
 +
 +**動作確認**\\
 +<WRAP color_term>
 +
 +<WRAP color_command><html><pre>
 +<b class=YEL>(pyMicroPython)</b> <b class=GRN>$</b> <b class=HIY>ampy</b> <b class=HIK>--help</b>
 +</pre></html></WRAP>
 +<WRAP color_result><html><pre>
 +Usage: ampy [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 environment 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 board.
 +  reset  Perform soft reset/reboot of the board.
 +  rm     Remove a file from the board.
 +  rmdir  Forcefully remove a folder and all its children from the board.
 +  run    Run a script and print its output.
 +</pre></html></WRAP>
 +</WRAP>
 +
 +**ESP32 内部のファイルを一覧表示**\\
 +<WRAP color_term>
 +<WRAP color_command><html><pre>
 +<b class=YEL>(pyMicroPython)</b> <b class=GRN>$</b> <b class=HIY>ampy</b> <b class=HIK>--port</b> /dev/ttyACM0 ls
 +</pre></html></WRAP>
 +<WRAP color_result><html><pre>
 +/boot.py
 +</pre></html></WRAP>
 +</WRAP>
 +または\\
 +<WRAP color_term>
 +<WRAP color_command><html><pre>
 +<b class=YEL>(pyMicroPython)</b> <b class=GRN>$</b> <b class=HIY>ampy</b> <b class=HIK>--port</b> /dev/ttyUSB0 ls
 +</pre></html></WRAP>
 +<WRAP color_result><html><pre>
 +/boot.py
 +</pre></html></WRAP>
 +</WRAP>
 +
 +**ファイル内容の表示**\\
 +<WRAP color_term>
 +<WRAP color_command><html><pre>
 +<b class=YEL>(pyMicroPython)</b> <b class=GRN>$</b> <b class=HIY>ampy</b> <b class=HIK>--port</b> /dev/ttyACM0 get boot.py
 +</pre></html></WRAP>
 +<WRAP color_code><code python>
 +# This file is executed on every boot (including wake-boot from deepsleep)
 +#import esp
 +#esp.osdebug(None)
 +#import webrepl
 +#webrepl.start()
 +</code></WRAP>
 +</WRAP>
 +または\\
 +<WRAP color_term>
 +<WRAP color_command><html><pre>
 +<b class=YEL>(pyMicroPython)</b> <b class=GRN>$</b> <b class=HIY>ampy</b> <b class=HIK>--port</b> /dev/ttyUSB0 get boot.py
 +</pre></html></WRAP>
 +<WRAP color_code><code python>
 +# This file is executed on every boot (including wake-boot from deepsleep)
 +#import esp
 +#esp.osdebug(None)
 +#import webrepl
 +#webrepl.start()
 +</code></WRAP>
 +</WRAP>
 +
 +===== 参考文献 =====
 +[[https://micropython-docs-ja.readthedocs.io/ja/latest/esp32/tutorial/intro.html|1. ESP32 での MicroPython の始め方 — MicroPython 1.18 ドキュメント]]\\
 +[[https://wiki.archlinux.jp/index.php/%E3%82%B7%E3%83%AA%E3%82%A2%E3%83%AB%E3%82%B3%E3%83%B3%E3%82%BD%E3%83%BC%E3%83%AB|シリアルコンソール - ArchWiki]]\\
 +[[https://unix.stackexchange.com/questions/22545/how-to-connect-to-a-serial-port-as-simple-as-using-ssh|How to connect to a serial port as simple as using SSH?]]\\
 +[[https://www.digikey.jp/en/maker/projects/micropython-basics-load-files-run-code/fb1fcedaf11e4547943abfdd8ad825ce|MicroPython Basics: Load Files & Run Code]]\\
 +[[https://hassiweb-programming.blogspot.com/2020/02/serial-comm-on-linux.html|Linux でシリアル通信を行う方法]]\\
 +[[https://chakoku.hatenablog.com/entry/2019/07/20/093720|ESP32 WROVER-B を使ってみる(SPI RAM対応版 MicroPython導入) - chakokuのブログ(rev4)]]\\
 +[[https://technoglitz.com/japan/upip%E3%82%92%E4%BD%BF%E7%94%A8%E3%81%97%E3%81%A6%E3%80%81micropython%E3%83%A9%E3%82%A4%E3%83%96%E3%83%A9%E3%83%AA%E3%82%92wi-fi%E7%B5%8C%E7%94%B1%E3%81%A7%E3%83%9E%E3%82%A4%E3%82%AF%E3%83%AD%E3%82%B3/|Upipを使用して、MicroPythonライブラリをWi-Fi経由でマイクロコンピュータにロードします«ヌルバイト:: WonderHowTo]]\\
 +[[https://micropython-docs-ja.readthedocs.io/ja/latest/esp8266/tutorial/ssd1306.html|14. SSD1306 OLED ディスプレイの使い方 — MicroPython 1.18 ドキュメント]]\\
 +[[https://micropython-docs-ja.readthedocs.io/ja/latest/library/machine.SDCard.html#machine.SDCard|クラス SDCard -- SD メモリカード — MicroPython 1.18 ドキュメント]]\\
 +
 +==== 付録 ====
 +[[tw>tomoyan596/status/1517600822838067200|Arduino IDEのビルドとマイコンへのフラッシュ時間短縮したくて、ESP32でMicroPython始めました🥰Raspberry Pi ZeroからMicroPythonをフラッシュする手順をメモ✍️してあります😊]]\\
 +[[tw>tomoyan596/status/1519525936286539776|うちにMOSFETあったかなぁ🤔]]\\
  
  • hardware/microcontroller/esp32/install_micropython.txt
  • 最終更新: 2024/04/19 10:47
  • by 非ログインユーザー