差分
このページの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:// | ||
+ | |||
+ | ==== Python 仮想環境の作成 ==== | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=GRN> | ||
+ | <b class=GRN> | ||
+ | <b class=YEL> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ==== esptool のインストール ==== | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=YEL> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | Looking in indexes: https:// | ||
+ | Collecting esptool | ||
+ | Downloading https:// | ||
+ | <b style=" | ||
+ | Collecting pyserial> | ||
+ | Downloading https:// | ||
+ | <b style=" | ||
+ | Collecting reedsolo< | ||
+ | Downloading https:// | ||
+ | <b style=" | ||
+ | Collecting cryptography> | ||
+ | Downloading https:// | ||
+ | <b style=" | ||
+ | Collecting bitstring> | ||
+ | Downloading https:// | ||
+ | Collecting ecdsa> | ||
+ | Downloading https:// | ||
+ | <b style=" | ||
+ | Requirement already satisfied: cffi> | ||
+ | Requirement already satisfied: six> | ||
+ | Requirement already satisfied: pycparser in ./ | ||
+ | Installing collected packages: reedsolo, pyserial, bitstring, ecdsa, cryptography, | ||
+ | Successfully installed bitstring-3.1.9 cryptography-36.0.2 ecdsa-0.17.0 esptool-3.3 pyserial-3.5 reedsolo-1.5.4 | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ==== ESP32 の接続ポートを確認 ==== | ||
+ | **ESP32-WROVER-B**\\ | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=YEL> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | 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 | ||
+ | </ | ||
+ | |||
+ | <WRAP color_command>< | ||
+ | <b class=YEL> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | /: Bus 01.Port 1: Dev 1, Class=root_hub, | ||
+ | |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/ | ||
+ | |__ Port 1: Dev 9, If 1, Class=CDC Data, Driver=cdc_acm, | ||
+ | |__ Port 1: Dev 9, If 0, Class=Communications, | ||
+ | |__ Port 2: Dev 3, If 0, Class=Human Interface Device, Driver=usbhid, | ||
+ | |__ Port 2: Dev 3, If 1, Class=Human Interface Device, Driver=usbhid, | ||
+ | |__ Port 3: Dev 4, If 0, Class=Human Interface Device, Driver=usbhid, | ||
+ | </ | ||
+ | |||
+ | <WRAP color_command>< | ||
+ | <b class=YEL> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | total 0 | ||
+ | lrwxrwxrwx 1 root root 13 Apr 22 14:02 platform-20980000.usb-usb-0: | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | **ESP32-WROOM-32 (cp210x)**\\ | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=YEL> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | /: Bus 02.Port 1: Dev 1, Class=root_hub, | ||
+ | |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/ | ||
+ | |__ Port 1: Dev 3, If 0, Class=Hub, Driver=hub/ | ||
+ | |__ Port 2: Dev 5, If 0, Class=Human Interface Device, Driver=usbhid, | ||
+ | |__ Port 2: Dev 5, If 1, Class=Human Interface Device, Driver=usbhid, | ||
+ | |__ Port 2: Dev 5, If 2, Class=Human Interface Device, Driver=usbhid, | ||
+ | |__ Port 6: Dev 4, If 0, Class=Video, | ||
+ | |__ Port 6: Dev 4, If 1, Class=Video, | ||
+ | /: Bus 01.Port 1: Dev 1, Class=root_hub, | ||
+ | |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/ | ||
+ | (pyMicroPython) [tomoyan@highway-x ~]$ lsusb -t | ||
+ | /: Bus 02.Port 1: Dev 1, Class=root_hub, | ||
+ | |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/ | ||
+ | |__ Port 1: Dev 3, If 0, Class=Hub, Driver=hub/ | ||
+ | |__ Port 2: Dev 5, If 0, Class=Human Interface Device, Driver=usbhid, | ||
+ | |__ Port 2: Dev 5, If 1, Class=Human Interface Device, Driver=usbhid, | ||
+ | |__ Port 2: Dev 5, If 2, Class=Human Interface Device, Driver=usbhid, | ||
+ | |__ Port 3: Dev 6, If 0, Class=Vendor Specific Class, Driver=< | ||
+ | |__ Port 6: Dev 4, If 0, Class=Video, | ||
+ | |__ Port 6: Dev 4, If 1, Class=Video, | ||
+ | /: Bus 01.Port 1: Dev 1, Class=root_hub, | ||
+ | |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/ | ||
+ | </ | ||
+ | |||
+ | <WRAP color_command>< | ||
+ | <b class=YEL> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | 合計 0 | ||
+ | lrwxrwxrwx 1 root root 13 10月 18 15:37 <b class=HIC> | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ==== ESP32 のフラッシュを消去 ==== | ||
+ | **ESP32-WROVER-B**\\ | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=YEL> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | esptool.py v3.3 | ||
+ | Serial port / | ||
+ | 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: | ||
+ | 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... | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | **ESP32-WROOM-32**\\ | ||
+ | ※ BOOT ボタンを少し長く押し続けないと、接続に失敗するモデルもある🤔\\ | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=YEL> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | esptool.py v4.3 | ||
+ | Serial port / | ||
+ | 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: | ||
+ | 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... | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ==== MicroPython ファームウェアのダウンロード ==== | ||
+ | MicroPython のファームウェアを [[https:// | ||
+ | **ESP32-WROVER-B**\\ | ||
+ | ※ここでは [[https:// | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=YEL> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | % Total % Received % Xferd Average Speed | ||
+ | | ||
+ | 100 1592k 100 1592k 0 | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | **ESP32-WROOM-32**\\ | ||
+ | ※ここでは [[https:// | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=YEL> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | % Total % Received % Xferd Average Speed | ||
+ | | ||
+ | 100 1524k 100 1524k 0 | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ==== MicroPython のファームウェアを ESP32 にフラッシュ ==== | ||
+ | **ESP32-WROVER-B**\\ | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=YEL> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | esptool.py v3.3 | ||
+ | Serial port / | ||
+ | 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: | ||
+ | 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... | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | **ESP32-WROOM-32**\\ | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=YEL> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | esptool.py v4.3 | ||
+ | Serial port / | ||
+ | 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: | ||
+ | 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... | ||
+ | </ | ||
+ | </ | ||
+ | ==== シリアルコンソールに接続する前に、ポートへのアクセス権限を設定 ==== | ||
+ | **/ | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=YEL> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | crw-rw---- 1 root dialout 166, 0 Apr 23 01:09 <b class=YEL>/ | ||
+ | </ | ||
+ | </ | ||
+ | または、**/ | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=YEL> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | crw-rw---- 1 root dialout 188, 0 10月 18 16:26 <b class=YEL>/ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ユーザーを **dialout** グループに所属させる。\\ | ||
+ | [[: | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=YEL> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | uid=1000(dietpi) gid=1000(dietpi) groups=1000(dietpi) | ||
+ | </ | ||
+ | <WRAP color_command>< | ||
+ | <b class=YEL> | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=YEL> | ||
+ | <b class=YEL> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | uid=1000(dietpi) gid=1000(dietpi) groups=1000(dietpi), | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ==== ESP32 MicroPython のシリアルコンソールに接続 ==== | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=YEL> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | </ | ||
+ | </ | ||
+ | または\\ | ||
+ | 接続後に本体の EN ボタンを押すと MicroPython バージョンが表示される🤔\\ | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=YEL> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | ets Jun 8 2016 00:22:57 | ||
+ | |||
+ | rst:0x1 (POWERON_RESET), | ||
+ | configsip: 0, SPIWP:0xee | ||
+ | clk_drv: | ||
+ | mode:DIO, clock div:2 | ||
+ | load: | ||
+ | ho 0 tail 12 room 4 | ||
+ | load: | ||
+ | ho 0 tail 12 room 4 | ||
+ | load: | ||
+ | entry 0x40080680 | ||
+ | MicroPython v1.19.1 on 2022-06-18; ESP32 module with ESP32 | ||
+ | Type " | ||
+ | <b class=GRN>& | ||
+ | </ | ||
+ | </ | ||
+ | ※接続を終了するには< | ||
+ | |||
+ | === ESP32 MicroPython の help() === | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=GRN>& | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | Welcome to MicroPython on the ESP32! | ||
+ | |||
+ | For generic online docs please visit http:// | ||
+ | |||
+ | For access to the hardware use the ' | ||
+ | |||
+ | import machine | ||
+ | pin12 = machine.Pin(12, | ||
+ | pin12.value(1) | ||
+ | pin13 = machine.Pin(13, | ||
+ | print(pin13.value()) | ||
+ | i2c = machine.I2C(scl=machine.Pin(21), | ||
+ | i2c.scan() | ||
+ | i2c.writeto(addr, | ||
+ | i2c.readfrom(addr, | ||
+ | |||
+ | Basic WiFi configuration: | ||
+ | |||
+ | import network | ||
+ | sta_if = network.WLAN(network.STA_IF); | ||
+ | sta_if.scan() | ||
+ | sta_if.connect("< | ||
+ | sta_if.isconnected() | ||
+ | |||
+ | Control commands: | ||
+ | CTRL-A | ||
+ | CTRL-B | ||
+ | CTRL-C | ||
+ | CTRL-D | ||
+ | CTRL-E | ||
+ | |||
+ | For further help on a specific object, type help(obj) | ||
+ | For a list of available modules, type help(' | ||
+ | <b class=GRN>& | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ===== ampy - Adafruit MicroPython Tool ===== | ||
+ | <WRAP round alert 90%> | ||
+ | **ampy は Adafruit が今後サポートしなくなる...🤔**\\ | ||
+ | [[https:// | ||
+ | \\ | ||
+ | Adafruit は CircuitPython のみをサポートするので、MicroPython 用の ampy は今後メンテされない😱😇\\ | ||
+ | ampy での実行例を載せているサイトは古い情報なので、MicroPython 公式ドキュメントに記載されている < | ||
+ | < | ||
+ | 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, | ||
+ | </ | ||
+ | < | ||
+ | このガイドの例はサポートされなくなり、機能しない可能性があります。 | ||
+ | ボードでは CircuitPython のみをサポートしています。 | ||
+ | CircuitPython の使用に関する詳細については、CircuitPython へようこそ: | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | **ampy のインストール**\\ | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=YEL> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | Looking in indexes: https:// | ||
+ | Collecting adafruit-ampy | ||
+ | Downloading https:// | ||
+ | Collecting python-dotenv | ||
+ | Downloading https:// | ||
+ | Collecting click | ||
+ | Downloading https:// | ||
+ | <b style=" | ||
+ | Requirement already satisfied: pyserial in ./ | ||
+ | Installing collected packages: python-dotenv, | ||
+ | Successfully installed adafruit-ampy-1.1.0 click-8.1.2 python-dotenv-0.20.0 | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | **動作確認**\\ | ||
+ | <WRAP color_term> | ||
+ | |||
+ | <WRAP color_command>< | ||
+ | <b class=YEL> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | 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' | ||
+ | even run scripts. | ||
+ | |||
+ | Options: | ||
+ | -p, --port PORT Name of serial port for connected board. | ||
+ | | ||
+ | -b, --baud BAUD Baud rate for the serial connection (default 115200). | ||
+ | Can optionally specify with AMPY_BAUD environment | ||
+ | | ||
+ | -d, --delay DELAY Delay in seconds before entering RAW MODE (default 0). | ||
+ | Can optionally specify with AMPY_DELAY environment | ||
+ | | ||
+ | --version | ||
+ | --help | ||
+ | |||
+ | 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/ | ||
+ | rm | ||
+ | rmdir Forcefully remove a folder and all its children from the board. | ||
+ | run Run a script and print its output. | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | **ESP32 内部のファイルを一覧表示**\\ | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=YEL> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | /boot.py | ||
+ | </ | ||
+ | </ | ||
+ | または\\ | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=YEL> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | /boot.py | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | **ファイル内容の表示**\\ | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=YEL> | ||
+ | </ | ||
+ | <WRAP color_code>< | ||
+ | # This file is executed on every boot (including wake-boot from deepsleep) | ||
+ | #import esp | ||
+ | # | ||
+ | #import webrepl | ||
+ | # | ||
+ | </ | ||
+ | </ | ||
+ | または\\ | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=YEL> | ||
+ | </ | ||
+ | <WRAP color_code>< | ||
+ | # This file is executed on every boot (including wake-boot from deepsleep) | ||
+ | #import esp | ||
+ | # | ||
+ | #import webrepl | ||
+ | # | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ===== 参考文献 ===== | ||
+ | [[https:// | ||
+ | [[https:// | ||
+ | [[https:// | ||
+ | [[https:// | ||
+ | [[https:// | ||
+ | [[https:// | ||
+ | [[https:// | ||
+ | [[https:// | ||
+ | [[https:// | ||
+ | |||
+ | ==== 付録 ==== | ||
+ | [[tw> | ||
+ | [[tw> | ||