Visual Studio Code Arduino



Programming my ESPDuino-32 on Visual Studio Code + Platform.io I am trying to make the DFRobot mini DFPlayer MP3 sample work using Platform.io with the Arduino framework. I noticed that in my project, I have a main.cpp just like the Arduino sketch (.ino), with the setup and loop method stubs. Visual-studio-code arduino vscode-settings arduino-ide. Follow edited Aug 13 '20 at 9:57. 24.3k 7 7 gold badges 56 56 silver badges 80 80 bronze badges. Asked Aug 13 '20 at 1:53. 471 5 5 silver badges 16 16 bronze badges.

In this short note I will summarize how I can happily use Visual Studio Code on my local Windows desktop or laptop to do remote development on a Raspberry Pi or another Linux machine, and even push Arduino sketches from the Raspberry to an Arduino without touching the Arduino IDE. I have been a fan of the Raspberry Pi single board computer for a number of years now, and have used quite a number of them in my desktop single board computer cluster and my developing Raspberry/Arduino robot car. Still, I found developing code on it to be uncomfortable and sometimes cumbersome, as some IDEs don't support ARM processors whereas others like Thonny are rather basic. Remote development solves this by allowing you to code on your desktop / laptop and run it externally on a host (like the RPi). With the nascent Arduino CLI you can even largely replace the Arduino IDE for developing Arduino sketches on RPi and pushing them to a connected Arduino.

Remote Development with Visual Studio Code

For remote development to work in VS Code, you need to be able to SSH into your Raspberry, or other remote machine, using ssh pi@IP_ADDRESS in a command prompt (Windows) / terminal (Linux). You also need to install the VS Code Remote - SSH extension. Once done there's a new symbol in the left toolbar and an indicator on the bottom-left corner of the Status bar. This indicator tells you in which context VS Code is running (local or remote). Click on the indicator to bring up a list of Remote extension commands.

You can enter a new SSH connection or choose among previously used ones that are stored in a configuration file. More details can be found in Microsoft tutorial pages here and here. Upon connection to a new system VS Code will provision the VS Code Server to the remote environement. This will work with a number of Linux flavors, but certain other extensions may not work on ARMv7l (AArch32) and ARMv8l (AArch64) devices if they use x86 native code in the extension. The installation on my Raspberry looked as follows:

That's basically it, from here on everything works fine, even on my old Raspberry Pi 2 Model B. Regarding supported / unsupported extensions I will need more time to explore and will eventually add to this post later on.

Visual studio code arduino libraries

Arduino CLI

The Arduino IDE is great at achieving its intended purpose: It's a simple, single-file application development environment. It has just enough integrated tools to help achieve that purpose. But for larger application development it doesn't compare with a full-featured C/C++ IDE, lacking features such as code navigation, auto-completion, version control integration, or an integrated terminal.

Thanks to the nascent Arduino CLI there is now a potentially much more efficient mode of coding for the Arduino. Arduino CLI is the 'glue' that can pair the VS Code IDE with common Arduino compilation and upload tools, providing a command-line interface for such tasks as building Arduino sketches, uploading Arduino sketches, downloading libraries and downloading new board definition files - all without ever opening the Arduino IDE.

Studio

The latest version of the Arduino CLI on any supported platform can be obtained using the install.sh script:

Next, I created a configuration file as suggested on the Arduino CLI man page, in order to avoid a lot of typing when issuing a command:

The next thing to do upon a fresh install is to update the local cache of available platforms and libraries by running:

Arduino Extension Visual Studio Code

Arduino and Raspberry are connected via USB cable on my mobile robot, so let's see whether the Arduino can be recognized:

The Arduino Uno was recognized and from the output of the command we see the platform core called arduino:avr is the one that needs to be installed to make it work. The fact that we see an Unknown board listed doesn't really matter as long as we identify the platform core and use the correct FQBN string.

You can search for available cores like this:

Let's install the arduino:avr platform core:

The process is also documented in the following picture which, on the left hand side, shows the folder structure that has been built during the installation process:

From a hardware perspective we are good to go but we may need to import external libraries before we can compile an Arduino sketch. In my case I needed a library for the Adafruit Motor shield. You can search for libraries like this:

This will result in a list of related libaries out of which you can then install the right one:

We are now good to go. Arduino sketches can be developed in VS Code and then compiled and uploaded from the integrated terminal. To make the last two steps handier and avoid typing long commands I added a few lines to the .bashrc shell script, using

First I added the directory of the arduino-cli executable to the user $PATH variable so that I can execute the Arduino CLI without typing the full path:

What is airport utility for mac. This is necessary since I didn't store arduino-cli in one of the standard directories for files with executable permissions, such as /bin, /sbin, /usr/sbin, /usr/local/bin or /usr/local/sbin. As a second addition, I create aliases acompile and aupload as follows:

They allow me to compile Arduino sketches and upload them to the board using the following short commands:

Note that you need to give the directories as arguments, not, e.g., the .ino file for compilation. After saving the .bashrc file I loaded the changes into the current shell session using the source command:

To confirm that the directory was successfully added, one can print the value of $PATH by typing:

The final picture shows the result of our work. We can now develop Python code for the Raspberry and C++/.ino code for the Arduino side by side. Also we can use several parallel terminal windows to upload sketches and monitor code execution:

Links

Finally, some links that I found helpful:

  • Visual Studio Code remote development using SSH is well-documented here and here.
  • The Arduino CLI is relatively well documented on their GitHub page. Additional websites that may be helpful: One, two, three.
Studio

See also

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).

Visual Studio Code Arduino

visualmicro.comDocumentationForumRelease NotesAll ReleasesHardware Debug Troubleshooter

Features:-

Visual Studio Code Arduino Path

  • 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

  • Virtualbox for mac yosemite. 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

Visual Studio Code Arduino Include Path

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