u/sh_pa_ic_rk_ie_tr

▲ 2 r/esp32

Help please, can't get on-board LED to blink, this is my code. Uncommenting the printf statements makes the LED blink. Can you please help me understand what's going on and how I can fix it?

void app_main(void) {
    // Resets any previous state of the pin (good practice)
    gpio_reset_pin(LED_GPIO);
    // Configure GPIO2 as output
    gpio_set_direction(LED_GPIO, GPIO_MODE_OUTPUT);
    
    // Blink forever
    while (1) {
        gpio_set_level(LED_GPIO, 1);            // Set pin(GPIO2 in this case) to HIGH(3.3V)
        // printf("LED ON\n");
        vTaskDelay(pdMS_TO_TICKS(1000)); 

        gpio_set_level(LED_GPIO, 0);            // Set pin(GPIO2 in this case) to LOW(0V)
        // printf("LED OFF\n");
        vTaskDelay(pdMS_TO_TICKS(1000)); 
    }
}
reddit.com
u/sh_pa_ic_rk_ie_tr — 22 hours ago

Help, can't get on-board LED to blink on ESP32

Hello, I'm a complete beginner trying to get into embedded systems with ESP32. I want to get the LED to blink using this code

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"

// Built-in LED is on GPIO2
#define LED_GPIO GPIO_NUM_2

void app_main(void) {
    // Resets any previous state of the pin (good practice)
    gpio_reset_pin(LED_GPIO);
    // Configure GPIO2 as output
    gpio_set_direction(LED_GPIO, GPIO_MODE_OUTPUT);
    
    // Blink forever
    while (1) {
        gpio_set_level(LED_GPIO, 1);            // Set pin(GPIO2 in this case) to HIGH(3.3V)
        vTaskDelay(pdMS_TO_TICKS(1000)); 

        gpio_set_level(LED_GPIO, 0);            // Set pin(GPIO2 in this case) to LOW(0V)
        vTaskDelay(pdMS_TO_TICKS(1000)); 
    }
}

But the LED does not blink. However when I add printfs before the delay like this, it blinks

// Blink forever
while (1) {
    gpio_set_level(LED_GPIO, 1);            // Set pin(GPIO2 in this case) to HIGH(3.3V)
    printf("LED ON\n");
    vTaskDelay(pdMS_TO_TICKS(1000)); 
    gpio_set_level(LED_GPIO, 0);            // Set pin(GPIO2 in this case) to LOW(0V)
    printf("LED OFF\n");
    vTaskDelay(pdMS_TO_TICKS(1000));
}

Can someone please help me know why this is happening and how can I fix it?

I'm using an ESP32 DEV KIT V1

reddit.com
u/sh_pa_ic_rk_ie_tr — 1 day ago