Replacing Arduino editor with vscode

Time:2021-2-25

Arduino has become the hottest development board at present, but its editor is not intelligent enough, even the basic syntax highlighting, code completion and syntax checking are not available. It’s really hard to knock line by line. Baidu found that there is a tutorial to replace vscode with Arduino development environment on the Internethttp://www.21ic.com/evm/trick…Because the vscode version is inconsistent, the configuration details may be different, so please record here. The following operations are based on version 1.30.1, and some of them may be different from the previous versions.

Let’s take a look at the hardware and software of vscode
Visual studio code (abbreviated as vs Code / VSC) is a free and open source modern lightweight code editor developed by Microsoft. It supports syntax highlighting, intelligent code completion, user-defined shortcut keys, bracket matching and color discrimination, code fragments, code contrast diff, GIT commands of almost all mainstream development languages It supports plug-in extension and optimizes web development and cloud application development. The software supports win, MAC and Linux across platforms and runs smoothly. It can be said that it is the work of Microsoft’s conscience

Why use vscode? First of all, as an editor, I feel that sublime can be compared with it. Secondly, Arduino plug-in on vscode integrates all the functions of ardunino. No matter coding / burning or importing library, it can be completed on the vscode interface.

Here are the configuration steps:
The first is to download the original version of ardiono. The download address of the official website is:https://www.arduino.cc/en/Mai…, you can choose the installation version or free installation version of the zip package, I choose the installation version.

Replacing Arduino editor with vscode

Isn’t it said that vscode integrates almost all the functions of Arduino ide? Why install the original Arduino?
Because vscode just calls arduinoid ide through the path, which is equivalent to setting a better UI outside arduinoid ide.

After installing Arduino IDE, open vscode, add Arduino plug-in, and select Microsoft

Replacing Arduino editor with vscode

After installation:

Replacing Arduino editor with vscode

The difference between vscode and vs is that the configuration files of vscode are all configured with JSON. Vscode reads these configurations at startup, and then it can start to work.
The shortcut key for vscode to set system parameters is Ctrl +. After opening, search for Arduino related settings, and then edit them.

Replacing Arduino editor with vscode

The main parameter to modify here is the location of Arduino.

Replacing Arduino editor with vscode

Replacing Arduino editor with vscode

After setting in this way, vscode should be able to use Arduino for development.

Next, let’s take blink program as an example
First, open your common directory with vscode, such as Arduino, then create a new folder test, and then create a new directory test.ino Documents.

Replacing Arduino editor with vscode

Replacing Arduino editor with vscode

The file will be opened after it is created test.ino After that, the status bar at the bottom of the vscode window will become as shown in the figure above. It is convenient to choose board model and serial port.
Here I choose Arduino micro and serial port 8,

Replacing Arduino editor with vscode

Replacing Arduino editor with vscode

Copy a blink code to a file, save it, and then press Ctrl + Alt + u to download it.

void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}

After the download is successful, the following information will be output:

[Starting] Upload sketch - test\test.ino
[Warning] Output path is not specified. Unable to reuse previously compiled files. Upload could be slow. See README.
Loading configuration
Initializing package
Preparing development board
Verifying
The project uses 4132 bytes, occupying (14%) program storage space. The maximum is 28672 bytes.
Global variables use 149 bytes (5%) of dynamic memory, leaving 2411 bytes of local variables. The maximum is 2560 bytes.
Upload

Replacing Arduino editor with vscode
Vscode doesn’t have a convenient download and compile icon like Arduino ide. It can only be implemented with commands or shortcut keys. Open the command panel with the shortcut keys Ctrl + Shift + P or F1, search Arduino’s, and if you want to compile and upload to the development board, you can either click Ardiono:Upload To achieve, or use Ctrl + alt_ You can use vscode to code, and then use Arduino ide to fine tune.

Replacing Arduino editor with vscode

Replacing Arduino editor with vscode

Vscode itself has code prompt and code completion function, but it is limited to the current file. In order to complete the whole project, we need to use the plug-in gtags.
To be continued….