I’ve been playing around with an Arduino Uno recently, something new to me since I’ve always only used Raspberry Pi hardware. Many Arduino devices, or at least the Uno like I have are inexpensive and a lot of fun to play around with. However, the development experience out of the box isn’t exactly what I was familiar with or happy about. To develop and push code to an Arduino you need to use the Arduino Desktop IDE. If you’re like me, you’re a one IDE type of developer, so having to work in a different environment is a little less than ideal.
It doesn’t have to be that way when developing with Arduino though.
In this tutorial I’m going to walk you through configuring Visual Studio Code for Arduino development. You’ll be able to write code, deploy to hardware, and monitor the output.
While we plan to use Visual Studio Code in the long run, having the Arduino Desktop IDE installed is still a requirement. It ships with the necessary drivers for your computer to be able to communicate with the hardware. Download and install the appropriate version of the Arduino Desktop IDE for your operating system.
After installing the Arduino Desktop IDE, open Visual Studio Code and search for extensions.
You’ll want to install the official Arduino extension released by Microsoft.
With the extension installed, some configurations need to happen before code can be pushed to the Arduino. At this point in time, the Arduino should be attached to your computer because we’re going to be selecting the active serial port.
From the Command Palette, type in Arduino and choose Change Board Type. There are many Arduino devices being sold so select the one that you’re planning to use.
With the board type appropriately chosen, we can move onto the other configurations. However, before we do, let’s look at some sample code that we’re going to try to run:
It is just going to print text on a delay, but notice the baud rate is set to 9600. We need to configure this in Visual Studio Code so the output can be monitored.
From the Command Palette, type Arduino and choose Change Baud Rate.
You’ll want the baud rate in Visual Studio Code to match the baud rate in your code. It doesn’t need to be 9600, it just needs to match.
Chances are your computer will have numerous serial ports that are accessible. You’ll want to inform Visual Studio Code which serial port represents the connected Arduino device.
From the Command Palette, type Arduino and choose Change Serial Port. You might see a lot in the list, but it should be obvious which is your Arduino.
Get familiar with the Arduino commands in the Command Palette because at this point you’ll be using them to upload your code and monitor the serial port at the given baud rate.
You just saw how to configure Visual Studio Code (VSC) for Arduino development. Yes, you still need to have the Arduino Desktop IDE installed, but you should have a more pleasant experience using an IDE that you’re already familiar with, not to mention an IDE with significantly more features.
A video version of this tutorial can be seen below.