Our website is made possible by displaying online advertisements to our visitors. Please consider supporting us by disabling your ad blocker.

Configuring Visual Studio Code for Arduino Development

TwitterFacebookRedditLinkedInHacker News

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.

Visual Studio Code Arduino Extension

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.

VSC Change Arduino Board Type

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:

void setup()
{
    Serial.begin(9600);
}

void loop()
{
    Serial.println("Hello World");
    delay(1000);
}

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.

VSC Change Arduino 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.

Conclusion

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.

Nic Raboy

Nic Raboy

Nic Raboy is an advocate of modern web and mobile development technologies. He has experience in Java, JavaScript, Golang and a variety of frameworks such as Angular, NativeScript, and Apache Cordova. Nic writes about his development experiences related to making web and mobile development easier to understand.

Search

Follow Us

The Polyglot Developer

Subscribe

Subscribe to the newsletter for monthly tips and tricks on subjects such as mobile, web, and game development.

The Polyglot Developer

Support This Site