• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here:Home » How to Program ESP32 Devices Using the ESP-IDF Framework (CLI)

By Abhishek Ghosh May 12, 2024 10:38 pm Updated on May 12, 2024

How to Program ESP32 Devices Using the ESP-IDF Framework (CLI)

Advertisement

The ESP32 microcontroller, developed by Espressif Systems, has gained widespread popularity for its versatility, low cost, and robust performance. To harness the full potential of ESP32 devices and develop feature-rich applications, developers often rely on the Espressif IoT Development Framework (ESP-IDF). In this article, we’ll explore the process of programming ESP32 devices using the ESP-IDF framework in the command-line interface (CLI), offering flexibility and efficiency in development workflows.

While using Arduino IDE is easy to use for smaller projects, using ESP-IDF Framework is the professional way for development since it unleashes the full power of ESP32.

  1. Basics of C++ For Beginners
  2. C/C++ Usage of Arduino and ESP Line

 

Understanding ESP-IDF and CLI Programming

 

The ESP-IDF framework provides a comprehensive set of libraries, tools, and components for developing applications for ESP32-based devices. While IDEs like PlatformIO and Arduino IDE offer graphical interfaces for ESP-IDF development, programming in the CLI environment offers greater control, customization, and integration with version control systems and automated build pipelines.

Advertisement

---

 

Prerequisites & Steps

 

This guide is for installing and working with the CLI tool. That is the first of the setup. You’ll get the online installer here:

Vim
1
https://dl.espressif.com/dl/esp-idf/

We recommend using the online installer since in that way you will get the latest updates. The total size is around 1.5GB but the CDNs are fast enough. In my case, among the prerequisite tools Python 3, Git, cross-compilers, and CMake were already installed on my Windows computer. The Ninja build tools were installed by the wizard. Here is the official documentation:

Vim
1
https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/windows-setup.html

Launch the installer, click on next, leave the settings on default or select which components you want to install. The ESP-IDF will now begin to download and install, this will take a few minutes.

Zero bug. After everything is ready, the wizard will launch the Windows Command Line Tool. Also, you’ll find shortcut icons on your desktop to launch the CMD tool and PowerShell. In the case of PowerShell, you may have to add the path of the PowerShell executable, which is in my case:

Vim
1
C:\Users\abhishekghosh\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Windows PowerShell

Whenever you launch PowerShell, it will return this output:

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
...
Setting PYTHONNOUSERSITE, was not set
Using Python in C:\Users\abhishekghosh\.espressif\python_env\idf5.2_py3.11_env\Scripts
Python 3.11.2
Using Git in C:\Users\abhishekghosh\.espressif\tools\idf-git\2.43.0\cmd
git version 2.43.0.windows.1
Setting IDF_PATH: C:\Espressif\frameworks\esp-idf-v5.2.1
Checking Python compatibility
Adding ESP-IDF tools to PATH...
 
Name                           Value
----                           -----
OPENOCD_SCRIPTS                C:\Users\abhishekghosh\.espressif\tools\openocd-esp32\v0.12.0-esp32-20230921\openocd-...
IDF_CCACHE_ENABLE              1
ESP_ROM_ELF_DIR                C:\Users\abhishekghosh\.espressif\tools\esp-rom-elfs\20230320\
IDF_PYTHON_ENV_PATH            C:\Users\abhishekghosh\.espressif\python_env\idf5.2_py3.11_env
ESP_IDF_VERSION                5.2
IDF_DEACTIVATE_FILE_PATH       C:\Users\ABHISH~1\AppData\Local\Temp\tmpxbh9s1q4idf_21164
 
Added to PATH
-------------
C:\Users\abhishekghosh\.espressif\tools\xtensa-esp-elf-gdb\12.1_20231023\xtensa-esp-elf-gdb\bin
C:\Users\abhishekghosh\.espressif\tools\riscv32-esp-elf-gdb\12.1_20231023\riscv32-esp-elf-gdb\bin
C:\Users\abhishekghosh\.espressif\tools\xtensa-esp-elf\esp-13.2.0_20230928\xtensa-esp-elf\bin
C:\Users\abhishekghosh\.espressif\tools\riscv32-esp-elf\esp-13.2.0_20230928\riscv32-esp-elf\bin
C:\Users\abhishekghosh\.espressif\tools\esp32ulp-elf\2.35_20220830\esp32ulp-elf\bin
C:\Users\abhishekghosh\.espressif\tools\cmake\3.24.0\bin
C:\Users\abhishekghosh\.espressif\tools\openocd-esp32\v0.12.0-esp32-20230921\openocd-esp32\bin
C:\Users\abhishekghosh\.espressif\tools\ninja\1.11.1\
C:\Users\abhishekghosh\.espressif\tools\idf-exe\1.0.3\
C:\Users\abhishekghosh\.espressif\tools\ccache\4.8\ccache-4.8-windows-x86_64
C:\Users\abhishekghosh\.espressif\tools\dfu-util\0.11\dfu-util-0.11-win64
C:\Espressif\frameworks\esp-idf-v5.2.1\tools
Checking if Python packages are up to date...
Constraint file: C:\Users\abhishekghosh\.espressif\espidf.constraints.v5.2.txt
Requirement files:
- C:\Espressif\frameworks\esp-idf-v5.2.1\tools\requirements\requirements.core.txt
Python being checked: C:\Users\abhishekghosh\.espressif\python_env\idf5.2_py3.11_env\Scripts\python.exe
Python requirements are satisfied.
 
