Convert Figma logo to code with AI

espressif logoarduino-esp32

Arduino core for the ESP32

13,492
7,382
13,492
582

Top Related Projects

13,539

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

Sample ESP32 snippets and code fragments

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

Lua based interactive firmware for ESP8266, ESP8285 and ESP32

Quick Overview

The espressif/arduino-esp32 repository is an Arduino core for ESP32 microcontrollers. It allows users to program ESP32 devices using the familiar Arduino IDE and ecosystem, providing a bridge between Arduino's simplicity and ESP32's powerful features.

Pros

  • Easy integration with the Arduino ecosystem and IDE
  • Access to ESP32's advanced features like Wi-Fi, Bluetooth, and dual-core processing
  • Large community support and extensive documentation
  • Regular updates and improvements from Espressif

Cons

  • May not fully utilize all ESP32 capabilities compared to native ESP-IDF framework
  • Some Arduino libraries may not be compatible or optimized for ESP32
  • Performance overhead due to Arduino abstraction layer
  • Learning curve for ESP32-specific features and limitations

Code Examples

  1. Blinking an LED:
const int ledPin = 2;

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

void loop() {
  digitalWrite(ledPin, HIGH);
  delay(1000);
  digitalWrite(ledPin, LOW);
  delay(1000);
}
  1. Connecting to Wi-Fi:
#include <WiFi.h>

const char* ssid = "YourWiFiSSID";
const char* password = "YourWiFiPassword";

void setup() {
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }
  
  Serial.println("Connected to WiFi");
}

void loop() {
  // Your code here
}
  1. Using both cores of ESP32:
TaskHandle_t Task1;
TaskHandle_t Task2;

void setup() {
  Serial.begin(115200);
  xTaskCreatePinnedToCore(
    Task1code, "Task1", 10000, NULL, 1, &Task1, 0);
  xTaskCreatePinnedToCore(
    Task2code, "Task2", 10000, NULL, 1, &Task2, 1);
}

void Task1code(void * parameter) {
  for(;;) {
    Serial.println("Task1 running on core " + String(xPortGetCoreID()));
    delay(1000);
  }
}

void Task2code(void * parameter) {
  for(;;) {
    Serial.println("Task2 running on core " + String(xPortGetCoreID()));
    delay(1000);
  }
}

void loop() {
  // This loop runs on core 1
}

Getting Started

  1. Install the Arduino IDE from the official website.
  2. Open Arduino IDE Preferences and add the following URL to the "Additional Boards Manager URLs" field:
    https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
    
  3. Go to Tools > Board > Boards Manager, search for "esp32", and install the "ESP32 by Espressif Systems" package.
  4. Select your ESP32 board from Tools > Board > ESP32 Arduino.
  5. Connect your ESP32 board and select the appropriate port.
  6. You're now ready to program your ESP32 using Arduino!

Competitor Comparisons

13,539

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

Pros of esp-idf

  • More comprehensive and flexible for advanced ESP32 development
  • Direct access to low-level hardware features and APIs
  • Better performance and power management capabilities

Cons of esp-idf

  • Steeper learning curve, especially for beginners
  • Requires more setup and configuration compared to Arduino
  • Less extensive community support and third-party libraries

Code Comparison

esp-idf:

#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();
}

arduino-esp32:

#include <WiFi.h>

void setup() {
    Serial.begin(115200);
    WiFi.begin("SSID", "PASSWORD");
}

void loop() {
    // Main program logic
}

The esp-idf code demonstrates lower-level initialization and control, while arduino-esp32 provides a simpler, more abstracted approach. esp-idf offers more granular control over system components, but requires more detailed setup. arduino-esp32 simplifies common tasks, making it easier for beginners to get started, but may limit access to some advanced features.

Sample ESP32 snippets and code fragments

Pros of esp32-snippets

  • Focused on providing code snippets and examples for specific ESP32 features
  • Includes a wider range of ESP32-specific functionalities beyond Arduino compatibility
  • More detailed documentation and explanations for each code snippet

Cons of esp32-snippets

  • Less integrated with the Arduino ecosystem
  • May require more manual setup and configuration
  • Not as frequently updated as arduino-esp32

Code Comparison

esp32-snippets:

#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>

BLEServer* pServer = NULL;

arduino-esp32:

#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>

BLEServer* pServer = BLEDevice::createServer();

