VSCode has an Arduino plugin available in preview. Use it. Put your Arduino desktop application in cold-storage. Comparing the two is like comparing a beaver with a 2 ton backhoe.
Assume you have a working project you want to convert to VSCode. Just
Once the Arduino extension is enabled for your project there are some tricks to make life better.
Strangely, arduino doesn’t support subfolders (it won’t automatically build and link them) unless they begin with a src subfolder root. See here: Recursive src Folder Discussion
Take a look at the picture at the start and make sure your source tree looks like:
ArduinoRootFolder
--- src
------- FolderA
------- FolderB
-------------SubfolderA
Depending on how the plugin works today, you may not get an output option defined in the arduino.json settings file. Add this line just above the closing brace:
,"output": "build"
Here I’ve defined the output folder as build. It will create a build folder in the project root where the caching of all the Arduino stuff takes place. That has two advantages:
Warning: from what I can tell putting the build folder inside your project tree sometimes causes issues. This is documented in the Arduino source. A better solution is to build in a folder outside of the project.
In typical new-age dumb software fashion there are lots of useful buttons on the bottom of the display that aren’t obvious but that you should totally learn to use.
Mouse over them and you’ll see all sorts of easy ways to change stuff.
The meat of the matter. There are four project settings files related to visual studio code and to Arduino. They can be confusing and you can often change them in more than one place. I’m going to skip tasks.json but discuss the rest.
This will create a .vscode folder if there isn’t one. It will also add the current Arduino settings to a file named arduino.json placed into the .vscode folder.
The following discussion refers to files found in the .vscode folder in your project. Add them there if they don’t exist.
This contains Arduino-specific settings. Most are set when you make changes with buttons and the Command Palette. Only the “output” folder did I notice as needing manual maintenance.
Add to your arduino.json (see above):
”output”: “build”
This file determines what gets linked and how intellisense finds files. Builds will still work but your mouseover helps and go-to-definitions and etc will be wrong if this is wrong.
{ "configurations": [ { "name": "Win32", "includePath": [ "${workspaceRoot}", "C:/Sr/Sketch/hardware/espressif/esp32/cores/esp32", "C:/Sr/Sketch/hardware/espressif/esp32/libraries", "C:/msys32/home/Mark/esp/esp-idf/components/esp32/include", "C:/Sr/Sketch/libraries", "C:/Users/Mark/AppData/Local/Arduino15/packages" ], "browse": { "limitSymbolsToIncludedHeaders": false, "path": [ "${workspaceRoot}", "C:/Sr/Sketch/hardware/espressif/esp32/cores/esp32", "C:/Sr/Sketch/hardware/espressif/esp32/libraries", "C:/msys32/home/Mark/esp/esp-idf/components/esp32/include", "C:/Sr/Sketch/libraries", "C:/Users/Mark/AppData/Local/Arduino15/packages" ] }, "intelliSenseMode": "msvc-x64" } ], "version": 3 }
My c_cpp_properties.json starts with workspaceRoot and the next three lines point at the standard ESP32 libraries (since this projects uses an ESP32) and then generically points at the default sketch library set and the local arduino packages. C:/Sr/Sketch is my Arduino Sketch folder.
Note the Local Appdata folder. This is the standard Windows location (with my name Mark). In many systems this folder is hidden or marked ‘system’ and in either case you won’t see it in a browse tree. You can type cd %appdata% to go the remote appdata folder.
This is the normal VSCode settings file. You can change it in workspace settings (File / Preferences / Settings and then the Workspace Settings tab) or you can use an editor.
User Settings for Arduino
“arduino.enableUSBDetection”: false
Turn off enableUSBDetection or it will (at least in my case) constantly nag you to change your board to what it thinks it reads from USB. If you mistakenly click Ok it will delete your current settings and use that incorrect driver to boot (sigh). So, turn it off.
Workspace Settings for Arduino
I set the external boards URL for the ESP32 supported boards:
"arduino.additionalUrls":"C:/Sr/Sketch/hardware/espressif/esp32/package/package_esp32_index.template.json",
It’s not obvious how to get rid of a library (or two) and sometimes arduino seems to choke. The easiest thing to do is to delete most of the contents of the arduino appdata folder (look in %appdata%\..\local for an Arduino15 folder). One of these files is the settings. Keep that.
After you delete the rest of the files all the installed board libraries will disappear and you get to start over (usually a good thing).