Detected installed tools that are not currently used by the active ESP-IDF version.
To remove old versions of idf-driver use command 'python.exe C:\Espressif\frameworks\esp-idf-v5.2.1\tools\idf_tools.py uninstall'
For free up even more space, remove installation packages of those tools. Use option 'python.exe C:\Espressif\frameworks\esp-idf-v5.2.1\tools\idf_tools.py uninstall --remove-archives'.
 
 
Done! You can now compile ESP-IDF projects.
Go to the project directory and run:
    idf.py build

In the case of Windows CMD, you’ll get this output:

Vim
1
Using Python in C:\Users\abhishekghosh\.espressif\python_env\idf5.2_py3.11_env\Scripts\                                 Python 3.11.2                                                                                                           Using Git in C:\Users\abhishekghosh\.espressif\tools\idf-git\2.43.0\cmd\                                                git version 2.43.0.windows.1                                                                                            Checking Python compatibility                                                                                           Setting IDF_PATH: C:\Espressif\frameworks\esp-idf-v5.2.1                                                                                                                                                                                        Adding ESP-IDF tools to PATH...                                                                                             C:\Users\abhishekghosh\.espressif\tools\xtensa-esp-elf-gdb\12.1_20231023\xtensa-esp-elf-gdb\bin                         C:\Users\abhishekghosh\.espressif\tools\riscv32-esp-elf-gdb\12.1_20231023\riscv32-esp-elf-gdb\bin                       C:\Users\abhishekghosh\.espressif\tools\xtensa-esp-elf\esp-13.2.0_20230928\xtensa-esp-elf\bin                           C:\Users\abhishekghosh\.espressif\tools\riscv32-esp-elf\esp-13.2.0_20230928\riscv32-esp-elf\bin                         C:\Users\abhishekghosh\.espressif\tools\esp32ulp-elf\2.35_20220830\esp32ulp-elf\bin                                     C:\Users\abhishekghosh\.espressif\tools\cmake\3.24.0\bin                                                                C:\Users\abhishekghosh\.espressif\tools\openocd-esp32\v0.12.0-esp32-20230921\openocd-esp32\bin                          C:\Users\abhishekghosh\.espressif\tools\ninja\1.11.1\                                                                   C:\Users\abhishekghosh\.espressif\tools\idf-exe\1.0.3\                                                                  C:\Users\abhishekghosh\.espressif\tools\ccache\4.8\ccache-4.8-windows-x86_64                                            C:\Users\abhishekghosh\.espressif\tools\dfu-util\0.11\dfu-util-0.11-win64                                               C:\Espressif\frameworks\esp-idf-v5.2.1\tools                                                                                                                                                                                                Checking if Python packages are up to date...                                                                           Constraint file: C:\Users\abhishekghosh\.espressif\espidf.constraints.v5.2.txt                                          Requirement files:                                                                                                       - C:\Espressif\frameworks\esp-idf-v5.2.1\tools\requirements\requirements.core.txt                                      Python being checked: C:\Users\abhishekghosh\.espressif\python_env\idf5.2_py3.11_env\Scripts\python.exe                 Python requirements are satisfied.                                                                                                                                                                                                              Detected installed tools that are not currently used by active ESP-IDF version.                                         For removing old versions of idf-driver use command 'python.exe C:\Espressif\frameworks\esp-idf-v5.2.1\tools\idf_tools.py uninstall'                                                                                                            For free up even more space, remove installation packages of those tools. Use option 'python.exe C:\Espressif\frameworks\esp-idf-v5.2.1\tools\idf_tools.py uninstall --remove-archives'.                                                                                                                                                                                                                                                                                                        Done! You can now compile ESP-IDF projects.                                                                             Go to the project directory and run:                                                                                                                                                                                                              idf.py build                                                                                                                                                                                                                                                                                                                                                          C:\Espressif\frameworks\esp-idf-v5.2.1>                                                                              

The above return indicates that there is no error in setup.

 

How to Use the ESP-IDF Framework in CLI

 

Now connect your ESP32 board to the computer and check under which serial port the board is visible. Serial port names start with COM in Windows. In my example, it is COM8. If you are not sure how to check the serial port name, open the Device Manager from the Windows start menu and get the port number.

Go to the ESP-IDF’s home location, which is this in my case:

Vim
1
C:\Espressif\frameworks\esp-idf-v5.2.1

cd to examples/get-started directory. You’ll get hello_world example here. cd to that directory and do an ls:

