ESP32 Starter Guide

ESP32 Getting Started

ESP32 is a low-cost, low-power system on a chip (SoC) series with Wi-Fi & dual-mode Bluetooth capabilities. It became a sought-after choice among developers for building wireless communication-based applications due to its microcontroller architecture and significantly low power consumption. ESP32 chip modules like the ESP32-WROOM and ESP32-WROVER integrate advanced components such as Flash, SRAM and input/output interfaces that simplify circuit design and reduce production cost.

Here, we will delve into the realms of ESP32, walking you through its basics, possible sensor modules, example CPP code, and how to use ESP32-WROVER to connect to wifi.

Table of Contents

  1. ESP32 Basic Overview
  2. Possible Sensor Modules for ESP32
  3. ESP32 CPP Code Example
  4. Connecting ESP32-WROVER to WiFi

ESP32 Basic Overview

ESP32 microcontroller supports a variety of features including:

Developers can also leverage the FreeRTOS on ESP32, which is a real-time operating system for microcontrollers that is lightweight and efficient.

Possible Sensor Modules for ESP32

Before choosing a sensor module for ESP32, it is necessary to consider the feasibility based on factors such as power consumption, accuracy, and ease of interfacing. Some compatible sensor modules include:

ESP32 CPP Code Example

Here's an example code to blink an onboard LED using ESP32. This is often used as a "Hello World" introductory code for beginners.

#define LED_BUILTIN 2

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);
  delay(1000);
  digitalWrite(LED_BUILTIN, LOW);
  delay(1000);
}

In the code above, LED_BUILTIN is a pre-defined pin in ESP32 board configuration where the on-board LED is connected.

Note: Ensure that you have the ESP32 board library installed in your IDE.

Connecting ESP32-WROVER to WiFi

To connect your ESP32-WROVER to WiFi, use the following CPP code snippet. Replace "yourSSID" and "YourPassword" with your WiFi SSID and password respectively.

#include <WiFi.h>

const char* ssid     = "yourSSID";
const char* password = "YourPassword";

void setup()
{
  Serial.begin(115200);

  delay(10);
  
  // connecting to a WiFi network
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  
  Serial.println("");
  Serial.println("WiFi connected.");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

In this example, we are using the 'WiFi.h' library. WiFi.begin(ssid, password) function is used to connect to a WiFi network. The ESP32 keeps trying to connect to WiFi until its status is 'WL_CONNECTED'.

While ESP32 is a powerful tool with numerous features, it requires skills and hands-on experience to master. This guide serves to be a stepping stone in your journey to mastering ESP32.


Sources:

  1. ESP32 Official Documentation
  2. ESP32 Arduino Core Board Package
  3. FreeRTOS in ESP32

Next Steps

  1. Flashing MicroPython on ESP32
  2. Building a Weather Station with ESP32

That's all about the ESP32 Starter Guide. Happy coding!