Arduino Development In Visual Studio Code

Arduino and its associated IDE (Integrated Development Environment) have been a stable of many of my projects. Even with its utility, it lacks many of the features I have grown accustom to in my other development endeavors. I usually work in Visual Studio Code (VSCode) and got to thinking, “Why can’t I us it to edit my Arduino Sketches.” Well, it didn’t take long before I found all the answers I needed. I will recount what I found in the following.

Software Required

Even though we will be using VSCode, we still need the Arduino IDE install. To make this work, we will need to be a bit specific. You MUST use the Arduino IDE that you install from their site, NOT the one from the windows store. You also should be using at least version 1.8.8+ as there were problems with the integration in 1.8.7.

Go download and install the Arduino IDE from here: https://www.arduino.cc/en/Main/Software

After it is installed I would recommend opening it at least once to allow it to initialize its settings and variables.

The next piece of software you will need is VSCode. There are fewer specifics to this, just go download and install the most recent version. It can be had here: https://code.visualstudio.com/Download

Configure VSCode

Open VSCode and allow it to situate. Once its done loading perform the following:

  1. Select “Extensions”
  2. Search for “Arduino”
  3. Select “Arduino” by “Microsoft”
  4. Press “Install” (I have already installed it, so mine says “Uninstall” ;))

You will get a few new options. Most notably, you will find, in the workspace explorer, a folder for all of the Arduino example. If you go down there and open the basic “Blink” example we will continue our discussion.

In your version, you may notice that many of the keywords are marked with an underscore of red. VSCode doesn’t know what is valid in the Arduino world, only raw C++. To fix that, go to File-Preferences-Settings. Then:

  1. in the search box, type “Arduino”
  2. Select: “Arduino Configuration”
  3. Select: “Edit in settings.json”

Add the following code to the settings file:

    "arduino.path": "C:\\Program Files (x86)\\Arduino", 
    "arduino.additionalUrls": "", 
    "arduino.logLevel": "info", 
    "arduino.enableUSBDetection": true, 
    "C_Cpp.intelliSenseEngine": "Tag Parser"

Save it, close it and you will now find that most if not all of your errors are gone.

Connecting and Uploading

You can do all of the configuration in VSCode, just like in the Arduino IDE. To make changes in VSCode, you can press F1 and type Arduino. You will see all of the options available. They are very similar to the Arduino IDE Menus:

Selecting any of these options brings you to settings for that option. Finally, you can also directly upload your code using the upload button on the top right of the window.

UPDATE 1 – Handling Include.h files

As I got to programming I found that VSCode was having trouble finding some of my libraries. To remedy this you will need to add a path to the c_cpp_properties.json file.

  1. Expand the .vscode folder and open the c_cpp_properties.json
  2. Add the path to the libraries folder. Note, mine is in documents, not the application folder.

That’s it for this post. If I learn more as I gain experience using VSCode for Arduino, I’ll update.

Add a Comment

Your email address will not be published. Required fields are marked *