hack4electronics.com

Creating an ESP32 Project Using Visual Studio Code in ESP-IDF : Tutorial 2 ESP32 FreeRTOS

Creating an ESP32 Project Using Visual Studio Code in ESP-IDF : Tutorial 2 ESP32 FreeRTOS

In the previous article, we learned how to install ESP-IDF in Visual Studio Code.

In this article, we will test ESP-IDF working in Visual Studio Code by uploading a code in ESP32 development kit. To learn this tutorial, you need to have an ESP32 development board (here throughout this tutorial I am using the ESP32 Lolin32 version development board).

    you can follow this tutorial for the installion of ESP-IDF in visual studio code : Installing ESP32 IDF / ESP-IDF in Visual Studio Code: Step-by-Step Guide

    Step 1:

    • In Visual Studio Code, go to View > Command Palette or Ctrl + Shift + P. A menu will open. Type ‘ESP-IDF: New Project.’ This will open a new window to add the project details.
    ESP-IDF  new project

    Specify the project name and directory. Specify the name and directory of your project.

    For the ESP-IDF board, we have chosen the custom board option. I have choosen standard ESP32 development board, you can choose the appropriate board option from the list.

    Click the Choose Template button to proceed. to proceed to the next step.

    Note: When naming your project, do not use spaces. It will not work.

    In the Extension, select ESP-IDF option

    Choose “Create project using template sample_project” at this time.A notification that the project has been created will be sent to you. Click “Yes” to launch the project in a new window.

    With the project we established in the EXPLORER tab is opened. As you can see, our project folder ( contains a number of directories. This applies to each project that you build with ESP-IDF Explorer. The main.c file can be located here because the main folder includes the source code. Our program code will be written inside the main.c file.

    Step 2:

    • Go to main > main.c and open it and write the code as shown below:
    #include <stdio.h>
    
    void app_main() {
      printf("Hello, World!\n");
    }

    Step 3:

    • Go to the toolbars in Visual Studio Code:
      • ESP-IDF: Select Port to use: This allows the user to select the available serial port where their device is connected.
      • ESP-IDF: Select Espressif device target: This allows the user to set the device target.
      • ESP-IDF: Current Project: This selects the current folder.
      • ESP-IDF SDK Configuration Editor
      • ESP-IDF: Full Clean: This cleans the project whereby the user can build the project from the start.
      • ESP-IDF: Build: This will compile the program code and will help in checking for potential errors.
      • ESP-IDF: Select flash method: This allows the user to select the flash method from JTAG, UART, and DFU.
      • ESP-IDF: Flash device: This will download the project in the chip.
      • ESP-IDF: Monitor device: This gives the serial output of the chip.
      • ESP-IDF: Build, Flash, and Monitor
      • ESP-IDF: Open ESP-IDF Terminal: Clicking on this icon opens the terminal. If the terminal was already opened then it refreshes the terminal.
      • ESP-IDF: Execute custom task

    Step 4:

    • Compile the Project: Open ESP-IDF Terminal and type idf.py build and click enter or click on the build icon. Our project will start building. It will take some time for it to be built completely.

    Step 5:

    Step 6:

    • To flash the chip and monitor the output, type the following command in the terminal:
    idf.py flash monitor
    
    • Alternatively, you can just click the flame icon (Build, Flash, and Monitor) that will automatically build, flash and monitor the script.

    Step 7:

    • This is the result of a successful flashing of the ESP32 chip and output we get in the serial monitor for the Hello World script

    Conclusion

    ESP-IDF stands for the ESP32, ESP32-S, and ESP32-C range of SoCs’ official IoT Development Framework. It provides a standalone SDK for C and C++ programmers to use to build any kind of generic application on a variety of platforms. A source code editor used for building and debugging programs is called VS Code, and it is available for Windows, macOS, and Linux.

    Leave a Reply

    Your email address will not be published. Required fields are marked *