ESP32 – blinky with delay function

This blinky project shows how to interface LED to the ESP32 and write a simple program to make the LED blink. The full code is on Github, click here.

Parts List

  • ESP-WROOM-32 module
  • USB<->TTL converter (3.3.V)
  • Efficient power supply (3.3V)
  • R1 – resistor 560Ω, see LED Resistor Calculator
  • LED1 – basic LED

Circuit Diagram

Firmware

This code is written in C and can be compiled using xtensa-esp32-elf-gcc.  Don’t know how to start  ? Please read about how to compile and upload program into ESP32.

#include "freertos/FreeRTOS.h"
#include "esp_event.h"
#include "driver/gpio.h"

#define    LED_GPIO_PIN    GPIO_NUM_4


void
app_main(void)
{
    int level = 0;

    /* setup */
    gpio_set_direction(LED_GPIO_PIN, GPIO_MODE_OUTPUT);

    /* loop */
    while (true) {
        gpio_set_level(LED_GPIO_PIN, level ^= 1);
        vTaskDelay(500 / portTICK_PERIOD_MS);
    }
}

 

Leave a Comment