Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fabianoriccardi/707fe6e3593a4312334be4d3411a6d70 to your computer and use it in GitHub Desktop.
Save fabianoriccardi/707fe6e3593a4312334be4d3411a6d70 to your computer and use it in GitHub Desktop.
Integrating makeEspArduino in Visual Studio Code (for Windows 10)

Integrating makeEspArduino in Visual Studio Code (for Windows 10)

The very first time I setup all this stuff on Windows I struggled for a while. Since I don't want to rely on my memory either I would repeat the same errors, I'm writing the procedure to get everything working.

I will assume that the Visual Studio Code, MSYS2, Arduino IDE, and the ESP8266 or ESP32 platforms are already installed. Also, I assume that you know how to use makeEspArduino to compile an Arduino sketch.

TL;TR

Before starting, let me explain why we are facing all this. The objective is to create a modern development environment for Arduino with the following requirements

  1. benefit of the Arduino ecosystem
  2. be free from the clumsy Arduino IDE
  3. availability of nowaday common editor features like linter, autocompletion, ...
  4. compile for esp8266 and esp32
  5. do not use PlatformIO

I state this last "weird" requirement because I would keep some of my old projects completely compatible with Arduino IDE, without changing folder structure, so that other people can continue to use it. However, if you are starting a project from scratch I strongly suggest considering it.

Moreover I have discarded Microsoft Arduino extension because it makes use of all the Java architecture at the base of Arduino IDE, hence it is equally slow.

Procedure

MSYS2

Open MSYS2 terminal and install the following packages required by makeEspArduino:

pacman -S mingw-w64-x86_64-python mingw-w64-x86_64-python-pip make perl git

Note that these packages are accessible only from MSYS2 environment, hence you have open mingwg64.exe instead of the default msys2.exe (placed in C:/msys64/). Please note that you are install a new version of git: if you have already installed the usual "git for Windows", probably you had autocrlf=true (checkout Windows-style, commit Unix-style). To enable this same setting, type:

git config --global core.autocrlf true

This avoids false-positive dirty working directory and other problems due to different line endings (alternatively, you may import the git version, without installing a new git). Then install pyserial, need to flash the MCU:

pip install pyserial

Moreover, pyserial, provides a simple terminal to communicate with esp board, called miniterm.py. Finally, to find your "Windows" documents, you have to move to your C drive, accessible through the command:

cd /c/

then you can navigate down to your Arduino projects.

makeEspArduino

Download (or clone) the esp makefile for Arduino. Install the version 5 or greater, which adds the support to Visual Studio Code. Remember that this makefile is designed only for ESP8266 and ESP32.

Visual Studio Code

The first step is configuring VSCode to open the MSYS2 shell instead of default Powershell. Install the (Shell Launcher)[https://marketplace.visualstudio.com/items?itemName=Tyriar.shell-launcher] extension. Open the folder of your Arduino project. Open the file .vscode/settings.json (create it if it doesn't exist). It contains a JSON object with the configuration for VS Code for the actual folder. Start to type the following key:

"shellLauncher.shells.windows"

Autocompletion should work, in case accept the suggestion. You should end up with a configuration like this:

{
  "shellLauncher.shells.windows": [
    {
      "shell": "C:\\Windows\\System32\\cmd.exe",
      "label": "cmd"
    },
    {
      "shell": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
      "label": "PowerShell"
    },
    {
      "shell": "C:\\Program Files\\Git\\bin\\bash.exe",
      "label": "Git bash"
    },
    {
      "shell": "C:\\Windows\\System32\\bash.exe",
      "label": "WSL Bash"
    }
  ]
}

Along the other shell's configurations, insert the configuration for MSYS2:

{
  "shell": "C:\\msys64\\usr\\bin\\bash.exe",
  "label": "MSYS2",
  "args": ["--login", "-i"],
  "env": {
    "MSYSTEM": "MINGW64",
    "CHERE_INVOKING": "1",
    //"MSYS2_PATH_TYPE": "inherit"
  }
}

You can uncomment MSYS2_PATH_TYPE if you would import the path from PowerShell. MSYSTEM must be set to MINGW64 to access the Python version previously installed.

Do CTRL + SHIFT + P to open the Command Palette, and type:

Shell Launcher: Launch

then, among the available options, select MSYS2. You should see the terminal already pointing to your Arduino folder. Now you can personalized VS code environment with the makefile. Type:

make vscode

This compiles your code, and in case of success, it generates all the defines and paths for IntelliSense. They can be checked in the file .vscode/c_cpp_properties.json and in .vscode/task.json.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment