Tag Archives: Visual Studio Code

Programming Arduino with Visual Studio Code

program arduino with vscode

Every hobbyist generally start programming on Arduino using its official IDE. For advanced programmers, it may be interesting to change the code editor to have access to a larger number of features. In this article, you will learn how to program your Arduino using of the Visual Studio Code software which is a nice alternative to the Arduino IDE.

Introducing Visual Studio Code

Visual Studio Code is an extensible and lightweight code editor developed by Microsoft. VSCode brings many features compared to the Arduino IDE:

  • Auto-completion.
  • Syntax highlighting.
  • Debug functionality.
  • Programming in several languages (C++, C#, Java, Python, PHP, etc.).
  • Project management.
  • Git repository management.

It is open source and available on Windows, Linux and MacOS platforms.

Installing Visual Studio Code

Go to the Visual Studio Code download page and download the latest version corresponding to your OS. Launch the installer and follow the usual steps.

Communicating with Arduino

To be able to communicate with Arduino, you must install the corresponding extension.

Click on the “Extensions” icon it the left of your screen or use the shortcut (Ctrl+Shift+X).

Then search for Arduino and select “Arduino for Visual Studio Code”.

install it then Restart VSCode.

Setting up VSCode for Arduino

Click on the Manage icon (gear icon on the bottom left) and select “Command Palette”. You can use the shortcut (Ctrl+Shift+P).

Search for Arduino, then you have access to several commands related to Arduino.

Select Arduino Board Config then select board type.

At the bottom right, click on Select Serial Port, then select the serial port corresponding to the Arduino (here, COM5).

At the bottom right, click on Select Programmer then select “AVRISP mkII”.

Code compilation and upload

In the command palette (Ctrl+Shift+P), search for “Arduino: Examples” then choose “Blink” or another example.

You can then upload the code by pressing “Upload” in the top right.

The console indicates if the code is loading and you can verify that the code is loaded on the Arduino board by looking at the status of the LED.

By modifying the code a bit we send text to the serial monitor.

int led = 13;

// the setup routine runs once when you press reset:
void setup() {
  Serial.begin(115200);
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  Serial.println("Led is High");
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  Serial.println("Led is Low");

  delay(1000);               // wait for a second
}

Upload the modified code to the Arduino board.

To open the serial monitor, press the Serial Monitor icon just to the right of the board type at the bottom right.

You can then select the desired Baudrate in the Arduino board configuration bar at the bottom right (115200).

Send commands to the serial monitor

Just like the Arduino IDE, it is possible to send commands via the Serial port.

In the Arduino command palette, search for “Send text to Serial Port”. An input bar appears.

It is possible to create a keyboard shortcut to open this command more easily. Press the gear icon to the right of the control.

Under the Keybinding tab, you can customize your shortcut.

Now you are ready to use use VSCode with your Arduino boards. Try this tutorial of the 16×02 LCD using VSCODE.