Convert Figma logo to code with AI

espressif logoesp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.

13,291
7,200
13,291
1,777

Top Related Projects

Your Gateway to Embedded Software Development Excellence :alien:

Arduino command line tool

MicroPython - a lean and efficient Python implementation for microcontrollers and constrained systems

4,656

Arm Mbed OS is a platform operating system designed for the internet of things

10,446

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.

Quick Overview

ESP-IDF (Espressif IoT Development Framework) is the official development framework for Espressif's ESP32, ESP32-S, and ESP32-C series of Wi-Fi and Bluetooth-enabled microcontrollers. It provides a robust and feature-rich environment for building IoT applications, offering a wide range of APIs, tools, and libraries to simplify development on Espressif's hardware platforms.

Pros

  • Comprehensive ecosystem with extensive documentation, examples, and community support
  • Regular updates and improvements, ensuring compatibility with the latest hardware features
  • Built-in support for various protocols (Wi-Fi, Bluetooth, MQTT, HTTP, etc.) and peripherals
  • Powerful build system and debugging tools for efficient development

Cons

  • Steep learning curve for beginners, especially those new to embedded systems
  • Large codebase and dependencies can lead to longer compile times
  • Some users report occasional stability issues or bugs in certain components
  • Limited portability to non-Espressif platforms

Code Examples

  1. Connecting to Wi-Fi:
#include "esp_wifi.h"
#include "esp_event.h"
#include "nvs_flash.h"

void app_main(void)
{
    nvs_flash_init();
    esp_netif_init();
    esp_event_loop_create_default();
    
    wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
    esp_wifi_init(&cfg);
    esp_wifi_set_mode(WIFI_MODE_STA);
    esp_wifi_start();
}
  1. Reading sensor data using I2C:
#include "driver/i2c.h"

#define I2C_MASTER_SCL_IO 22
#define I2C_MASTER_SDA_IO 21
#define I2C_MASTER_NUM I2C_NUM_0
#define I2C_MASTER_FREQ_HZ 100000

void app_main(void)
{
    i2c_config_t conf = {
        .mode = I2C_MODE_MASTER,
        .sda_io_num = I2C_MASTER_SDA_IO,
        .scl_io_num = I2C_MASTER_SCL_IO,
        .sda_pullup_en = GPIO_PULLUP_ENABLE,
        .scl_pullup_en = GPIO_PULLUP_ENABLE,
        .master.clk_speed = I2C_MASTER_FREQ_HZ,
    };
    i2c_param_config(I2C_MASTER_NUM, &conf);
    i2c_driver_install(I2C_MASTER_NUM, conf.mode, 0, 0, 0);
}
  1. Creating a simple HTTP server:
#include "esp_http_server.h"

static esp_err_t root_handler(httpd_req_t *req)
{
    httpd_resp_send(req, "Hello World!", HTTPD_RESP_USE_STRLEN);
    return ESP_OK;
}

void app_main(void)
{
    httpd_handle_t server = NULL;
    httpd_config_t config = HTTPD_DEFAULT_CONFIG();
    httpd_start(&server, &config);
    
    httpd_uri_t uri_get = {
        .uri = "/",
        .method = HTTP_GET,
        .handler = root_handler,
        .user_ctx = NULL
    };
    httpd_register_uri_handler(server, &uri_get);
}

Getting Started

  1. Install ESP-IDF following the official guide: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/
  2. Set up the environment variables:
    . $HOME/esp/esp-idf/export.sh
    
  3. Create a new project:
    idf.py create-project my_project
    cd my_project
    
  4. Configure, build, and flash

Competitor Comparisons

Your Gateway to Embedded Software Development Excellence :alien:

Pros of PlatformIO Core

  • Multi-platform support: Works with various microcontrollers and development boards, not limited to ESP32
  • Integrated development environment: Offers a complete ecosystem with library management, debugging, and testing tools
  • Simplified project management: Provides a unified interface for different platforms and frameworks

Cons of PlatformIO Core

  • Learning curve: May require additional time to understand its ecosystem and configuration
  • Less ESP-specific optimizations: Might not offer the same level of fine-tuning for ESP32 as ESP-IDF
  • Dependency on third-party tools: Relies on external components, which may introduce compatibility issues

Code Comparison

ESP-IDF (main.c):

#include "esp_system.h"

void app_main(void)
{
    // ESP-IDF specific code
}

PlatformIO Core (main.cpp):

#include <Arduino.h>

void setup() {
    // PlatformIO setup code
}

void loop() {
    // PlatformIO main loop
}

The code comparison shows that ESP-IDF uses a C-style entry point with app_main(), while PlatformIO Core typically uses the Arduino-style setup() and loop() functions in C++. This reflects the different approaches and ecosystems of the two platforms.

Arduino command line tool

Pros of arduino-cli

  • Simpler and more user-friendly for beginners
  • Supports a wide range of Arduino boards and compatible hardware
  • Extensive library ecosystem with easy-to-use functions

Cons of arduino-cli

  • Limited low-level hardware control compared to esp-idf
  • Less optimized for specific ESP32 features and capabilities
  • Fewer advanced debugging and analysis tools

Code Comparison

arduino-cli example:

#include <Arduino.h>

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);
  delay(1000);
  digitalWrite(LED_BUILTIN, LOW);
  delay(1000);
}

esp-idf example:

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

void app_main() {
    gpio_pad_select_gpio(GPIO_NUM_2);
    gpio_set_direction(GPIO_NUM_2, GPIO_MODE_OUTPUT);
    while (1) {
        gpio_set_level(GPIO_NUM_2, 1);
        vTaskDelay(1000 / portTICK_PERIOD_MS);
        gpio_set_level(GPIO_NUM_2, 0);
        vTaskDelay(1000 / portTICK_PERIOD_MS);
    }
}

The arduino-cli code is more straightforward and uses familiar Arduino functions, while the esp-idf code offers more direct hardware control and uses FreeRTOS for task management.

MicroPython - a lean and efficient Python implementation for microcontrollers and constrained systems

Pros of MicroPython

  • Easier to learn and use, especially for beginners
  • Faster development and prototyping
  • Interactive REPL for quick testing and debugging

Cons of MicroPython

  • Lower performance compared to native C code
  • Limited access to low-level hardware features
  • Larger memory footprint

Code Comparison

MicroPython:

import machine
import time

led = machine.Pin(2, machine.Pin.OUT)
while True:
    led.value(not led.value())
    time.sleep(1)

ESP-IDF:

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

void app_main() {
    gpio_set_direction(GPIO_NUM_2, GPIO_MODE_OUTPUT);
    while (1) {
        gpio_set_level(GPIO_NUM_2, !gpio_get_level(GPIO_NUM_2));
        vTaskDelay(1000 / portTICK_PERIOD_MS);
    }
}

The MicroPython code is more concise and readable, while the ESP-IDF code offers more control and better performance. ESP-IDF provides a comprehensive development framework for ESP32 chips, with extensive libraries and tools. MicroPython, on the other hand, offers a more accessible and rapid development experience, particularly suitable for smaller projects and educational purposes.

4,656

Arm Mbed OS is a platform operating system designed for the internet of things

Pros of mbed-os

  • Supports a wider range of ARM-based microcontrollers
  • More extensive ecosystem with a larger community and more third-party libraries
  • Provides a higher-level abstraction layer, making it easier for beginners

Cons of mbed-os

  • Generally slower performance compared to esp-idf
  • Less optimized for specific hardware, potentially leading to larger binary sizes
  • May have higher power consumption due to the abstraction layer

Code Comparison

mbed-os example:

#include "mbed.h"

DigitalOut led(LED1);

int main() {
    while (1) {
        led = !led;
        ThisThread::sleep_for(500ms);
    }
}

esp-idf example:

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

void app_main(void) {
    gpio_set_direction(GPIO_NUM_2, GPIO_MODE_OUTPUT);
    while (1) {
        gpio_set_level(GPIO_NUM_2, !gpio_get_level(GPIO_NUM_2));
        vTaskDelay(pdMS_TO_TICKS(500));
    }
}

Both examples demonstrate a simple LED blinking program, highlighting the differences in API and abstraction level between the two frameworks.

10,446

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.

Pros of Zephyr

  • Supports a wider range of hardware platforms and architectures
  • More extensive and active community support
  • Offers a more comprehensive set of features for real-time operating systems

Cons of Zephyr

  • Steeper learning curve for developers new to RTOS
  • May have higher resource requirements for simpler projects
  • Less specialized for Espressif hardware compared to ESP-IDF

Code Comparison

ESP-IDF example (FreeRTOS task creation):

void app_main(void)
{
    xTaskCreate(my_task, "my_task", 2048, NULL, 5, NULL);
}

Zephyr example (Thread creation):

void main(void)
{
    k_thread_create(&my_thread, my_stack, K_THREAD_STACK_SIZEOF(my_stack),
                    my_entry, NULL, NULL, NULL, MY_PRIORITY, 0, K_NO_WAIT);
}

Both examples demonstrate task/thread creation, but Zephyr's API is more detailed and offers finer control over thread parameters.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Espressif IoT Development Framework

ESP-IDF is the development framework for Espressif SoCs supported on Windows, Linux and macOS.

ESP-IDF Release Support Schedule

Support Schedule

ESP-IDF Release and SoC Compatibility

The following table shows ESP-IDF support of Espressif SoCs where alt text and alt text denote preview status and support, respectively. The preview support is usually limited in time and intended for beta versions of chips. Please use an ESP-IDF release where the desired SoC is already supported.

Chipv5.0v5.1v5.2v5.3
ESP32alt textalt textalt textalt text
ESP32-S2alt textalt textalt textalt text
ESP32-C3alt textalt textalt textalt text
ESP32-S3alt textalt textalt textalt textAnnouncement
ESP32-C2alt textalt textalt textalt textAnnouncement
ESP32-C6alt textalt textalt textAnnouncement
ESP32-H2alt textalt textalt textAnnouncement
ESP32-P4alt textAnnouncement
ESP32-C5alt textAnnouncement

There are variants of revisions for a series of chips. See Compatibility Between ESP-IDF Releases and Revisions of Espressif SoCs for the details of the compatibility between ESP-IDF and chip revisions.

Espressif SoCs released before 2016 (ESP8266 and ESP8285) are supported by RTOS SDK instead.

Developing With ESP-IDF

Setting Up ESP-IDF

See https://idf.espressif.com/ for links to detailed instructions on how to set up the ESP-IDF depending on chip you use.

Note: Each SoC series and each ESP-IDF release has its own documentation. Please see Section Versions on how to find documentation and how to checkout specific release of ESP-IDF.

Non-GitHub forks

ESP-IDF uses relative locations as its submodules URLs (.gitmodules). So they link to GitHub. If ESP-IDF is forked to a Git repository which is not on GitHub, you will need to run the script tools/set-submodules-to-github.sh after git clone.

The script sets absolute URLs for all submodules, allowing git submodule update --init --recursive to complete. If cloning ESP-IDF from GitHub, this step is not needed.

Finding a Project

As well as the esp-idf-template project mentioned in Getting Started, ESP-IDF comes with some example projects in the examples directory.

Once you've found the project you want to work with, change to its directory and you can configure and build it.

To start your own project based on an example, copy the example project directory outside of the ESP-IDF directory.

Quick Reference

See the Getting Started guide links above for a detailed setup guide. This is a quick reference for common commands when working with ESP-IDF projects:

Setup Build Environment

(See the Getting Started guide listed above for a full list of required steps with more details.)

  • Install host build dependencies mentioned in the Getting Started guide.
  • Run the install script to set up the build environment. The options include install.bat or install.ps1 for Windows, and install.sh or install.fish for Unix shells.
  • Run the export script on Windows (export.bat) or source it on Unix (source export.sh) in every shell environment before using ESP-IDF.

Configuring the Project

  • idf.py set-target <chip_name> sets the target of the project to <chip_name>. Run idf.py set-target without any arguments to see a list of supported targets.
  • idf.py menuconfig opens a text-based configuration menu where you can configure the project.

Compiling the Project

idf.py build

... will compile app, bootloader and generate a partition table based on the config.

Flashing the Project

When the build finishes, it will print a command line to use esptool.py to flash the chip. However you can also do this automatically by running:

idf.py -p PORT flash

Replace PORT with the name of your serial port (like COM3 on Windows, /dev/ttyUSB0 on Linux, or /dev/cu.usbserial-X on MacOS. If the -p option is left out, idf.py flash will try to flash the first available serial port.

This will flash the entire project (app, bootloader and partition table) to a new chip. The settings for serial port flashing can be configured with idf.py menuconfig.

You don't need to run idf.py build before running idf.py flash, idf.py flash will automatically rebuild anything which needs it.

Viewing Serial Output

The idf.py monitor target uses the esp-idf-monitor tool to display serial output from Espressif SoCs. esp-idf-monitor also has a range of features to decode crash output and interact with the device. Check the documentation page for details.

Exit the monitor by typing Ctrl-].

To build, flash and monitor output in one pass, you can run:

idf.py flash monitor

Compiling & Flashing Only the App

After the initial flash, you may just want to build and flash just your app, not the bootloader and partition table:

  • idf.py app - build just the app.
  • idf.py app-flash - flash just the app.

idf.py app-flash will automatically rebuild the app if any source files have changed.

(In normal development there's no downside to reflashing the bootloader and partition table each time, if they haven't changed.)

Erasing Flash

The idf.py flash target does not erase the entire flash contents. However it is sometimes useful to set the device back to a totally erased state, particularly when making partition table changes or OTA app updates. To erase the entire flash, run idf.py erase-flash.

This can be combined with other targets, ie idf.py -p PORT erase-flash flash will erase everything and then re-flash the new app, bootloader and partition table.

Resources