The code snippets are similar, but arduino-esp32 provides a more streamlined approach with built-in functions for common tasks. esp32-snippets often includes more detailed explanations and alternative implementations, which can be beneficial for learning and understanding the underlying concepts.

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

Pros of MicroPython

  • Simpler syntax and easier to learn for beginners
  • Interactive REPL for quick testing and development
  • Smaller memory footprint, suitable for resource-constrained devices

Cons of MicroPython

  • Generally slower execution compared to compiled C++ code
  • Limited availability of libraries and modules compared to Arduino ecosystem
  • Less mature and smaller community support

Code Comparison

MicroPython:

from machine import Pin
import time

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

Arduino-ESP32:

const int ledPin = 2;

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

void loop() {
  digitalWrite(ledPin, !digitalRead(ledPin));
  delay(1000);
}

Both examples demonstrate blinking an LED on pin 2 with a 1-second interval. MicroPython's code is more concise and readable, while Arduino-ESP32's code follows a familiar structure for Arduino users. The Arduino version may have slightly better performance due to compilation, but the difference is negligible for simple tasks like this.

Lua based interactive firmware for ESP8266, ESP8285 and ESP32

Pros of nodemcu-firmware

  • Built-in Lua interpreter for easier scripting and rapid prototyping
  • Smaller firmware size, suitable for resource-constrained devices
  • Includes a file system for storing Lua scripts and data

Cons of nodemcu-firmware

  • Limited hardware support compared to arduino-esp32
  • Less frequent updates and smaller community support
  • Steeper learning curve for developers not familiar with Lua

Code Comparison

NodeMCU (Lua):

gpio.mode(4, gpio.OUTPUT)
tmr.create():alarm(1000, tmr.ALARM_AUTO, function()
    gpio.write(4, gpio.read(4) == gpio.HIGH and gpio.LOW or gpio.HIGH)
end)

Arduino-ESP32 (C++):

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

void loop() {
  digitalWrite(4, !digitalRead(4));
  delay(1000);
}

The NodeMCU example uses Lua's event-driven programming model with timers, while the Arduino-ESP32 code follows a more traditional setup/loop structure. NodeMCU's approach can be more flexible for complex timing scenarios, but Arduino's simplicity may be preferable for beginners or straightforward applications.

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

Arduino core for the ESP32, ESP32-S2, ESP32-S3, ESP32-C3, ESP32-C6 and ESP32-H2

Build Status External Libraries Test Hardware Tests

Need help or have a question? Join the chat at Gitter or open a new Discussion

Contents

Development Status

Latest Stable Release Release Version Release Date Downloads

Latest Development Release Release Version Release Date Downloads

Development Planning

Our Development is fully tracked on this public Roadmap 🎉

For even more information you can join our Monthly Community Meetings 🔔.

Documentation

You can use the Arduino-ESP32 Online Documentation to get all information about this project.


Migration guide from version 2.x to 3.x is available here.


APIs compatibility with ESP8266 and Arduino-CORE (Arduino.cc) is explained here.


Supported Chips

Here are the ESP32 series supported by the Arduino-ESP32 project:

SoCStableDevelopmentDatasheet
ESP32YesYesESP32
ESP32-S2YesYesESP32-S2
ESP32-C3YesYesESP32-C3
ESP32-S3YesYesESP32-S3
ESP32-C6YesYesESP32-C6
ESP32-H2YesYesESP32-H2

[!NOTE] ESP32-C2 is also supported by Arduino-ESP32 but requires rebuilding the static libraries. This is not trivial and requires a good understanding of the ESP-IDF build system. For more information, see the Lib Builder documentation.

For more details visit the supported chips documentation page.

Decoding exceptions

You can use EspExceptionDecoder to get meaningful call trace.

Issue/Bug report template

Before reporting an issue, make sure you've searched for similar one that was already created. Also make sure to go through all the issues labeled as Type: For reference.

Finally, if you are sure no one else had the issue, follow the Issue template or Feature request template while reporting any new Issue.

External libraries compilation test

We have set-up CI testing for external libraries for ESP32 Arduino core. You can check test results in the file LIBRARIES_TEST. For more information and how to add your library to the test see external library testing in the documentation.

Contributing

We welcome contributions to the Arduino ESP32 project!

See contributing in the documentation for more information on how to contribute to the project.

We would like to have this repository in a polite and friendly atmosphere, so please be kind and respectful to others. For more details, look at Code of Conduct.