[ESP32 most complete study notes (basic articles) - 1. Introduction to ESP32]

          New to ESP32? Start here!

About this tutorial:

ESP32 Basics                                

1. Introduction to ESP32☑                                                                 

2. ESP32 Arduino Integrated Development Environment

3.ESP32 Arduino IDE 2.0

4. VS Code and PlatformIO

5. ESP32 pinout

6. ESP32 input and output

7.ESP32 Pulse Width Modulation

8. ESP32 analog input

9. ESP32 interrupt timer

10. ESP32 deep sleep

ESP32 Protocol

ESP32 web server

ESP32 LoRa

ESP32 BLE

ESP32 BLE Client-Server

ESP32 Bluetooth

ESP32 MQTT

ESP32 ESP-NOW

ESP32 Wi-Fi

ESP32 WebSocket

ESP32 ESP-MESH

ESP32 mailbox

ESP32 SMS

ESP32 HTTP get POST

HTTP GET Web APIs

HTTP POST Web APIs

 ESP32 server articles

Keep updating, follow bloggers and don't get lost! ! !

 ESP32 Sensor Module

Keep updating, follow bloggers and don't get lost! ! !

ESP32 Ultimate Combat

More than 100 ESP32 practical projects, please pay attention! ! !

        The ESP32 is a family of low-cost, low-power System-on-Chip (SoC) microcontrollers developed by Espressif that include Wi-Fi and Bluetooth wireless capabilities and a dual-core processor. If you're familiar with the ESP8266, the ESP32 is its successor, loaded with many new features.

        New to ESP32? You have come to the right place. This guide contains all the information you need to get started with the ESP32. Learn what an ESP32 is, how to choose an ESP32 development board, how to get your first program running, and more. Here's what we'll cover in this guide: 

Table of contents

Introduction to ESP32

        ■ ESP32 specification

        ■ ESP32 and ESP8266

■ ESP32 development board

        ■ How to choose ESP32 development board?

        ■ What is the best ESP32 development board for beginners

■ ESP32 development kit DOIT

■ ESP32GPIO Pin Guide

■ How to program ESP32?

■ ESP32 and Arduino IDE

■ Use Arduino IDE to upload code to ESP32

Introduction to ESP32

First things first, what is an ESP32 ? ESP32 is a series of chip microcontrollers independently developed by Espressif.

Why are they so popular? Mainly because of the following characteristics:

Low cost : You can buy ESP32 starting from $6, which makes it easily accessible to the general public;
Low power consumption : Compared to other microcontrollers, ESP32 consumes very little power and supports low-power mode states such as deep sleep , to save power;
Wi-Fi function : ESP32 can easily connect to a Wi-Fi network to connect to the Internet (station mode), or create its own Wi-Fi wireless network (access point mode) so that other devices can connect to it - This is essential for IoT and home automation projects - you can have multiple devices communicate with each other using their Wi-Fi capabilities;
Bluetooth : ESP32 supports Classic Bluetooth and Bluetooth Low Energy (BLE) - applicable for a variety of IoT applications;
Dual-core : Most ESP32s are dual-core—they have 2 Xtensa 32-bit LX6 microprocessors: core 0 and core 1. Rich peripheral input/output interfaces - ESP32 supports capacitive touch, ADC, DAC, UART, SPI, I2C and other input (reading data from the outside world) and output (sending commands/signals to the outside world) peripherals,
pulse wide modulation, etc. Compatible with Arduino "programming language" : Those who are already familiar with programming Arduino boards, you will be happy to know that they can program ESP32 in Arduino style.

Compatible with MicroPython : You can program the ESP32 with the MicroPython firmware, which is a reimplementation of Python 3 for microcontrollers and embedded systems.

ESP32 Specifications