Vim
1
2
3
4
5
6
7
8
9
Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----           12-5-24     10:33                build
da----           12-5-24      9:55                main
-a----           12-5-24      9:55            242 CMakeLists.txt
-a----           12-5-24      9:55           1661 pytest_hello_world.py
-a----           12-5-24      9:55           2474 README.md
-a----           12-5-24     10:23          57704 sdkconfig
-a----           12-5-24      9:55              0 sdkconfig.ci

The main directory contains hello_world_main.c, which is the program file. While you are inside the hello_world directory (not the main directory):

Vim
1
C:\Espressif\frameworks\esp-idf-v5.2.1\examples\get-started\hello_world

In order to compile, run this command:

Vim
1
idf.py build

It will check for errors and compile the thing. The required command to upload this to ESP32, need to run:

Vim
1
idf.py -p PORT flash

Which in my case is:

Vim
1
idf.py -p COM8 flash

You’ll get the indication that the upload is complete:

How to Program ESP32 Devices Using the ESP-IDF Framework CLI

Now open any serial monitor software on your Windows PC. You can use Arduino IDE’s serial monitor if you have no other serial monitor software installed on your PC. You’ll get the informative output from the program.

To create a new project, navigate to the directory where you want to create your ESP32 project. Use the idf.py command-line tool to create a new project. For example:

Vim
1
idf.py create-project my_esp32_project

You can customize project settings such as board configuration, Wi-Fi credentials, and other parameters using the idf.py menuconfig command. Also, you can configure components, drivers, and features required for your ESP32 application. It will create a file named my_esp32_project.c under the main sub-directory with this content:

Vim
1
2
3
4
5
6
#include <stdio.h>
 
void app_main(void)
{
 
}

Use a text editor to write your ESP32 application code in C or C++ or copy-paste some examples, like this one to blink the LED connected to Pin 2:

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
 
#define PIN 2
 
void app_main(void)
{
  gpio_set_direction(PIN, GPIO_MODE_OUTPUT);
  uint32_t isOn = 0;
  while (true)
  {
    isOn = !isOn;
    gpio_set_level(PIN, isOn);
    vTaskDelay(1000 / portTICK_PERIOD_MS);
  }
}

You already know how to compile and upload code to ESP32.

Now, you’ll install the drivers/libraries for your sensors such as DHT11. Here is the component registry:

Vim
1
https://components.espressif.com/

Here is your driver for DHT11:

Vim
1
https://components.espressif.com/components/zorxx/dht

You can add dependency with this command:

Vim
1
idf.py add-dependency "zorxx/dht"

You’ll find the installed components and drivers here (example of my PC):

Vim
1
2
C:\Espressif\frameworks\esp-idf-v5.2.1\components
C:\Espressif\frameworks\esp-idf-v5.2.1\components\driver

They have full documentation (and also component manager):

Vim
1
https://docs.espressif.com/projects/idf-component-manager/en/latest/

This is the shortest and easiest possible guide to get started with the ESP-IDF Framework. I would suggest programming in this way instead of Arduino IDE for your serious projects, including home automation projects.

Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to How to Program ESP32 Devices Using the ESP-IDF Framework (CLI)

  • ESP WROOM 32 : How To Setup ESP32 NodeMCU With Arduino IDE

    Here is Step by Step Guide to Setup on How to Setup ESP32 NodeMCU with Arduino IDE. We Provided Solutions For the Commonly Faced Problems Too.

  • ESP32 vs Arduino : How ESP32 is Different from Arduino

    ESP32 is a low cost, low power consuming System on Chip (SoC) with integrated Wi-Fi and Bluetooth compatible with Arduino IDE.

  • Understanding C/C++ Usage of Arduino and ESP Line

    Both Arduino IDE and ESP-IDF primarily use C/C++. Understanding how C and C++ are employed in Arduino and ESP development is essential for development.

  • ESP32 ESP Rainmaker Cloud for Arduino

    Espressif is a company that has revolutionized the low-cost WiFi, BLE development. With classic ESP32 WROOM module, we have shown Controlling AC Powered Appliances With ESP32 and IBM Watson IoT with zero monthly cost. But the coding part with IBM Watson IoT was not easy. Although, we have pointed out how to use Android Apps […]

performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

vpsdime

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • Cloud-Powered Play: How Streaming Tech is Reshaping Online GamesSeptember 3, 2025
  • How to Use Transcribed Texts for MarketingAugust 14, 2025
  • nRF7002 DK vs ESP32 – A Technical Comparison for Wireless IoT DesignJune 18, 2025
  • Principles of Non-Invasive Blood Glucose Measurement By Near Infrared (NIR)June 11, 2025
  • Continuous Non-Invasive Blood Glucose Measurements: Present Situation (May 2025)May 23, 2025
PC users can consult Corrine Chorney for Security.

Want to know more about us?

Read Notability and Mentions & Our Setup.

Copyright © 2026 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy