blink_main.c

ESP32-H2 · File : blink_main.c · Language : C · Use case : Faire clignoter une LED avec un projet ESP-IDF

The ESP-IDF hello-world on the H2: the GPIO driver and FreeRTOS tasks replace Arduino. The log prints free heap on every blink — the reflex before stacking 802.15.4 radio components.

Hardware required

An ESP32-H2 board (RISC-V 96 MHz, IEEE 802.15.4 radio only — no Wi-Fi) such as a DevKitM-1, powered over USB. None: the DevKitM-1/DevKitC-1 user LED (GPIO8) or LED + 330 Ω.

Wiring

Nothing to wire on the DevKit; otherwise LED on GPIO8 through 300 Ω to GND. Serial console on the USB-Serial/JTAG port (GPIO26/27).

How it works

app_main is the entry point launched by the RTOS; gpio_set_level drives the pin and vTaskDelay sleeps the task for 500 ms without blocking the scheduler — the basis of ESP-IDF code. Program it with ESP-IDF (idf.py set-target esp32h2); the USB-Serial/JTAG port (GPIO26/27) acts as console and flash port. Hold Boot + Reset for download mode if needed.

Going further

Move to LEDC for a breathing effect, or create two tasks with different priorities to watch FreeRTOS scheduling.

blink_main.c

// blink_main.c — projet minimal ESP-IDF v5.x pour ESP32-H2.
// idf.py set-target esp32h2 && idf.py flash monitor
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "esp_log.h"

#define BROCHE_LED GPIO_NUM_8      // LED utilisateur de nombreux DevKitC-1

static const char *TAG = "blink";

void app_main(void)
{
    ESP_LOGI(TAG, "Clignotement H2 demarre");
    gpio_reset_pin(BROCHE_LED);
    gpio_set_direction(BROCHE_LED, GPIO_MODE_OUTPUT);

    int n = 0;
    while (1) {
        gpio_set_level(BROCHE_LED, n & 1);
        ESP_LOGI(TAG, "LED %d — heap libre %u", n & 1,
                 (unsigned)xPortGetFreeHeapSize());
        n++;
        vTaskDelay(pdMS_TO_TICKS(500));   // cede le CPU au scheduler
    }
}

← Back to the board