Select Page

Setting up Visual Studio Code for Arduino Programming

by Nov 24, 2019How To, Microcontroller Programming, Software0 comments

Today I decided to stop using the Arduino IDE because it sucks!

Having worked with Netbeans, MPLAB X and Visual Studio in the past, the Arduino IDE (version 1.8.1) really does not help with development so I am trying the Arduino add-in for Visual Studio Code from Microsoft. The configuring of the environment has proven to be a “not out the box” setup and as such I have documented my steps to get it working (mostly) with Intellisense. 

Installing the Software Components

You will need two main pieces of software and some add-ons to get started.

First, install the Arduino IDE 1.8.1 or higher but make sure its the Windows installer version, not the app from the Microsoft store as that won’t work. Also, take note of the installation location as you will need that for when configuring the new IDE. 

Next, download and instal the Visual Studio Code (VSC) application. During the installation, you will be prompted to choose the languages (extensio0ns) you wish to work with. Select C/C++ and Arduino, as well as any others you are interested in using.

Visual Studio Code Arduino extension

 

Configuring the Settings

VSC relies on a component of the Arduino IDE to physically upload the code to the board, which is why you needed to note the install location earlier. There are a couple of places this can be added but as several other settings need to be changed, we will do them all in the same file.

From the Explorer window press F1 to bring up the search

Then locate within the settings “Edit in settings.json”.
There may be an easier way of locating this – please comment below if you know of one…

Select “Edit in settings.json”

We need to add several items into the JSON file, and I don’t believe the order is important so long as each is separated by a comma and all within the curly braces.

 First is the path to the Arduino exe to allow the sketches to be uploaded to the board.

“arduino.path”“C:\\Program Files (x86)\\Arduino”,

 Then the list of additional board url’s, which is the same as found in the Arduino IDE File>Preferences> Additional Boards Manager URL’s. For mine, I have Adafruit and ESP8266

 “arduino.additionalUrls”https://adafruit.github.io/arduino-board-index/package_adafruit_index.json,http://arduino.esp8266.com/stable/package_esp8266com_index.json,

 And lastly, a modification to make Intellisense work. Without this you will find when you compile a sketch, you will see lots of errors for common commands such as pinMode not being recognised.

    “C_Cpp.intelliSenseEngineFallback”“Disabled”,
    “C_Cpp.intelliSenseEngine”“Tag Parser”

Changes required in settings.json to program the Arduino

 

To Speed up Compiling

In every new sketch, you are going to need to add this instruction to provide a location to save data about the last compile so as to not need to do a full clean compile every time you change just 1 line.

  “output”: “../ArduinoOutput”,
This can be found by expanding .vscode in the tree and selecting arduino.json

Adding the compile output path to avoid always doing clean builds

And lastly, select the board type, programmer, serial port from the blue toolbar at the bottom of the window to see the additional parameters in ardunio.json.  

Miscellaneous C/C++ Configurations

I am going to say upfront – I have no idea what this section is for other than I needed it for Intellisense. Read about it here if you need more information – https://github.com/microsoft/vscode-arduino/issues/438.

Basically I opened  c_cpp_properties.json from, vscode in the tree and replace the existing with the following code.

 

{

    “configurations”: [

        {

            “name”“Arduino”,

            “includePath”: [

                “${workspaceRoot}”

            ],

            “browse”: {

                “path”: [

                    “C:/Program Files (x86)/Arduino/hardware”,

                    “C:/Program Files (x86)/Arduino/libraries”,

                    “C:/Users/****/Documents/Arduino/libraries/”,

                    “C:/Users/****/Documents/Arduino/hardware/”,

                    “${workspaceRoot}”

                ],

                “limitSymbolsToIncludedHeaders”true,

                “databaseFilename”“”

            },

            “intelliSenseMode”“msvc-x64”

        }

    ],

    “version”4

}

 

Final Thoughts

There are still some areas that need tweaking in Visual Studio Code for Arduino for me to be entirely happy with it. One of which is an inconsistent result when trying to upload to the board, which most of the time gives the error “

unable to rename ‘core\core.a’; reason: File exists”. To work around this, I have set the Arduino IDE to use external editor but am still doing my board upload via the Arduino IDE until I can find a fix.

0 Comments

Submit a Comment

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