This is a step-by-step tutorial, which will show you how to install ESP32 ESP-IDF in Linux Ubuntu and then build and flash an example code to an ESP32 development board. The official IoT Development Framework for the ESP32, ESP32-S, and ESP32-C line of SoCs is known as ESP-IDF. It offers an independent SDK for creating any type of generic application on various platforms using C and C++ programming languages.
We have a similar guide for Windows operating system:
Install Pre-requisites for ESP-IDF installation on Linux (Git)
The first step for installing ESP-IDF in our Linux Ubuntu system, is to fulfill all the necessary pre-requisites for the successful installation. We will first start by installing Git in our system. Open the following link: (https://git-scm.com/). The following web page will open:
Click “Downloads” highlighted below to select the download version according to your operating system.
In the Downloads page, click ‘Linux/Unix‘ as your operating system.
Here you can view the command that is required to get Git on our system. It is highlighted below:
Open the Terminal in your Linux Ubuntu system and write down the following command:
apt-get install git
You will be asked for your password. After entering the password, the Git will start installing on the system.
After a few moments, Git will get installed. Type the following command in the terminal to ensure the successful installation of Git on your system.
git --version
As you can see the in the picture below, the output shows that git version 2.34.1 in present in our system. Hence, all is well. Let us move to the next step.
Install ESP-IDF on Linux Ubuntu
Open the official ESP-IDF documentation. Open the following link: (https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/index.html). This opens the official ESP32 getting started webpage by Espressif. Scroll down until you reach the Manual Installation section. Here click ‘Linux and macOS.’
This will open the Standard Setup of Toolchain for Linux and macOS webpage. This webpage provides a detailed step by step method to install ESP-IDF. We will follow it.
Step 1 Install Prerequisites for Standard Toolchain Setup (Linux)
The first step here is to install all the necessary pre-requites. Copy the command for Ubuntu setup and paste it in the Terminal. This will install all the pre-requites with Python that are required.
sudo apt-get install git wget flex bison gperf python3 python3-venv cmake ninja-build ccache libffi-dev libssl-dev dfu-util libusb-1.0-0
Here is how the output looks like after the process completes.
Permission issues/dev/ttyUSB0
There is a common issue where the currently logged user does not have read and write access to the serial port over USB. To enable that, scroll down until you reach the following section of ‘Permission issues/dev/ttyUSB0‘. Click the link highlighted below to find the solution.
This link opens the page where there is information regarding establishing serial connection with ESP32 and PC. The command highlighted below is used to add the user to dialout on Linux.
Copy this command and paste it in the Terminal. Press enter. This will grant permission to the user to access the serial port.
sudo usermod -a -G dialout $USER
Now re-login to your PC to enable the changes to take place.
Step 2: Get ESP-IDF
After fulfilling the prerequisites, let us move to the next step.
Copy the following commands to the Terminal. Here we will first create a directory called ‘esp.’ Then we will navigate in that directory and do a git clone.
mkdir -p ~/esp
cd ~/esp
git clone --recursive https://github.com/espressif/esp-idf.git
Here is how the output looks like after the process completes.
Step 3: Set up the Tools
Now we are all ready to build the toolchain. Run the following command in the terminal.
cd ~/esp/esp-idf
./install.sh esp32
This is how the output looks like when the process completes. We have successfully installed the toolchain.
The next step is to import the environment variables that are required. Type the following command in the Terminal and press enter. This will enable the tools to be from the command line by setting some environment variables.
. ./export.sh
This is the output we obtain after the command is run. Here you can view that all the environment variables that we need have been loaded and it is ready to compile ESP-IDF projects.
Let us first look at this directory. Type the following command in theTerminal:
ls -al
You can find the examples directory present here
Opening the examples directory, we can see that there are various basic examples provided listed below.
cd examples/
ls -al
Let us open the get-started folder. Here you can view the hello_world example. Lets try to build that.
Build Hello World Example Sketch
To build the hello_world example project, first head over to the ~/esp directory as highlighted in the red box below. Then copy the hello_world project to that directory.
cd ~/esp
cp -r $IDF_PATH/examples/get-started/hello_world .
Enter the commands in the Terminal shown in the picture below, to build the hello_world project.
To build a project, use idf.py build command. This command will compile the application and all ESP-IDF components. Additionally it will also generate the bootloader, partition table, and application binaries.
idf.py build
This is how the output looks like showing a successful project build. We are now ready to flash our chip.
Where to go next?
- Getting Started with ESP32 using ESP-IDF
- ESP32 GPIO with ESP-IDF with LED Blinking example
- ESP32 Push Button with ESP-IDF (Digital Input)
- ESP32 ADC with ESP-IDF Measure Analog Inputs
- ESP32 PWM ESP-IDF LED Brightness Control Example
We are a team of experienced Embedded Software Developers with skills in developing Embedded Linux, RTOS, and IoT products from scratch to deployment with a demonstrated history of working in the embedded software industry. Contact us for your projects: admin@esp32tutorials.com