Skip to content

Instantly share code, notes, and snippets.

@LastZactionHero
Created June 26, 2025 03:38
Show Gist options
  • Save LastZactionHero/ed84bc775e3d85f8d29d77de09583566 to your computer and use it in GitHub Desktop.
Save LastZactionHero/ed84bc775e3d85f8d29d77de09583566 to your computer and use it in GitHub Desktop.
ESP32 C++ Development Setup Guide

ESP32 "Hello World" Example

This is a simple "Hello World" example for the ESP32, using the ESP-IDF C++ framework.

Setup

These steps only need to be performed once.

  1. Install Prerequisites:

    brew install cmake ninja dfu-util
  2. Clone the ESP-IDF repository:

    mkdir ~/esp
    cd ~/esp
    git clone --recursive https://github.com/espressif/esp-idf.git
  3. Install ESP-IDF Tools:

    cd ~/esp/esp-idf
    ./install.sh
  4. Set up Environment Variables: To make the idf.py command available in every terminal session, add the following alias to your shell's profile script (e.g., ~/.zshrc or ~/.bash_profile):

    echo "alias get_idf='. $HOME/esp/esp-idf/export.sh'" >> ~/.zshrc

    Then, in any new terminal, you can type get_idf to set up the environment.

Creating a New Project

To create a new project, you can copy the hello_world example:

cp -r ~/esp/esp-idf/examples/get-started/hello_world ~/esp/my_new_project
cd ~/esp/my_new_project

Building and Flashing

  1. Navigate to your project directory:

    cd ~/esp/hello_world 
  2. Set up the environment in your new terminal:

    . ~/esp/esp-idf/export.sh

    Or, if you've set up the alias:

    get_idf
  3. Set the target chip (only needs to be done once per project):

    idf.py set-target esp32
  4. Build the project:

    idf.py build
  5. Flash and monitor the project: Connect your ESP32 board and run:

    idf.py -p /dev/cu.usbserial-10 flash monitor

    (Replace /dev/cu.usbserial-10 with your device's serial port if it's different.)

    To exit the monitor, press Ctrl+].

Program Walkthrough

The main logic is in main/hello_world_main.c.

  • It starts by printing "Hello world!".
  • Then, it retrieves and prints information about the ESP32 chip, including the number of cores, features (WiFi, BT, BLE), silicon revision, and flash size.
  • It prints the minimum free heap size.
  • Finally, it counts down from 10 and restarts the device.

Next Steps

Now that you have a working development environment, you can start exploring the other examples in the ~/esp/esp-idf/examples directory. These examples cover a wide range of functionalities, from GPIO and timers to Wi-Fi and Bluetooth.

You can also start writing your own applications by modifying the hello_world_main.c file or creating new source files in the main directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment