Visual Studio Code Arduino



Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter. Arduino & Visual Studio - Serial Communication: The reason for this project is to show you, how to manage Serial connections in Visual Studio 2015 with VisualBasic as the main programming language.A few days ago, I copyed a project from VisualBasic 2010 to Visual Studio inside a VisualBasic proje.

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.

Contents

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.

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…

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.

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”: “”

Arduino

},

“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 ‘corecore.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.

Visual Micro is an Arduino compatible Build, Upload and Debugging solution for Visual Studio 2017 & 2019.

License: Perpetual or Yearly Licenses are available from $12 per year (includes forum support and updates).

visualmicro.comDocumentationForumRelease NotesAll ReleasesHardware Debug Troubleshooter

Features:-

Visual Studio Code Arduino Tutorial

  • Fully Arduino Compatible Build and Upload System (supporting all Arduino Versions)

  • Code remains 100% Arduino Compatible

  • Configuration is Shared with the Arduino IDE saving setup time and confusion

  • Share code accross teams

  • Souce control

  • Includes maintained Project Templates and Code Snippets to increase your velocity

  • Save Board Selection, Board Options, and Port settings for each project, or configuration.

  • Automatic IDE Toolbar Visibility for seamless integration into your setup

  • Use Multiple Serial Monitors together at the same time

  • Advanced Library Management allowing libraries to be in any folder

  • Versioned Library In-Project Capture per-project or per-solution (ideal for TFS or Git VC)

  • Unique Software Debugging via USB and WiFi (perfect for the Uno/Mega, and ESP32

    • Step/Break/Trace functionality

  • Debug Options automatically saved per-board and project configuration

  • Pre-Configured and Fully Customizable GDB Hardware Debugging

  • Supports GDBStub Debugging with Fully Customizable configuration

  • Integrate Automated Testing for your Cross Platform Code on your PC

Installation Guide

  • Install Failed? If this download fails to install then right click the downloaded .vsix file and then 'Right click > Open with > Visual Studio Version Selector'. This often applies to all Microsoft extensions if Atmel Studio or older Visual Studio versions are installed side-by-side with Vs2017/2019.
  • IDE load time? Visual Micro will only load at Startup when its toolbars are visible. Otherwise Visual Micro will load only when needed. The 'VMicro' toolbar is an exception to the rule, it can always be visible and will not affect load times. Switching 'vMicro>Toolbar Auto Visibility' 'On' allows toolbars to automatically 'display/hide' when an Arduino project is open. Switching auto visbility 'Off' provides user control of toolbar visibility using the standard Visual Studio toolbar visibility features.
  • See all project sources? The small icon called 'Show all files' above the solution explorer enables switch between 'physical file and folder view' and 'Filtered view of files included in the current project(s)'. The 'show all files' view is useful to see which sources are included in the project. By default, for novice users, Visual Micro will ensure the correct sources are included. Advanced users that change sources using windows explorer or external editors need to review and manage this themselves.... Right clicking folders and files when 'show all files' is enabled provides options to 'Include' or 'Exclude' sources from the current project. Normally, for Arduino, we should expect to see all sources below the project, the 'src' folder and folders below the 'src' folder to be included. Another useful option can be 'vMicro>Show hiden files' which will includes core Arduino and library sources as shortcuts in the solution explorer. This can make it easest to navigate to or view the underlying cpp/c sources.

Arduino Visual Studio Code Setup

Quick Project Templates