How To Get Started — ESP_IDF_Series Episode #00
Note
This tutorial uses the Legacy GNU Make Build System and MSYS2 Unix compatibility environment to build projects of ESP-IDF. This is no longer required, ESP-IDF can be used from the Windows Command Prompt.
Edited [main, 2024]: ESP-IDF v5.0 no longer supports GNU make-based projects. Please follow the build system guide for migration.
For a new one build system, using CMake + Ninja, please use this post:)
In this tutorial, we will be dealing with the installation of the EXPRESSIF ESP-IDF toolchain & ESP_IDF for Windows. This is a GNU Make based build system.Please access this link for official instructions (choose your platform: Windows, Linux or Mac OS)https://my-esp-idf.readthedocs.io/en/latest/get-started/index.html
Let’s get it on!
Radio operates like this: you send signals here, they receive them there.
Sending data over long distances is like magic.
Most WiFi, Bluetooth, Zigbee, and other wireless radios chipsets use 2.4GHz, which is great for high-speed transfers.
If you aren’t so concerned about streaming a video, you can use a lower license-free frequency such as 433 or 900 MHz. You can’t send data as fast but you can send data a lot farther. And here is where LoRa Radios shine up!
LoRa radios can operate at a frequency of 33 MHz, 868 MHz (Europe), 915 MHz (Australia and South/North America), and 923 MHz (Asia).
The LoRa radios are exciting and more powerful but also a bit more expensive($20 — $30) compared to The RFM69’s. But not so much like Zigbee ($60-$100).
LoRa packet radios can easily go 2 Km line of sight using simple wire antennas, or up to 20Km with directional antennas and settings tweaking.
This is WiFi LoRa 32 (v2):
This is the 900 MHz radio version, which can be used for either 868MHz or 915MHz transmission/reception — the exact radio frequency is determined when you load the software since it can be tuned around dynamically.
For us, hobbyists, there are 2 ESP32 development options available, via: 1 - Arduino environment, which I already posted here;2 - or an amazing native ec·o·sys·tem: ESP-IDF Toolchain (this very own post).Here we will be dealing with the most powerfull method: ESP-IDF from ESPRESSIF. The native software development framework for the ESP-32 is called the ESPRESSIF IoT Development Framework (ESP-IDF).
The quickest way to start development with ESP-IDF is by installing a prebuilt toolchain.
Here is a step-by-step procedure for Windows users:
01#Step — Download the Windows all-in-one toolchain & MSYS2 zip file from dl.espressif.com (about 710 MB — it takes five minutes @ 50MB internet):
https://dl.espressif.com/dl/esp32_win32_msys2_environment_and_toolchain_idf3-20200601.zip
02#Step — Unzip it in your C:/ driver directory and files will end up in the 👆MSYS32👆 directory;
03#Step — Open an MSYS2 MINGW32 terminal window by running this app: C:\msys32\mingw32.exe
This is a bash shell.
04#Step — Inside the shell, Make a directory named esp, like this:
mkdir -p ~/esp
05#Step — Now access this folder:
cd ~/esp
06#Step —Now get SDK-IDF version 3.3.2, type:
git clone -b v3.3.2 --recursive https://github.com/espressif/esp-idf.git
This process will take ~20' and it’ll cloning important API component, like:
esptool_py/esptool (prog to compile and upload hex into the chip);
json/cJSON (transform JSON);
lwip/lwip (Famous Socket library);
tinyusb/tinyusb (Driver USB);
lib/tinyxml2(XML manipulations);
mbedtls/mbedtls (TTL/SSL Library);
mqtt/esp-mqtt(MQTT Protocol)and others.
07#Step — Setup Path to IDF_PATH — Create a new script file in C:/msys32/etc/profile.d/
directory. Name it export_idf_path.sh
;
The toolchain programs access ESP-IDF using an environment variable. This variable should be set up on your PC, otherwise, projects will not build. To set up it permanently by defining IDF_PATH
in the user profile.
The user profile scripts are contained in C:/msys32/etc/profile.d/
directory. They are executed every time you open an MSYS2 window. Let’s do that:
08#Step — Add the export
command to the script file, e.g.:
At C:/msys32/etc/profile.d/ directory, type:
vim export_idf_path.sh
Then paste:
export IDF_PATH="C:/msys32/home/user-name/esp/esp-idf"
As an example, this is my path:
And finally, type:
<ESC>, :wq, <ENTER>
and you are #GOODTOGO:)\o/
Here are some tips to help you out:
C:/msys32/etc/profile.d/ directory
Note: Remember this is a Linux terminal window. You can type it as a normal Windows path, but use forward-slashes instead of back-slashes:)
But there is a much, much easier method:
Simply in your Windows Explorer directory C:\mysys32\etc\profile.d
copy & paste another file as a template, rename it to export_idf_path.sh
and open it at Notepad++ app, edit it, and paste this:
export IDF_PATH="C:/msys32/home/giljr/esp/esp-idf"
And save it:
And You are #GOODTOGOTOO:)\o/
09#Step — Now to test the environment, close the MSYS2 MINGW32 terminal shell, and open it again (I reinitiate my machine, just in case;)
Now type:
printenv IDF_PATH
10# Step — Install the Required Python Packages;
Python packages required by ESP-IDF are located in the $IDF_PATH/requirements.txt
file. You can install them in this Linux env by running:
python -m pip install --user -r $IDF_PATH/requirements.txt
If your system complains about updating pip, type:/
python -m pip install --upgrade pip
Then, run again:
python -m pip install --user -r $IDF_PATH/requirements.txt
Start a Project
Now you are ready to prepare your application for ESP32. To start off quickly, we will use a get-started/hello_world project from the examples directory in IDF.
Copy get-started/hello_world to ~/esp
the directory:
cd ~/esp
cp -r $IDF_PATH/examples/get-started/hello_world
You can also find a range of example projects under the examples directory in ESP-IDF. These example project directories can be copied in the same way as presented above, to begin your own projects.
Connect
You are almost there. To be able to proceed further, connect the ESP32 board to the PC, check under what serial port the board is visible, and verify if serial communication works. If you are not sure how to do it, check the instructions in section Establish Serial Connection with ESP32. Note the port number, as it will be required in the next step.
Configure
Being in a terminal window, go to the directory of hello_world
the application by typing cd ~/esp/hello_world
. Then start project configuration utility menuconfig
:
cd ~/esp/hello_world
make menuconfig
If previous steps have been done correctly, the following menu will be displayed:
In the menu, navigate to Serial flasher config
> Default serial port
to configure the serial port (mine is COM10), where the project will be loaded to. Confirm the selection by pressing enter, save the configuration by selecting<Save>
and then exit the application by selecting <Exit>
.
Output
Now go to your sys_config.h file at C:\msys32\home\giljr\esp\esp-idf\examples\get-started\hello_world and modify these entries:
copy the path access it
Save the project, now type:
make -j5 flash monitor
I (212) cpu_start: App cpu up.I (238) heap_init: Initializing. RAM available for dynamic allocation:I (245) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAMI (251) heap_init: At 3FFB2EE0 len 0002D120 (180 KiB): DRAMI (257) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAMI (263) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAMI (270) heap_init: At 40088470 len 00017B90 (94 KiB): IRAMI (276) cpu_start: Pro cpu start user codeI (294) cpu_start: Starting scheduler on PRO CPU.I (0) cpu_start: Starting scheduler on APP CPU.Hello world!This is ESP32 chip with 2 CPU cores, WiFi/BT/BLE, silicon revision 1, 8MB external flashRestarting 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:57rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)configsip: 0, SPIWP:0xeeclk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00mode:DIO, clock div:2load:0x3fff0018,len:4load:0x3fff001c,len:6784ho 0 tail 12 room 4load:0x40078000,len:12072ho 0 tail 12 room 4load:0x40080400,l
...
What happens here is that the HelloWorld program simply reset your device via software…nothing fancy, right?
Now If you got here, congratulations!
Your ESP-IDF IS READY FOR YOUR PROJECTS!
That’s all for now, In the next episode let’s talk about ESP-IDF and Semtech’s LoRa radio ;)
See you soon!
Bye!
Notes
.Troubleshooting — Driver Bridge(see below, right below...).What is MSYS2? (https://www.msys2.org/)MSYS2 is a software distro and building platform for Windows.It features a package management system, Pacman, to provide easy installation of packages. It brings many powerful features such as dependency resolution and simple complete system upgrades, as well as straight-forward package building.Please, Update the package database and core system packages with:pacman -Syu. On Windows, while executing C:\msys32\mingw32.exe remember to execute it all as an administrator privileges :)
Related Post
Related Post
00#Episode — ESP_IDF_Series — ESP-IDF Programming Guide + WiFi LoRa 32 (v2) — How To Get Started (this one:)
01#Episode — ESP_IDF_Series — LoRa LPWAN — Long Range Low Power Wide Area Network — LoRa was developed by Semtech, founder LoRa Alliance
02#Episode — ESP_IDF_Series — ESP-IDF Programming Guide + WiFi LoRa 32 (v2) + idf.py utility — How To Really Get Started
03#Episode — ESP_IDF_Series — ESP32-IDF — HelloWorld Get Started — How To Get Started
05 #Episode FreeRTOS — A Real Real-Time TV Transmissions — Fundamental Understanding about FreeRTOS Apps — IoT
Credits & References
Microgênios — Treinamento em Sistemas Embarcados — Microchip Regional Partner certified Training Courses a Simplício-owned enterprise
https://my-esp-idf.readthedocs.io/en/latest/get-started/index.html
Troubleshooting — Driver Bridge
If the driver is installed previously, a COM port will be allotted as soon as you plug your ESP32 kit (mine is WiFi LoRa 32 V2). Otherwise, download the silicon labs cp2102 driver from here & install it with this utility Program CH341SER.EXE on your PC. Everything will be allright o/
If it didn’t help, please access this page: Establish Serial Connection with ESP32.
Edited @ Dez/2020 — downloads updates, text complementation, minor typos corrections:)