If you want to know more technical and specific information, you can check out the detailed specifications of the ESP32 below (source: http://esp32.net/ - check the datasheet for more details ) :

 Wireless Connections WiFi: HT40 at 150.0 Mbps data rate
Bluetooth: BLE (Bluetooth Low Energy) and Bluetooth Classic
Processor: Tensilica Xtensa dual-core 32-bit LX6 microprocessor running at 160 or 240 MHz
Memory:
ROM: 448 KB (with for boot and core functions)
SRAM: 520 KB (for data and instructions)
RTC fas SRAM: 8 KB (for data storage and main CPU during RTC startup from deep-sleep mode)
RTC slow SRAM: 8KB (for deep Coprocessor access in sleep mode)
eFuse: 1 Kbit (of which 256 bits are used for the system (MAC address and chip configuration), and the remaining 768 bits are reserved for customer applications, including Flash-Encryption and Chip-ID) Embedded Flash:
ESP32 - Flash internally connected via IO16, IO17, SD_CMD, SD_CLK, SD_DATA_0 and SD_DATA_1 on D2WD and ESP32-PICO-D4.
0 MiB (ESP32-D0WDQ6, ESP32-D0WD and ESP32-S0WD chips)
2 MiB (ESP32-D2WD chip)
4 MiB (ESP32-PICO-D4 SiP module)
Low power consumption: Make sure you can still use ADC conversions, e.g. During deep sleep.
Peripheral I/O:
Peripheral interface with DMA, including capacitive touch
ADC (Analog to Digital Converter)
DAC (Digital to Analog Converter)
I²C (Inter-Integrated Circuit)
UART (Universal Asynchronous Receiver/Transmitter)
SPI (Serial Peripheral Interface)
I²S (Sound Integrated Chip Interconnect)
RMII (Reduced Media Independent Interface)
PWM (Pulse Width Modulation)
Security: AES and SSL Hardware Accelerator for /TLS

 The main difference between ESP32 and ESP8266

         Earlier, we mentioned that ESP32 is the successor of ESP8266. What are the main differences between ESP32 and ESP8266 boards?

        ESP32 adds extra CPU cores, faster Wi-Fi, more GPIOs, and support for Bluetooth 4.2 and Bluetooth Low Energy. Additionally, the ESP32 has a touch-sensitive pin that can be used to wake the ESP32 from deep sleep, as well as a built-in Hall effect sensor.

So, to summarize:

  • ESP32 is faster than ESP8266;
  • ESP32 comes with more full-featured GPIO;
  • ESP32 supports analog measurement of 18 channels (analog enable pin), while ESP8266 only supports one 10-bit ADC pin;
  • ESP32 supports Bluetooth, but ESP8266 does not;
  • ESP32 is dual-core (most models), ESP8266 is single-core;
  • ESP32 is a bit more expensive than ESP8266.

        For a more detailed analysis of the differences between these boards, we recommend reading the following article: ESP32 vs. ESP8266 – Pros and Cons.

ESP32 development board

        ESP32 refers to the ESP32 bare chip. However, the term "ESP32" is also used to refer to the ESP32 development board. Working with an ESP32 bare chip is not easy or practical, especially when it comes to learning, testing, and prototyping. Most of the time, you'll want to use an ESP32 development board.

        These development boards come with all the circuitry needed to power and program the chip, connect it to your computer, pins to connect peripherals, built-in power and control LEDs, antennas for wi-fi signals, and other useful features. Others even come with additional hardware, such as specific sensors or modules, displays, or cameras for the ESP32-CAM.

How to choose an ESP32 development board?

        Once you start searching online for ESP32 development boards, you'll find a wide variety of them from different suppliers. While they all work in a similar way, some boards may be better suited for certain projects than others. When looking for an ESP32 development board, there are a few things you need to consider:

  • USB to UART interface and voltage regulator circuit . Most full-featured development boards have both of these features. This is very important to easily connect the ESP32 to your computer for uploading code and powering up.
  • The BOOT and RESET/EN buttons put the board in flash mode or reset (restart) the board. Some boards do not have a BOOT button. Normally, these boards automatically go into flashing mode.
  • pin configuration and pin count. To properly use the ESP32 in your projects, you need to have access to the board pinout (like a map showing which pin goes to which GPIO and what it does). So make sure you have access to the pinouts of the board you get. Otherwise, you may end up using the ESP32 incorrectly.
  • Antenna connector . Most development boards have an onboard antenna for the Wi-Fi signal. Some boards have antenna connectors that optionally allow connection of an external antenna. Adding an external antenna increases your Wi-Fi coverage.
  • battery connector . If you want to use batteries to power the ESP32, you can use a development board with a LiPo battery connector - it's more convenient. You can also power a "regular" ESP32 from a battery via the power pin.
  • Additional hardware features . There are ESP32 development boards with additional hardware capabilities. For example, some may have built-in OLED displays, LoRa modules, SIM800 modules (for GSM and GPRS), battery holders, cameras, etc.

What are the best ESP32 development boards for beginners?

        For starters, we recommend the ESP32 development board, which has a large number of GPIOs available and doesn't have any extra hardware features. Just as importantly, it comes with regular voltage and a USB input for powering and uploading code.

        In most of our ESP32 projects, we use the ESP32 DEVKIT DOIT development board, which is our recommended development board for beginners. There are different versions of this board with different numbers of pins available (30, 36 and 38) - all work similarly.

ESP32 development kit DOIT

In this article, we will use the ESP32 DEVKIT DOIT development board as a reference. Don't worry if you have a different board. The information on this page also applies to other ESP32 development boards.

The figure below shows the ESP32 DEVKIT DOIT V1 development board, the version with 36 GPIO pins.

Specifications – ESP32 DEVKIT V1 DOIT

The table below summarizes the features and specifications of the ESP32 DEVKIT V1 DOIT development board:

        This particular ESP32 board has 36 pins, 18 on each side. The number of GPIOs available depends on your board model.

        To learn more about ESP32 GPIOs, read our GPIO reference guide:  ESP32 Pin Reference: Which GPIO Pins Should You Use?

 

        It has a microUSB connector that you can use to connect the board to your computer to upload code or power on.

        It uses a CP2102 chip (USB to UART) to communicate with your computer using a serial interface through a COM port. Another popular chip is the CH340. Check what the USB to UART chip converter is on the board, as you'll need to install the required drivers so your computer can communicate with the board (more on that later in this guide).

        The board also has a RESET button (probably labeled EN) to reboot the board, and a BOOT button to put the board in flash mode (which can be used to receive code). Note that some boards may not have a BOOT button.

        It also comes with a built-in blue LED which is internally connected to GPIO 2. This LED can be used for debugging to provide some kind of visual physical output. There is also a red LED that lights up when you are powering the board.

ESP32 GPIO Pin Guide

        The ESP32 chip has 48 pins with various functions. Not all pins of ESP32 development boards are exposed, and some pins should not be used. The ESP32 DEVKIT V1 DOIT board usually has 36 exposed GPIOs that can be used to connect peripherals.

power pin

        Generally, all boards have power pins: 3V3, GND, and VIN. You can use these pins to power the board (if you are not powering the USB port), or to power other peripherals (if you are powering the board through the USB port).

General purpose input and output pins (GPIOS)

        Almost all GPIOs are assigned a number, which is how you should call them - by their number.

        With ESP32 you can decide which pins are UART, I2C or SPI you just set it in code. This is possible because of the multiplexing feature of the ESP32 chip that allows multiple functions to be assigned to the same pin.

        If you don't set them in code, the default configuration pins are shown in the image below (pin locations may vary by manufacturer). Additionally, there are pins that have specific functions that make them suitable or unsuitable for specific projects.

        We have a detailed guide dedicated to ESP32 GPIO, we recommend you to read: ESP32 Pin Assignment Reference Guide. It shows how to use the ESP32 GPIO and explains the best GPIO to use according to your project.

        The location of the GPIOs may vary depending on your board model. In general, however, each particular GPIO works the same way no matter what board you're using (with some exceptions). For example, no matter what the board is, usually GPIO5 is always the VSPI CS0 pin, and GPIO 23 always corresponds to VSPI MOSI for SPI communication, etc.

How to program ESP32?

ESP32 can be programmed with different firmware and programming languages. you can use it:

■ Arduino C/C++ using the Arduino core for the ESP32
■ Espressif IDF (Internet of Things Development Framework)
■ MicroPython
■ JavaScript
■ LUA
...
Our preferred method of programming the ESP32 is using C/C++ "The Arduino Programming Language". We also have some guides and tutorials for using the MicroPython firmware.

Use Arduino IDE to program ESP32

To program the board, you need an IDE to write code. For beginners, we recommend using the Arduino IDE. While it's not the best IDE, it works well and is easy and intuitive for beginners. After you become familiar with the Arduino IDE and start creating more complex projects, you may find it useful to use VS Code with the Platformio extension.

If you're just getting started with the ESP32, start with the Arduino IDE . At the time of writing this tutorial, we recommend using an older version (1.8.19) with the ESP32. While version 2 works well with the Arduino, there are still some bugs and some features that are not yet supported by the ESP32.

Install the Arduino IDE

To run the Arduino IDE, you need to have JAVA installed on your computer. If not, download and install the latest version from http://java.com/download .

Download Arduino IDE

To download the Arduino IDE, visit the following URL:

Do not install version 2.0. At the time of writing this tutorial, we recommend using an older version (1.8.19) with the ESP32. While version 2 works well with the Arduino, there are still some bugs and some features that are not yet supported by the ESP32.

Scroll down until you find the Legacy section.

Choose your operating system and download the software. For Windows, we recommend downloading the "  Windows ZIP File ". 

Run the Arduino IDE

Take the folder you just downloaded and unzip it. Run the executable named arduino.exe (highlighted below).

The Arduino IDE window should open.

Install ESP32 in Arduino IDE

In order to be able to program the ESP32 using the Arduino IDE, you need to add support for the ESP32 development board. Follow the steps below:

  1. Go to File > Preferences .

  1.  Enter the following in the Additional Board Manager URLs field. This will also add support for ESP32 and ESP8266 boards.

https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json,

http://arduino.esp8266.com/stable/package_esp8266com_index.json

 See below. Then, click the " OK " button.

  1. Open the board manager . Go to Tools > Boards > Board Manager...
  1. Search for ESP32 and install "  ESP32 by Espressif Systems  ":

 That's it. It will install in a few seconds.

After this, restart your Arduino IDE.

Then, go to Tools  >  Boards and check if you have an ESP32 board available.

You are now ready to start programming the ESP32 using the Arduino IDE.

ESP32 Example

In your Arduino IDE you can find several examples for the ESP32. First, make sure you have the ESP32 board selected in Tools  >  Board . Then, just go to File  >  Examples and look at the examples under the ESP32 section.

Update ESP32 core in Arduino IDE

It's a good idea to check occasionally that you have the latest version of the ESP32 board add-on installed.

You just need to go to Tools   >  Board   > Boards Manager , search for ESP32 , and check which version you have installed. If a newer version is available, select it to install.

Use Arduino IDE to upload code to ESP32

        To show you how to upload code to your ESP32 board, we'll try a simple example provided in the Arduino IDE Examples for ESP32.

     First, make sure you have ESP32 selected in Tools  >  Board . Then, go to File > ExamplesWiFi  >  WiFiScan .

     This will load code that scans for Wi-Fi networks within range of the ESP32 board.

         Connect the ESP32 development board to the computer with a USB cable. If you have the ESP32 DEVKIT DOIT development board, the built-in red LED will light up. This indicates that the board is getting power.

1) Go to Tools  >  Board , scroll down to the ESP32 section and select the name of your ESP32 board. In my case it was the DOIT ESP32 DEVKIT V1 board.

2) Go to  Tools  >  Ports  and select an available COM port. If the COM port is grayed out, you do not have the required USB driver. Check the Installing USB Drivers section before proceeding.

3) Press the upload button.

Some boards will automatically go into blink mode and the code will upload successfully immediately.

Other boards don't automatically go into blink mode, so you may end up with the error below.

 Failed to connect to ESP32: timed out...connecting...

or something similar:

A fatal error occurred: Failed to connect to ESP32: Wrong boot mode detected (0x13)! The chip needs to be in download mode.

        This means the ESP32 is not in blink mode when you try to upload code. In this case, you should long press the board's BOOT button, when you start to see "Connecting...". ” message in the debug window.

        NOTE: On some boards, a simple trick can put the ESP32 into blink mode automatically. Check out the following tutorials: [SOLVED] Could not connect to ESP32: Timed out waiting for packet header.

        The code should now have been successfully uploaded to the board. You should get a "Done uploading" message.

Guess you like

Origin blog.csdn.net/m0_46509684/article/details/129079088