Link Search Menu Expand Document

ESP-IDF

Get Started

Step 1. Install prerequisites

Standard Setup of Toolchain for Mac OS

brew install cmake ninja ccache
python --version
Python 3.9.2

Step 2. Get ESP-IDF

mkdir -p ~/esp
cd ~/esp
git clone -b release/v4.0 --recursive https://github.com/espressif/esp-idf.git
Cloning into 'esp-idf'...
remote: Enumerating objects: 255931, done.
remote: Total 255931 (delta 0), reused 0 (delta 0), pack-reused 255931
Receiving objects: 100% (255931/255931), 141.33 MiB | 7.34 MiB/s, done.
Resolving deltas: 100% (189612/189612), done.
Updating files: 100% (5482/5482), done.
Submodule 'components/asio/asio' (https://github.com/espressif/asio.git) registered for path 'components/asio/asio'
Submodule 'components/bootloader/subproject/components/micro-ecc/micro-ecc' (https://github.com/kmackay/micro-ecc.git) registered for path 'components/bootloader/subproject/components/micro-ecc/micro-ecc'
Submodule 'components/bt/controller/lib' (https://github.com/espressif/esp32-bt-lib.git) registered for path 'components/bt/controller/lib'
Submodule 'components/bt/host/nimble/nimble' (https://github.com/espressif/esp-nimble.git) registered for path 'components/bt/host/nimble/nimble'
Submodule 'components/coap/libcoap' (https://github.com/obgm/libcoap.git) registered for path 'components/coap/libcoap'
Submodule 'components/esp_wifi/lib_esp32' (https://github.com/espressif/esp32-wifi-lib.git) registered for path 'components/esp_wifi/lib_esp32'
Submodule 'components/esptool_py/esptool' (https://github.com/espressif/esptool.git) registered for path 'components/esptool_py/esptool'
Submodule 'components/expat/expat' (https://github.com/libexpat/libexpat.git) registered for path 'components/expat/expat'
Submodule 'components/json/cJSON' (https://github.com/DaveGamble/cJSON.git) registered for path 'components/json/cJSON'
Submodule 'components/libsodium/libsodium' (https://github.com/jedisct1/libsodium.git) registered for path 'components/libsodium/libsodium'
Submodule 'components/lwip/lwip' (https://github.com/espressif/esp-lwip.git) registered for path 'components/lwip/lwip'
Submodule 'components/mbedtls/mbedtls' (https://github.com/espressif/mbedtls.git) registered for path 'components/mbedtls/mbedtls'
Submodule 'components/mqtt/esp-mqtt' (https://github.com/espressif/esp-mqtt.git) registered for path 'components/mqtt/esp-mqtt'
Submodule 'components/nghttp/nghttp2' (https://github.com/nghttp2/nghttp2.git) registered for path 'components/nghttp/nghttp2'
Submodule 'components/protobuf-c/protobuf-c' (https://github.com/protobuf-c/protobuf-c.git) registered for path 'components/protobuf-c/protobuf-c'
Submodule 'components/spiffs/spiffs' (https://github.com/pellepl/spiffs.git) registered for path 'components/spiffs/spiffs'
Submodule 'components/unity/unity' (https://github.com/ThrowTheSwitch/Unity.git) registered for path 'components/unity/unity'
Submodule 'examples/build_system/cmake/import_lib/main/lib/tinyxml2' (https://github.com/leethomason/tinyxml2.git) registered for path 'examples/build_system/cmake/import_lib/main/lib/tinyxml2'
...

Step 3. Set up the tools

cd ~/esp/esp-idf
./install.sh
Detecting the Python interpreter
Checking "python" ...
Python 3.9.2
"python" has been detected
Installing ESP-IDF tools
Installing tools: xtensa-esp32-elf, esp32ulp-elf, openocd-esp32
Skipping xtensa-esp32-elf@esp-2020r3-8.4.0 (already installed)
Skipping esp32ulp-elf@2.28.51.20170517 (already installed)
Installing openocd-esp32@v0.10.0-esp32-20210401
Downloading openocd-esp32-macos-0.10.0-esp32-20210401.tar.gz to /Users/adithya321/.espressif/dist/openocd-esp32-macos-0.10.0-esp32-20210401.tar.gz.tmp
Done
Extracting /Users/adithya321/.espressif/dist/openocd-esp32-macos-0.10.0-esp32-20210401.tar.gz to /Users/adithya321/.espressif/tools/openocd-esp32/v0.10.0-esp32-20210401
Installing Python environment and packages
Creating a new Python environment in /Users/adithya321/.espressif/python_env/idf4.0_py3.9_env
Installing virtualenv
Collecting virtualenv
  Downloading virtualenv-20.6.0-py2.py3-none-any.whl (5.3 MB)
     |████████████████████████████████| 5.3 MB 8.6 MB/s
Collecting distlib<1,>=0.3.1
  Downloading distlib-0.3.2-py2.py3-none-any.whl (338 kB)
     |████████████████████████████████| 338 kB 44.7 MB/s
Collecting platformdirs<3,>=2
  Downloading platformdirs-2.0.2-py2.py3-none-any.whl (10 kB)
Collecting six<2,>=1.9.0
  Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
Collecting backports.entry-points-selectable>=1.0.4
  Downloading backports.entry_points_selectable-1.1.0-py2.py3-none-any.whl (6.2 kB)
Collecting filelock<4,>=3.0.0
  Downloading filelock-3.0.12-py3-none-any.whl (7.6 kB)
Installing collected packages: distlib, platformdirs, six, backports.entry-points-selectable, filelock, virtualenv
  WARNING: The script virtualenv is installed in '/Users/adithya321/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  NOTE: The current PATH contains path(s) starting with `~`, which may not be expanded by all applications.
Successfully installed backports.entry-points-selectable-1.1.0 distlib-0.3.2 filelock-3.0.12 platformdirs-2.0.2 six-1.16.0 virtualenv-20.6.0
WARNING: You are using pip version 20.2.3; however, version 21.1.3 is available.
You should consider upgrading via the '/Users/adithya321/.pyenv/versions/3.9.2/bin/python -m pip install --upgrade pip' command.
created virtual environment CPython3.9.2.final.0-64 in 560ms
  creator CPython3Posix(dest=/Users/adithya321/.espressif/python_env/idf4.0_py3.9_env, clear=False, no_vcs_ignore=False, global=False)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/Users/adithya321/Library/Application Support/virtualenv)
    added seed packages: pip==21.1.3, setuptools==57.1.0, wheel==0.36.2
  activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
Installing Python packages from /Users/adithya321/esp/esp-idf/requirements.txt
Requirement already satisfied: setuptools in /Users/adithya321/.espressif/python_env/idf4.0_py3.9_env/lib/python3.9/site-packages (from -r /Users/adithya321/esp/esp-idf/requirements.txt (line 4)) (57.1.0)
Collecting click>=5.0
  Using cached click-8.0.1-py3-none-any.whl (97 kB)
Collecting pyserial>=3.0
  Downloading pyserial-3.5-py2.py3-none-any.whl (90 kB)
     |████████████████████████████████| 90 kB 7.9 kB/s
Collecting future>=0.15.2
  Downloading future-0.18.2.tar.gz (829 kB)
     |████████████████████████████████| 829 kB 12.2 MB/s
Collecting cryptography>=2.1.4
  Downloading cryptography-3.4.7-cp36-abi3-macosx_10_10_x86_64.whl (2.0 MB)
     |████████████████████████████████| 2.0 MB 11.2 MB/s
Collecting pyparsing<2.4.0,>=2.0.3
  Downloading pyparsing-2.3.1-py2.py3-none-any.whl (61 kB)
     |████████████████████████████████| 61 kB 1.3 MB/s
Collecting pyelftools>=0.22
  Downloading pyelftools-0.27-py2.py3-none-any.whl (151 kB)
     |████████████████████████████████| 151 kB 16.2 MB/s
Collecting cffi>=1.12
  Downloading cffi-1.14.6-cp39-cp39-macosx_10_9_x86_64.whl (176 kB)
     |████████████████████████████████| 176 kB 14.7 MB/s
Collecting pycparser
  Downloading pycparser-2.20-py2.py3-none-any.whl (112 kB)
     |████████████████████████████████| 112 kB 13.5 MB/s
Building wheels for collected packages: future
  Building wheel for future (setup.py) ... done
  Created wheel for future: filename=future-0.18.2-py3-none-any.whl size=491070 sha256=441e9661e2a3f4764b1ac44ed11d61034306a8394551cc53684f31cf41087d1c
  Stored in directory: /Users/adithya321/Library/Caches/pip/wheels/2f/a0/d3/4030d9f80e6b3be787f19fc911b8e7aa462986a40ab1e4bb94
Successfully built future
Installing collected packages: pycparser, cffi, pyserial, pyparsing, pyelftools, future, cryptography, click
Successfully installed cffi-1.14.6 click-8.0.1 cryptography-3.4.7 future-0.18.2 pycparser-2.20 pyelftools-0.27 pyparsing-2.3.1 pyserial-3.5
All done! You can now run:

  . ./export.sh

Step 4. Set up the environment variables

echo "alias get_idf='. $HOME/esp/esp-idf/export.sh'" | tee -a ~/.zshrc
source ~/.zshrc
get_idf
Setting IDF_PATH to '/Users/adithya321/esp/esp-idf'
Detecting the Python interpreter
Checking "python" ...
Python 3.9.2
"python" has been detected
Adding ESP-IDF tools to PATH...
Checking if Python packages are up to date...
Python requirements from /Users/adithya321/esp/esp-idf/requirements.txt are satisfied.
Updated PATH variable:
  /Users/adithya321/esp/esp-idf/components/esptool_py/esptool:/Users/adithya321/esp/esp-idf/components/espcoredump:/Users/adithya321/esp/esp-idf/components/partition_table/:/Users/adithya321/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin:/Users/adithya321/.espressif/tools/esp32ulp-elf/2.28.51.20170517/esp32ulp-elf-binutils/bin:/Users/adithya321/.espressif/tools/openocd-esp32/v0.10.0-esp32-20210401/openocd-esp32/bin:/Users/adithya321/.espressif/python_env/idf4.0_py3.9_env/bin:/Users/adithya321/esp/esp-idf/tools:/Users/adithya321/google-cloud-sdk/bin:/Users/adithya321/.volta/bin:/usr/local/opt/libpq/bin:/Users/adithya321/.pyenv/shims:/Users/adithya321/.avn/bin:/Users/adithya321/.nvm/versions/node/v15.5.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public:/usr/local/share/dotnet:~/.dotnet/tools:/Library/Apple/usr/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Users/adithya321/google-cloud-sdk/bin:/Users/adithya321/.volta/bin:/usr/local/opt/libpq/bin:/Users/adithya321/.pyenv/shims:/Users/adithya321/.avn/bin:/Users/adithya321/.nvm/versions/node/v15.5.0/bin:/Users/adithya321/.cargo/bin
Done! You can now compile ESP-IDF projects.
Go to the project directory and run:

  idf.py build

Step 5. Start a Project

{
    cd ~/esp
    cp -r $IDF_PATH/examples/get-started/hello_world .
    cd hello_world

    idf.py menuconfig
    idf.py build

    idf.py -p /dev/cu.SLAB_USBtoUART flash monitor
}
...

Hello world!
This is ESP32 chip with 2 CPU cores, WiFi/BT/BLE, silicon revision 1, 2MB external flash
Restarting in 10 seconds...
Restarting in 9 seconds...
Restarting in 8 seconds...
Restarting in 7 seconds...
Restarting in 6 seconds...
Restarting in 5 seconds...
Restarting in 4 seconds...
Restarting in 3 seconds...
Restarting in 2 seconds...
Restarting in 1 seconds...
Restarting in 0 seconds...
Restarting now.
ets Jun  8 2016 00:22:57

...
{
    cd ~/esp
    cp -r $IDF_PATH/examples/get-started/blink .
    cd blink

    idf.py menuconfig # Change pin to GPIO2

    idf.py build
    idf.py -p /dev/cu.SLAB_USBtoUART flash monitor
}
...

Turning off the LED
Turning on the LED
Turning off the LED
Turning on the LED
Turning off the LED

...

Children

  1. ESP IDF v4.3.1


Page last modified: 7/20/2021.