Getting started with the ESP32 Microcontroller

Killian Chateau
3 min readAug 24, 2023

--

The ESP32 is a cheap way to learn more about microcontrollers and IoT. For less than 5€ you can get one ! The ESP32 has the ability to use WiFi which is great. I’m using an ESP32 WROOM 32U and I will show you the quickest way get started with the ESP32.

Our development environment :

After experimenting with different ways to program the ESP32, I have decided to use VsCode and the PlatformIO extension. It is really easy to use, just download the extension and start a new project on the PlatformIO menu. No need to install any compiler or anything else, PlatformIO takes care of everything.

For the board and framework, just use the following it will be enough to start.

Head to the src folder and modify main.cpp and let’s make a program that makes use of the WiFi capabilities of the ESP32. Mine doesn’t have a light to blink anyways :(

The code

This program will scan for WiFi networks and print informations on it.

#include <Arduino.h>
#include <WiFi.h>

void setup() {
Serial.begin(115200);
// Set Wifi to station mode (connects to the router like a phone)
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);
Serial.println("Setup OK");


}

void loop() {
// Every 5 second we scan the environment for WiFi networks
Serial.println("Starting Scan");
int n = WiFi.scanNetworks(); // number of networks
Serial.println("Scan OK");
if (n==0)
Serial.println("No Networks Found");
else
{
Serial.print(n);
Serial.println(" Networks Found");
for (int i=0;i<n;i++)
{
// Print SSID (network name) and RSSI (quality of connection)
Serial.print(i+1);
Serial.print(" :");
Serial.print(WiFi.SSID(i));
Serial.print(" (");
Serial.print(WiFi.RSSI(i));
Serial.print(")");
Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN)?" ":"*");
delay(10);
}
Serial.println("");
delay(5000);
}

}

Compiling and Flashing on the ESP32

  • go to VsCode command palette (CTRL + SHIFT + P) or View →Command palette. Don’t forget to connect your PC to your ESP32 with a USB cable.
  • run Tasks: Run build Task
  • Then in command palette, use PlatformIO Upload while holding the boot button on your ESP32

Note : if the upload fails, it is probably because your program doesn’t recognize your ESP32. You will need to install this driver and link the folder to your ESP32 device (Windows + X), device monitor, search your ESP32 in other devices and choose to manually link this driver folder to your device.

https://www.silabs.com/documents/public/software/CP210x_Universal_Windows_Driver.zip

Once it is done you should see something like this in your device monitor :

Now our program is in the ESP32, let’s see what it prints with the PlatformIO Serial Monitor (in command palette)

Here is an example of what the output should look like :

I recommend using an aluminum foil antenna to enchance the WiFi range, otherwise it can be quite short (around 10m).

Congratulations, you can now develop on your ESP32 and you have built a WiFi scanner on a microcontroller.

Thank you for reading. Have a nice day :)

--

--