0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

MicroPython のスクリプトを VScode で書き、mpremoteで実行する

Last updated at Posted at 2024-09-07

初めて tasks.jsonlaunch.json を書いてみた。
誤っていたらご容赦ください

Terminal で 準備

  • プロジェクトフォルダーを作る
  • プロジェクトフォルダーで .venv を構成
$ echo .venv >.gitignore
$ python3 -m venv .venv
$ . .venv/bin/activate.fish
(.venv) $ python -m pip install mpremote

VS Code で準備

Geminiに教えてもらいました...

launch.json
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python Debugger: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        }
    ]
}
tasks.json
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Run on MicroPython",
            "type": "shell",
            "command": "./.venv/bin/mpremote",
            "args": ["run", "${file}"],
            "problemMatcher": [],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

実行

  • ローカル(PC側)でスクリプトを書く。
  • コマンドパレットで Tasks: Run Task を実行。またはメニューから Terminal - Run Task... を実行
  • Run on MicroPythonを選ぶと実行される。

おことわり...

VS Code側を簡素にするため、mpremote時のポート指定を省略しています。

see also

自分向け追記

  • task.jsonlaunch.json.vscode フォルダーに配置
  • mpremote の位置は適宜修正。例えば "command": "./python-3.10.9-embed-amd64/Scripts/mpremote.exe",
  • エラーが出るとき、まずは接続確認。Windowsの場合は COMポート出現を確認してから実行。
  • mpremoteそのものがエラーとなる場合、python -m mpremote を試す。
  • pipでインストールしなおし、も有り
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?