Visual Studio Code 使用 Arduino
安裝
安裝需求
- Arduino 原生 IDE
- Visual Studio Code 的 Arduino擴充套件
首先進入Visual Studio Code的擴充套件
搜尋Arduino並安裝即可
安裝完畢後,需要告訴VS Code你的IDE的安裝路徑。
從主功能表選擇File→Preferences→Settings
命令,搜尋arduino
關鍵字
找到Arduino設定選項裡的Arduino:Path
,確認Arduino IDE的安裝路徑是正確的,否則請自行修改。
到這裡就安裝完成了
命令
更詳細的請參考官方的文檔
This extension provides several commands in the Command Palette (F1 or Ctrl + Shift + P) for working with *.ino
files:
- Arduino: Board Manager: Manage packages for boards. You can add 3rd party Arduino board by configuring
Additional Board Manager URLs
in the board manager. - Arduino: Change Baud Rate: Change the baud rate of the selected serial port.
- Arduino: Change Board Type: Change board type or platform.
- Arduino: Close Serial Monitor: Stop the serial monitor and release the serial port.
- Arduino: Examples: Show list of examples.
- Arduino: Initialize: Scaffold a VS Code project with an Arduino sketch.
- Arduino: Library Manager: Explore and manage libraries.
- Arduino: Open Serial Monitor: Open the serial monitor in the integrated output window.
- Arduino: Select Serial Port: Change the current serial port.
- Arduino: Send Text to Serial Port: Send a line of text via the current serial port.
- Arduino: Upload: Build sketch and upload to Arduino board.
- Arduino: Upload Using Programmer: Upload using an external programmer.
- Arduino: Verify: Build sketch.
使用流程
選擇Arduino板子類型
按下F1並輸入Arduino: Change Board Type
這裡以UNO板作為範例
選擇Serial Port
接下來選擇Arduino: Select Serial Port
這裡我選擇COM3
最底下可以看到剛剛設定的設定值
不過到這裡還沒有完成
可以看到目前還有一些error未解決
解決C++設定檔
設定c_cpp_properties.json
這是C++的設定檔沒有設定好
#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit (C:\Users\king0\Documents\arduino file\Blink\Blink.ino).
cannot open source file "stdlib.h" (dependency of "C:\Users\king0\Documents\arduino file\Blink\Blink.ino")
在您開啟專案的目錄底下,會有一個c_cpp_properties.json
設定檔存在
進入該設定檔並貼上,以下設定檔
注意:這個設定請針對,您安裝的環境進行修改
{
"configurations": [
{
"name": "Win32",
"defines": [
"ARDUINO=10800"
],
"includePath": [
"${workspaceRoot}",
"C:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\**",
"C:\\Program Files (x86)\\Arduino\\tools\\**",
"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\**",
"C:\\Program Files (x86)\\Arduino\\libraries\\**",
"C:\\Users\\king0\\Documents\\Arduino\\hardware\\tools\\**",
"C:\\Users\\king0\\Documents\\Arduino\\libraries\\**"
],
"forcedInclude": [
"C:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino\\Arduino.h"
],
"intelliSenseMode": "clang-x64",
"cStandard": "c11",
"cppStandard": "c++17"
}
],
"version": 4
}
設定C/C++擴充套件
完美的解決方案
進入C/C++擴充套件
的設定檔裡面
Include path
欄位加上
C:\Program Files (x86)\Arduino\tools\**
C:\Program Files (x86)\Arduino\hardware\arduino\avr\**
C:\Program Files (x86)\Arduino\hardware\tools\**
C:\Program Files (x86)\Arduino\libraries\**
驗證及上傳
在右上角可以看到驗證跟上傳的按鈕