IoT – Getting Started with ESP IDF VS Code IDE

In this episode we will learn how to code, build, flash, monitor and debug the Espressif chips like ESP32 using ESP-IDF (IoT Development Framework) and Visual studio code.

In this article we will use MacBook pro with MacOS BigSur v11.2.3 as our development machine, let’s start.

Prerequisites for MacOS

Before getting started with the Visual Studio Code setup for ESP IDF environment we will need to install following tools on our machine.

Python 3.5

Please note that MacOS comes with Python 2.7 installed out of the box. We will use HomeBrew ti install Python 3 on our machine, run following command from a Terminal if you do not have installed it already.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Run following command to install Python 3 using Homebrew.

brew install python

Homebrew will also install pip pointing to newly installed hombrew version of python. Run following commands to verify installation of latest version of Python.

python --version

This will print python version on screen.

Python 3.9.0

Click here to further learn about python virtual environment management.

Git

Run following command to install git on MacOS using homebrew.

brew install git

CMake

CMake is simply a crossplatform make tool, run following command to install it on your mac.

brew install cmake

Ninja Build

Ninja build tool is used with gyp or CMake and it makes the build process a lot faster.

brew install ninja

Summary of the ESP IDF Prerequisites

Here is the summary of all dependencies for all major platforms.

Setup Visual Studio Code for ESP IDF development

Download and install Microsoft Visual Studio Code if you do not have installed.

Open visual studio code and search for “ESP-IDF” from extensions side bar panel.

Search ESP-IDF extension

Choose the “Espressif IDF” extension from Espressif Systems and click on “Install” button.

Install ESP IDF Visual Studio Code extension

Configure ESP IDF Extension

Open visual studio code command palette by pressing F1 key or “Cmd + Shift + P” on MacOS or “Control + Shift + P” on Windows OS. Type “ESP-IDF: Configure ESP-IDF extension” in command palette and hit Enter.

Configure ESP-IDF extension

Above command will open thee extension setup page, from this page click on “EXPRESS” to start the setup process. There is also another called “ADVANCED” setup on the same page, choose this for manual setup of ESP IDF tools or if you already have ESP IDF framework and tools installed on your system, otherwise if you are doing this on a fresh system or for the first time then “EXPRESS” is the most appropriate option for you.

ESP IDF Extension setup

Next the ESP extension setup wizard will move you to the tool and path selection page, from this page choose following options.

OptionValue to chooseDescription
Download ServerGitHubChoose the source of ESP-IDF build tools, GitHub or Espressif.
ESP-IDF Versionv4.2 (release version)Choose the latest available version, this was the latest version at time of writing this article.
ESP-IDF Container Directory$HOME/espThe destination of ESP IDF tools.
Python VersionPython 3.5+Python version
ESP IDF Extension setup
ESP IDF Extension setup

Click on the install button to start the install the required tools for ESP IDF build.

ESP IDF Extension setup

You are ready to build applications once the installation process is complete.

Useful ESP IDF Visual Studio Code Commands

On Microsoft Windows OS replace “⌘ (Cmd)” with “Ctrl” key.

ActionDescriptionKeyboard Shortcut
Create new ESP IDF projectCreates blank ESP IDF project⌘ E N
Create new ESP project based on one from available list of templates.⌘ E C
Select port to useChoose the COM port where you have connected the ESP32 module.⌘ E P
Build your projectCompile / build current project⌘ E B
Flash your projectFlash current project onto the ESP32 chip connected via selected COM port. (build before flashing on chip)⌘ E F
Monitor your deviceMonitor the running program on ESP32 chip connected with the selected COM port.⌘ E M
Build, Flash and start a monitor on your deviceThis command will build, flash and start a monitor in sequence.⌘ E D
Full clean projectFull clean will simply delete previously compiled artifacts (not the source code).⌘ E X
SDK Configuration editorThis command will open the SDK configuration editor.⌘ E G
Size analysis of the binariesThis will open up a detailed analysis of generated binary file for current project. Look at the following image for a sample analysis page.⌘ E S
Search in documentation…Select text from code and press “⌘ E Q” to search it in ESP IDF reference documentation.⌘ E Q
Open ESP-IDF TerminalThis will open a ESP-IDF terminal with all paths set.⌘ E T
Useful ESP IDF VS Code extension commands
ESP IDF Size Analysis

USB to UART Bridge VCP Drivers

USB to UART Bridge is used to connect devices with UART interface via USB port of system, you may need to install following drivers to connect ESP32 DevKit (with USB interface) with your PC or MacBook.

Download USB to UART Bridge VCP Drivers.

ESP32 DevKit Connectivity Issue

If you face trouble while flashing your project to an ESP32 module, press and hold the boot button on ESP32 DevKit module and then issue the flash command from visual studio code, this will start the flash process, please note that you can release the boot button once the flash process has started.

ESP32 Flash Problem

In next article we will create a hello world world project using ESP-IDF extension for Visual studio code and will flash it on ESP32 chip.

Shoket Mahmood Ahmed

Leave a Reply

Back to top