Getting Started with ESP32 – Hello World

In this project we will use Visual Studio Code with ESP-IDF extension to create a new ESP-IDF project and then we will build and flash it on ESP32 chip.

Press ⌘ E N to create a new ESP IDF project, this will open new project UI as following.

Fill the required fields as following.

Project Name: hello-esp32

Project Directory: Choose desired location

ESP-IDF Target: Choose ESP32

Serial Port: This will list available serial ports on your system, choose the serial port to which you have connected the ESP32 module (This is applicable if you already have connected your ESP32 module via a USB port on system).

Now click on “Choose Template”button, select “blink” from opened list of project templates and finally create on “Create project using template blink”button.

This will create new ESP IDF project, and visual studio code will display a popup to open the created project in new window, click yes on this popup to open newly project.

Now open the blink.c from main directory and revise the blink delay from 1000 ms to 2000 ms as following. Save the file after making this change.

vTaskDelay(2000 / portTICK_PERIOD_MS);

Here is the final code.

/* Blink Example

   This example code is in the Public Domain (or CC0 licensed, at your option.)

   Unless required by applicable law or agreed to in writing, this
   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
   CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "sdkconfig.h"

/* Can use project configuration menu (idf.py menuconfig) to choose the GPIO to blink,
   or you can edit the following line and set a number here.
*/
#define BLINK_GPIO CONFIG_BLINK_GPIO

void app_main(void)
{
    /* Configure the IOMUX register for pad BLINK_GPIO (some pads are
       muxed to GPIO on reset already, but some default to other
       functions and need to be switched to GPIO. Consult the
       Technical Reference for a list of pads and their default
       functions.)
    */
    gpio_pad_select_gpio(BLINK_GPIO);
    /* Set the GPIO as a push/pull output */
    gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
    while(1) {
        /* Blink off (output low) */
	printf("Turning off the LED\n");
        gpio_set_level(BLINK_GPIO, 0);
        vTaskDelay(2000 / portTICK_PERIOD_MS);
        /* Blink on (output high) */
	printf("Turning on the LED\n");
        gpio_set_level(BLINK_GPIO, 1);
        vTaskDelay(1000 / portTICK_PERIOD_MS);
    }
}

Now press ⌘ E B to build out project.

Once the build process is compete, press ⌘ E F to flash the project binary output onto the connected ESP32 module, please note that you can use command ⌘ E P to choose a port if it is different from one selected during project creation.

Here are are the schematic and breadboard connections of external LED with ESP32 module.

ESP32 LED Connection – Breadboard Connections
ESP32 LED Connection – Schematic

Source code and the frizzing file with breadboard and schematic view can downloaded from this link.

Shoket Mahmood Ahmed

2 thoughts on “Getting Started with ESP32 – Hello World

Leave a Reply

Back to top