Programming Espressif ESP8266 and ESP32 microcontrollers
Here I describe how to program the microcontrollers Espressif ESP8266 and ESP32.
Programming the ESP8266
Development boards that are programmable via USB make life easier. One such board is the D1 mini which comes in different revisions (original, up to version 3) and feature different versions of the ESP8266MOD microcontroller. The AZ-Delivery D1 Mini ESP8266-Module, also called “D1 mini NodeMcu with ESP8266-12F” is an example.
Programming the ESP8266 using the Arduino IDE
Az-delivery.de provides instructions how to program the board via USB using the Arduino IDE in their D1 Mini NodeMcu eBook.
When using the Arduino IDE, the board definitions have to be installed using the Arduino IDE board manager:
- Open the Arduino IDE
- Select “File” -> “Preferences”
- Edit “Additional Boards Manager URLs” and add https://arduino.esp8266.com/stable/package_esp8266com_index.json to the comma-seperated list and click “OK”.
- Select “Tools” -> “Boards” -> “Boards Manager” and search for “esp8266” and install in “esp8266” by “ESP8266 Community”.
- Select “Tools” -> “Board” -> “Generic ESP8266 module”
- To program via USB using the Arduino bootloader, select “Tools” -> “Programmer” -> “avrISP mkII”
- Select “Tools” -> “Port” and select the port the D1 mini board is connected to.
- Follow https://arduino-esp8266.readthedocs.io/en/latest/mmu.html
- Select “Verify”
- Select “Upload”
Programming the ESP8266 using PlatformIO
- If your operating system is set up to delete the the contents of your
%USERPROFILE%
folder upon restart, edit the system environment variables: Add the system environment variablePLATFORMIO_CORE_DIR
and/or set it to the desired directory as described at https://docs.platformio.org/en/latest/envvars.html#directories. You may set it to any permanent directory with read- and write access. - Install Microsoft Visual Studio code and the PlatformIO IDE extension or download and unzip VSC_PlatformIO_Python391.zip from https://github.com/Jason2866/Portable_VSC_PlatformIO/releases
- Install the platform “Espressif 8266” for PlatformIO.
- Follow https://docs.platformio.org/en/stable/platforms/espressif8266.html and more specifically https://docs.platformio.org/en/latest/boards/espressif8266/d1_mini.html#board-espressif8266-d1-mini
To explicitely set internal DRAM size and internal cache size, specify build_flags according to https://docs.platformio.org/en/stable/platforms/espressif8266.html (Further details can be found at https://arduino-esp8266.readthedocs.io/en/latest/mmu.html. A typical platformio.ini file for an Arduino project could look like this:
[platformio]
default_env = mini_shared-release
[env:d1_mini]
platform = espressif8266
board = d1_mini
upload_protocol = esptool
framework = arduino
[env:d1_mini_shared-release]
extends = d1_mini
build_type = release
build_flags =
-D PIO_FRAMEWORK_ARDUINO_MMU_CUSTOM
-D MMU_IRAM_SIZE=0xC000
-D MMU_ICACHE_SIZE=0x4000
-D MMU_IRAM_HEAP
Examples can be found here:
- https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/soft-access-point-examples.html
- https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/examples/WiFiAccessPoint/WiFiAccessPoint.ino
- https://github.com/platformio/platform-espressif8266/tree/develop/examples/arduino-webserver
Programming the ESP32
The Espressif ESP32 DevKits are more capable boards featuring the ESP32 microcontrollers. The Az-delivery DevKitC V4 is an example.
Programming the ESP32 using the Arduino IDE
Az-delivery.de provides instructions how to program the board via USB using the Arduino IDE in their ESP32 Dev Kit C V4 eBook.
When using the Arduino IDE, the board definitions have to be installed using the Arduino IDE board manager:
- Open the Arduino IDE
- Select “File” -> “Preferences”
- Edit “Additional Boards Manager URLs” and add https://dl.espressif.com/dl/package_esp32_index.json to the comma-seperated list and click “OK”.
- Select “Tools” -> “Boards” -> “Boards Manager” and search for “esp32” and install in “esp32” by “Espressif Systems”.
- Select “Tools” -> “Board” -> “ESP32 Dev Module”
- To program via USB using the Arduino bootloader, select “Tools” -> “Programmer” -> “avrISP mkII”
- Select “Tools” -> “Port” and select the port the D1 mini board is connected to.
- Select “Verify”
- Select “Upload”
Programming the ESP32 using PlatformIO
- If your operating system is set up to delete the the contents of your
%USERPROFILE%
folder upon restart, edit the system environment variables: Add the system environment variablePLATFORMIO_CORE_DIR
and/or set it to the desired directory as described at https://docs.platformio.org/en/latest/envvars.html#directories. You may set it to any permanent directory with read- and write access. - Install Microsoft Visual Studio code and the PlatformIO IDE extension or download and unzip VSC_PlatformIO_Python391.zip from https://github.com/Jason2866/Portable_VSC_PlatformIO/releases
- Install the platform “Espressif 32” for PlatformIO.
- Follow https://docs.platformio.org/en/latest/platforms/espressif32.html and more specifically https://docs.platformio.org/en/latest/boards/espressif32/az-delivery-devkit-v4.html
Accordingly, a typical platformio.ini for an Arduino project would be
[platformio]
default_envs = devkit-v4-release
[env:az-delivery-devkit-v4]
platform = espressif32
board = az-delivery-devkit-v4
framework = arduino
[env:devkit-v4-release]
extends = az-delivery-devkit-v4
build_type = release
A typical platformio.ini for a C99 project using the Espressif 32 platform and the ESP-IDF framework could look like this:
[platformio]
default_envs = devkit-v4-release
[env:az-delivery-devkit-v4]
platform = espressif32
board = az-delivery-devkit-v4
framework = espidf
[env:devkit-v4-release]
extends = az-delivery-devkit-v4
build_type = release
Example projects can be found here:
- https://github.com/platformio/platform-espressif32/tree/develop/examples/espidf-blink
- https://docs.platformio.org/en/latest/tutorials/espressif32/espidf_debugging_unit_testing_analysis.html
- https://github.com/espressif/esp-idf/tree/master/examples/wifi/getting_started/softAP
- https://github.com/espressif/arduino-esp32/blob/master/libraries/WiFi/examples/WiFiAccessPoint/WiFiAccessPoint.ino
Copyright 2022 ITlernpfad