转载来源:https://cjh0613.com/20200630VScode-Arduino.html
为什么要用VScode
代替Arduino IDE
?因为它是最好的进行arduino开发的利器,支持许多Arduino IDE
所没有的功能,其Arduino
插件由微软开发,十分稳定。支持代码高亮,代码补全,转到定义,文件跳转等,有利于提高敲代码速度以及查看源码或者库文件。而且VScode
可以跨平台使用,Windows
,MAC
,Linux
都支持。而且没有vs
那样臃肿,其他比较好的c语言IDE如Clion(arduino插件由个人开发,相比vs系列,用户较少)的支持都不太好。
安装插件
步骤 2: 中左键单击菜单中拓展
步骤 3: 在搜索框输入arduino并安装(还需要安装 C/C++ 插件)
修改VScode设置
步骤 1: 左键单击左下角齿轮设置按钮
步骤 2: 点击"设置 "
步骤 3: 在"设置 "中左键单击右上角“打开json设置”按钮
步骤 4: 添加下方内容至括号中。(如果是json最后一项配置项,去掉最后一项后方的逗号)
"arduino.path": "C:/Program Files (x86)/Arduino",
"C_Cpp.intelliSenseEngine": "Tag Parser",
"editor.insertSpaces": true,
"files.autoGuessEncoding": true,
"arduino.logLevel": "info",
"explorer.confirmDelete": false,
"editor.detectIndentation": false,
我的完整配置:
{
"git.path": "D:/mypro/PortableGit/bin/git.exe",
"workbench.colorTheme": "Default Light+",
"editor.tabCompletion": "on",
"arduino.path": "C:/Program Files (x86)/Arduino",
"C_Cpp.intelliSenseEngine": "Tag Parser",
"editor.insertSpaces": true,
"files.autoGuessEncoding": true,
"arduino.logLevel": "info",
"explorer.confirmDelete": false,
"editor.detectIndentation": false,
}
如此便可使用代码补全了
修改项目配置文件
目的是让VScode识别Arduino项目。
参照下方添加/修改项目根目录.vscode/C_cpp_properties.json
文件,请注意使用对应安装目录、我的文档arduino库目录:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"C:/Program Files (x86)/Arduino/libraries",
"C:/Program Files (x86)/Arduino/hardware/arduino/avr/**",
"C:/Program Files (x86)/Arduino/hardware/tools/avr/avr/include",
"C:/Program Files (x86)/Arduino/hardware/tools/avr/lib/gcc/avr/7.3.0/include",
"C:/Program Files (x86)/Arduino/hardware/tools/avr/lib/gcc/avr/7.3.0/include-fixed",
"C:/Program Files (x86)/Arduino/tools/**"
],
"forcedInclude": [
"C:/Program Files (x86)/Arduino/hardware/arduino/avr/cores/arduino/Arduino.h"
],
"browse": {
"limitSymbolsToIncludedHeaders": true,
"path": [
"C:/Program Files (x86)/Arduino/libraries"
]
},
"intelliSenseMode": "msvc-x64",
"defines": [
"USBCON"
]
}
],
"version": 4
}
参考资料
- https://blog.csdn.net/acktomas/article/details/102815385
- https://www.csdn.net/gather_2d/MtTaggysNzQzOS1ibG9n.html
- https://mithatkonar.com/wiki/doku.php/arduino/configuring_visual_studio_code_for_arduino_development
- https://mithatkonar.com/wiki/doku.php/arduino/code_completion
- https://sunmengxin.cn/vscode-replace-arduino/
- https://blog.csdn.net/yanggengzhen/article/details/103900182
- https://www.ancii.com/agzua0dgq/
附录
附上一些在实际使用过程汇总遇到问题的解决办法。
1、输出窗口中文乱码
解决方法:修改%HOMEPATH%.vscodeextensionsvsciot-vscode.vscode-arduino-0.3.2outsrccommonutil.js
注释下面的代码区块
/* if (os.platform() === "win32") {
try {
const chcp = childProcess.execSync("chcp.com");
codepage = chcp.toString().split(":").pop().trim();
}
catch (error) {
outputChannel_1.arduinoChannel.warning(`Defaulting to code page 850 because chcp.com failed.
rEnsure your path includes %SystemRoot%\system32r${error.message}`);
codepage = "850";
}
} */
如下所示:
然后重启VS Code即可。
2、输出窗口输出一大串DEBUG信息
解决方法:找到Arduino IDE文件夹下面的arduino_debug.l4j.ini,在最后新增一行-DDEBUG=false
参考链接:https://github.com/microsoft/vscode-arduino/issues/891
如下所示:
3、无法打开Arduino串口,查看串口输出
解决办法:暂未找到解决方法!
文章评论