You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在VS Code+PlatformIO中一键实现Arduino编译上传并自动重连串口监视器?

实现Arduino Nano一键编译上传+串口监视器自动重启

1. 自定义任务流程(tasks.json)

在VS Code中,按Ctrl+Shift+B打开任务面板,选择「创建tasks.json文件」,选择PlatformIO模板后,替换为以下内容:

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Upload with Serial Monitor Restart",
      "type": "shell",
      "dependsOrder": "sequence",
      "dependsOn": [
        "platformio device monitor stop",
        "platformio run --target upload",
        "platformio device monitor start"
      ],
      "problemMatcher": []
    },
    {
      "label": "platformio device monitor stop",
      "type": "shell",
      "command": "pio device monitor stop",
      "problemMatcher": []
    },
    {
      "label": "platformio run --target upload",
      "type": "shell",
      "command": "pio run --target upload",
      "problemMatcher": []
    },
    {
      "label": "platformio device monitor start",
      "type": "shell",
      "command": "pio device monitor start",
      "args": [
        "--environment", "nanoatmega328" // 替换为你platformio.ini里的环境名
      ],
      "problemMatcher": []
    }
  ]
}
  • 注意修改--environment后的参数,要和你platformio.ini中[env:xxx]的xxx一致,比如Arduino Nano(ATmega328P)通常是nanoatmega328。

2. 绑定快捷键

按Ctrl+K Ctrl+S打开快捷键设置,点击右上角「打开键盘快捷方式(JSON)」,添加以下配置:

{
  "key": "ctrl+shift+u", // 可自定义快捷键组合
  "command": "workbench.action.tasks.runTask",
  "args": "Upload with Serial Monitor Restart"
}

3. 功能说明

  • 执行快捷键后,会自动停止当前运行的串口监视器(无论是否是手动打开的面板式监视器),然后编译上传代码,上传完成后自动重启串口监视器(和手动打开的面板功能一致,支持发送指令)。
  • 若Linux/macOS下遇到串口权限问题,需将当前用户加入串口权限组(如dialout组);Windows下无需额外配置。

内容的提问来源于stack exchange,提问作者John

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 15:40:02