文章目录
官方文档(参考手册)
https://www.arduino.cc/reference/en/
使用方法
先下载好arduino IDE
https://www.arduino.cn/thread-5838-1-1.html
需要说明的是,Arduino IDE和Vscode 不要同时运行
入股同时运行,会导致vscode无法正确写入到upload到Arduino上
这样做,出现的错误如下
[Starting] Uploading sketch 'arduinoCodes\blink.ino'
[Warning] Output path is not specified. Unable to reuse previously compiled files. Build will be slower. See README.
正在加载配置...
正在初始化包...
正在准备开发板...
正在验证...
上传...
上传项目出错
avrdude: ser_open(): can't open device "\\.\COM4": �ܾ����ʡ�
TRACE StatusLogger XmlConfiguration stopping remaining Appenders.
IntelliSense configuration already up to date. To manually rebuild your IntelliSense configuration run "Ctrl+Alt+I"
[Error] Uploading sketch 'arduinoCodes\blink.ino': Exit with code=1
如果关掉Arduino IDE,只用vscode来验证编译/上传,则是正常的
[Starting] Uploading sketch 'arduinoCodes\blink.ino'
[Warning] Output path is not specified. Unable to reuse previously compiled files. Build will be slower. See README.
正在加载配置...
正在初始化包...
正在准备开发板...
正在验证...
上传...
IntelliSense configuration already up to date. To manually rebuild your IntelliSense configuration run "Ctrl+Alt+I"
[Done] Uploading sketch 'arduinoCodes\blink.ino'
运行前选择开发板及其型号,以及需要运行的arduino代码源文件(注意,同一个目录下智能存放一个ino文件,否则会出现main函数的重复定义问题!!!)
要么就把其他ino文件全文注释掉
智能提示配置
下载arduino插件,并在设置中搜索arduino,配置setting.json文件
下载c/c++插件:
配置路径
Jsoncode
/* 修正错误提示的json代码: */
"C_Cpp.intelliSenseEngineFallback": "Disabled",
"C_Cpp.intelliSenseEngine": "Tag Parser",
后期处理(如果遇到乱码)
更多细节,参看
https://mp.weixin.qq.com/s/Se0-lMHXVj9oGXkakhQm9A
打开如下文件修改:
大概是:
C:\Users\userName.vscode\extensions\vsciot-vscode.vscode-arduino-0.4.0\out\src\common
效果:
配置查看源代码的方法
/* 将Arduino的库代码添加到c/c++ 插件中,方面查看源代码 */
"C_Cpp.default.includePath": [
"${default }",//默认保留
"C:\\Program Files (x86)\\Arduino"//arduino的安装目录
],
如下: