Introduction to ESP32 Programming Using ESP-IDF & Arduino Framework
$ whoami Alwin Arrasyid Software Engineer, DycodeX winter@dycode.com twitter.com/alwin_wint3r github.com/alwint3r
ESP32
CPU: Tensilica Xtensa 32-bit dual core, up to 240 MHz, 600 DMIPS. Operating voltage: 3.3V Memory: 448 KB ROM, 520 KB SRAM 16 KB SRAM in RTC, 1 Kbit of eFuse. External Flash: 512 KB to (4 x 16) MiB WiFi (802.11): b/g/n/e/i Bluetooth: v4.2 BR/EDR & BLE Peripherals: GPIOs, PWM, ADC, DAC, I2S, UART, SPI, I2C, CAN, RMII, Cap Touch
ESP8266 vs ESP32
ESP32 Modules
ESP32 Boards
ESP32 Boards
ESP-IDF ESP32 Development Platforms
ESP32 Development Tools / IDE
Our Focus ESP-IDF
What is ESP-IDF? ESP IoT Development Framework or abbreviated as ESP-IDF is the official development framework for ESP32. source code: https://github.com/espressif/esp-idf documentation: http://esp-idf.readthedocs.io
ESP-IDF is built with these languages
Let's get started!
Installation Steps • Download required software packages (OS specific) • Download & setup xtensa-esp32 toolchain • Download & setup ESP-IDF
Prerequisites - GNU/Linux (Debian-based) git wget make libncurses-dev flex bison gperf python python-serial Install the following packages using the package manager
Prerequisites - macOS sudo easy_install pip Install pip, package manager for python sudo pip install pyserial Install pyserial using pip
Toolchain Setup - GNU/Linux (Debian-based) https://dl.espressif.com/dl/xtensa-esp32-elf-linux32-1.22.0-61-gab8375a-5.2.0.tar.gz Toolchain for 32 bit system https://dl.espressif.com/dl/xtensa-esp32-elf-linux64-1.22.0-61-gab8375a-5.2.0.tar.gz Toolchain for 64 bit system
Toolchain Setup - GNU/Linux (Debian-based) $ mkdir -p ~/esp $ cd ~/esp $ tar -xzf ~/Downloads/xtensa-esp32-elf-linux64-1.22.0-61-gab8375a- 5.2.0.tar.gz Download & extract the toolchain to the ~/esp directory.
Toolchain Setup - GNU/Linux (Debian-based) $ export PATH=$PATH:$HOME/esp/xtensa-esp32-elf/bin "Introduce" the toolchain so the system knows they're there. You can also append above line to the .bashrc, .profile, or .bash_profile, so you only need to do this only once.
Toolchain Setup - macOS https://dl.espressif.com/dl/xtensa-esp32-elf-osx-1.22.0-61-gab8375a-5.2.0.tar.gz The steps are pretty much the same with the previous one. Only the filename & URL of the toolchain that is different with the GNU/Linux.
Toolchain Setup - Windows https://dl.espressif.com/dl/esp32_win32_msys2_environment_and_toolchain-20170330.zip You only need to download the toolchain + msys2 environment from this URL & extract the archive to C: drive. Open msys2 terminal & create esp directory inside home folder. $ mkdir -p ~/esp
ESP-IDF Setup $ cd ~/esp $ git clone -- recursive https://github.com/espressif/esp-idf.git Clone the esp-idf repository.
ESP-IDF Setup - GNU/Linux & macOS $ export IDF_PATH=$HOME/esp/esp-idf Set a new environment variable with the path to ESP-IDF directory as its value. It is recommended to append above line to the .bashrc, .profile, or .bash_profile, so you only need to do this only once.
ESP-IDF Setup - Windows $ touch /etc/profile.d/export_idf_path.sh Create a user script file inside the C:/msys32/etc/profile.d/ directory. We'll call it export_idf_path.sh. Export the ESP-IDF path $ echo export IDF_PATH=C:/msys32/home/user-name/esp/esp-idf >> /etc/profile.d/export_idf_path.sh
Complete installation guide: esp-idf.readthedocs.io/en/latest/get-started
Hello World
Hello World ~/esp/esp-idf/examples/get-started/hello_world Copied from examples provided by ESP-IDF.
├── main │ ├── component.mk │ └── hello_world_main.c ├── Makefile └── README.md Project Tree
Build & Flash the Firmware We need to configure the project first. The configuration includes the serial port of the ESP32 board, the baud rate, and so many more! $ make menuconfig
Build & Flash the Firmware $ make -j3 $ make flash $ make monitor $ make -j3 flash monitor Or even better, a one liner!
ESP-IDF Component
ESP-IDF Component • Has a C/C++ source & header files • Has a component.mk file • Optionally has Kconfig (configuration) file
component_name ├── component.mk ├── component_source.c ├── include │ └── component_source.h └── Kconfig ESP-IDF Component Anatomy
component_name ├── component.mk ├── Kconfig ├── component_source.h └── component_source.c ESP-IDF Component Anatomy
Another Demo
Using Arduino for ESP32
Using Arduino for ESP32 • Arduino is still the preferred choice among makers • Huge community • Easier to get started with
Using Arduino for ESP32 - Trade-off! • Lose control of the configurations & low level stuff
Arduino for ESP32 Demo
Choose one! ESP-IDF or Arduino?
ESP-IDF + = as component
Proof, please!
Moar demo!
Where to go from here?
ESP32 Learning Resources • Official documentation esp-idf.readthedocs.io • ESP-IDF examples code github.com/espressif/esp-idf/tree/master/examples • Technical Book (Free!) leanpub.com/kolban-ESP32 • Really useful snippets github.com/nkolban/esp32-snippets • ESP32 forum esp32.com
Code shown during this session: github.com/alwint3r/RTR_Surabaya2017
Thank you!

Introduction to ESP32 Programming [Road to RIoT 2017]