ESP8266 and ESP32 are popular WiFi development solutions that can be programmed in several ways using different programming languages. Common languages include MicroPython, C, JavaScript, and LUA script. The choice of embedded firmware and software tools makes it possible to program ESP8266 and ESP32 in different languages.
The versatility and flexibility to program ESP boards with different firmware, programming languages, and software tools make these boards so popular. The variety of firmware and programming languages also facilitate different levels of software features, community support, modules, and tools.
Embedded software developers with different programming backgrounds can choose their preferred firmware and programming language to develop IoT projects with ESP8266. (Learn more about programming ESP boards here).
A common way to program ESP8266 and ESP32 is using embedded C via Arduino IDE or Visual Studio Code. An advantage of being Arduino-compatible means there are many ready-to-use libraries and community-contributed source codes to reuse on ESP boards. It’s also fast because it’s unnecessary to write the code from scratch to interface most components, and many programming tasks are readily resolved.
Let’s get started programming ESP boards via Arduino IDE.
ESP8266 vs. ESP32
ESP8266 and ESP32 are development boards from the same family. ESP32 is the successor to ESP8266 and superior to ESP8266 in several respects. However, both boards have a 32-bit controller and run on an operating voltage of 3.3V (compared to Arduino’s 5V). They also both lack hardware PWM.
Here are the differences:
ESP8266 has…
- A single-core Xtensa 32-bit L106 running on 80 MHz clock
- WiFi only
- A 20MHz channel for WiFi (HT20)
- Two SPI ports, 1 I2C, 2I2S, and 2 UART ports
- 17 GPIO
- A single 10-bit ADC
- Eight software PWM channels
ESP32 has…
- A dual-core Xtensa 32-bit LX6 running on 160~240 MHz
- High-speed WiFi and Bluetooth, including 4.2 and Low Energy
- A 40 MHz channel for WiFi (HT40)
- Touch-sensitive pins and a built-in hall sensor that wake it up from a deep sleep
- 512 bytes of flash memory and 512Kb of SRAM
- CAN 2.0 interface, Ethernet MAC interface, and touch and hall effect sensor
- 34 GPIO
- GPIOs are multiplexed with SPI, I2C, and UART (if a function is not set in code, the pins default to GPIO).
- 18 analog-enabled pins with a 12-bit ADC channel on each pin
- 16 software PWM channels
Despite the differences between the two boards, Arduino IDE works nearly identically with either one. As ESP8266 is older than ESP32, it offers greater library support though it’s not difficult to get most libraries to work with ESP32. It’s more powerful and versatile.
ESP8266 versions
ESP8266 and ESP32 can be standalone modules or breakout boards with additional chips and interfaces. Typically, they’re used as breakout boards for designing embedded applications and rarely as bare chips.
Many ESP8266 breakout boards fall into two categories: development boards with a USB interface or without a USB interface. Several standalone modules are available in the ESP-NN (ESP01 to ESP14) series from AI-Thinkers vendor. Another standalone module is ESP-WROOM-02 from Espressif. Others vendors include Wireless-tag, Olimex, Smarttime, and Qilianer.
The standalone modules serve as Wi-Fi adaptors or Wi-Fi-enabled microcontroller development boards. The modules vary in size, pins broken out, exposed on-chip features, antenna type, and flash memory.
A bare-bones ESP8266 SoC requires an external flash memory, reset and program circuitry, chip enabling circuitry, a 3.3 voltage regulator power supply, and a USB-to-Serial adapter. The required features may be on-board in a module or provided externally.
The ESP8266-based development boards are equipped with all the required circuitry with or without a USB interface for programming. Some popular ESP8266 development boards are available from Adafruit, SparkFun, NodeMCU, and AI Thinkers.
The ESP8266 categories…
1. Development boards with USB interface: have a USB interface for programming with all the required circuitry, requiring no external circuit for setup (at most, one may need to solder header pins). Examples include SparkFun ESP8266 Thing, Adafruit Feather HUZZA, SparkFun Blynk Board, and certain AI Thinker ESP-NN boards.
When these boards are connected to a desktop computer via a USB cable, they appear in a Windows PC’s device manager on a Linux System’s lsusb. They have a 3.3V regulator and can be programmed directly via the USB interface.
2. Development boards without USB interface: require a USB-to-Serial adaptor for programming and an external circuit for enabling the chip and adding reset and programming buttons. Some boards have an onboard 3.3V regulator, but not all of them.
The ESP-12E or ESP-12E NodeMCU kit is the most popular ESP8266 breakout board.
ESP8266 pinout
ESP-01, ESP8266-12E NodeMCU kit, and Wemos D1 Mini are commonly used ESP8266 breakout boards.
The ESP-01 has the following pin diagram…
The ESP8266-12E NodeMCU kit has this pin diagram…
Wemos D1 Mini has the following pin diagram…
ESP32 boards
Commonly used ESP32 breakout boards include ESP32 DevKit, ESP32 DOIT DEVKIT V1, ESP32 Thing, HUZZAH32, ESP-32S NodeMCU, WEMOS OLED, and WEMOS LOLIN32.
ESP32 pinout
ESP32 DOIT DEVKIT V1 is currently the most popular ESP32 board. It comes in two versions, one with 30 pins and the other with 36 pins.
The 30-pin version has this pin diagram…
The 36-pin version has the following pin diagram…
Installing Arduino IDE
Arduino IDE can be downloaded from here. Arduino IDE 2.0.0 is the latest version. The legacy version Arduino IDE 1.8.19 can also be installed based on your preference. Complete the installation process as per the instructions.
Installing ESP32 add-on in Arduino IDE
ESP-32 is the most recommended ESP board to explore. ESP-32 has a powerful processor and better clock speed. It offers WiFi and Bluetooth and has more GPIOs and peripherals than ESP8266.
To work with ESP32 in Arduino IDE, install its add-on. Navigate to File->Preferences.
Add the following URL to the “Additional Board Manager URLs” field.
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
or
https://dl.espressif.com/dl/package_esp32_index.json
Click OK. Next, navigate to Tools->Board->Board Manager.
Search for ESP32 and install it from Expressif.
That’s all. The ESP32 add-on will install on Arduino IDE within seconds.
Installing ESP8266 add-on in Arduino IDE
ESP8266 is recommended for many IoT and smart home projects. Typically, ESP8266 is sufficient if a project only requires WiFi networking and does not involve many time-critical embedded tasks. As ESP8266 costs almost half of ESP32, the production of a prototype on ESP8266 could be lot more cost effective than on ESP32.
To install the ESP8266 add-on in Arduino IDE, navigate to File->Preferences. Add the following URL to the “Additional Board Manager URLs” field.
http://arduino.esp8266.com/stable/package_esp8266com_index.json
You can add support for both ESP32 and ESP8266 by adding a comma separated list of URLs as follows…
http://arduino.esp8266.com/stable/package_esp8266com_index.json, https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
or
http://arduino.esp8266.com/stable/package_esp8266com_index.json, https://dl.espressif.com/dl/package_esp32_index.json
Click OK. Next, navigate to Tools->Board->Board Manager. Search for ESP8266 and install it via the ESP8266 Community.
That’s all. ESP8266 add-on will install in few seconds on Arduino IDE.
Testing installation on ESP8266
To test installation on ESP8266, you can use the ESP-12E NodeMCU Kit and connect it with computer via a Micro-USB cable. Navigate to Tools->Board->ESP8266 boards. Select NodeMCU 1.0 or NodeMCU 0.9 according to your ESP12 board.
Next, select the port by navigating to Tools->Port. Copy and paste the following code in code editor…
int pin = 2;
void setup() {
pinMode(pin, OUTPUT);
}
void loop() {
digitalWrite(pin, HIGH);
delay(1000);
digitalWrite(pin, LOW);
delay(1000);
}
Click the “Upload” button and wait until the message “Done uploading” shows in the bottom left corner. If the code is successfully uploaded, the LED on ESP8266 board will start blinking.
Testing installation on ESP32
To test ESP32 on Arduino IDE, connect the board with your computer via a Micro-USB cable. Navigate to Tools-Board->ESP32 Arduino. Select DOIT ESP32 DEVKIT V1 or your specific ESP32 board.
Next, select the port.
Open an example sketch by navigating File->Examples->WiFi->WiFiScan. The sketch will open in a new window. Press the upload button and wait for the code to compile and upload.
Open the Arduino IDE Serial Monitor at a baud rate of 115200 bps. If the sketch is successfully uploaded, you will see a similar scan result on the Serial Monitor.
Troubleshooting
When uploading the sketch to ESP8266 or ESP32, you might encounter an error message like “esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header” or “A fatal error occurred: Failed to connect to ESP32: Timed out… Connecting…”.
Either message means that ESP8266/ESP32 is not in the proper flashing or uploading mode. To resolve this, hold down the boot/flash button on ESP8266/ESP32 after selecting the board and port, then press the upload button in the Arduino IDE to upload the sketch.
Once you see a message “Connecting…” in the Arduino IDE, release the boot/flash button on ESP8266/ESP32. After the sketch is successfully uploaded to ESP8266/ESP32, press the enable button on ESP8266/ESP32. This will restart the ESP8266/ESP32 board and run the uploaded sketch.
This must be repeated every time a new sketch is uploaded to ESP8266 or ESP32. Repeating this troubleshooting measure can be avoided in ESP32 by hacking the board. ESP32 can be made to go into the flashing/uploading mode automatically.
To do this, you must connect a 10 uF electrolyte capacitor between the enable pin and the ground. Since the enable and GND pins are far apart on the breakout board, the capacitor can be connected between ESP32 chip’s enable pin and the ground as shown in the image below.
You can test the setup on the breadboard first before soldering the capacitor on the board as shown below.
Ensure the capacitor is soldered only to the chip’s enable pin and the ground. It should not solder to anything next to these pins. Once complete, you will not need to hold the boot/flash button on the board when uploading any sketches to ESP32. ESP32 will automatically flash and upload.
You may also like:
Filed Under: Electronic Projects, ESP8266
Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.