Lesson 3 / 1127%

Lesson 3

Setting Up the Environment

15 min

Add the ESP32 package to the Arduino IDE, select the board and port, and fix common problems.

Definition

A board package is a collection of files that teaches the Arduino IDE how to recognize a new type of board. It contains the compiler, libraries, and settings specific to that board. Uploading is the process of transferring the compiled program from the computer to the board's memory through a USB cable.

What You Need

  • An ESP32 development board (DevKit).
  • A USB cable capable of transferring data: some cables are designed only for charging and will not work.
  • The Arduino IDE, available for free at arduino.cc.
  • An Internet connection, because the board package is quite large (several hundred megabytes).

Installation Overview

The installation process consists of five steps that only need to be completed once. After that, you will be able to upload programs to your ESP32 just as easily as to an Arduino Uno.

  • Step 1: tell the IDE where to find Espressif's board package.
  • Step 2: install the esp32 package.
  • Step 3: install a USB driver if your computer does not recognize the board.
  • Step 4: select the board and port.
  • Step 5: upload your first test program.

Step 1: Add ESP32 Support to the IDE

The Arduino IDE does not support the ESP32 by default: you need to add Espressif's board package. Open File > Preferences(or Arduino IDE > Settings on macOS), find the Additional Boards Manager URLs field, and add the following address:

Boards Manager URL
https://espressif.github.io/arduino-esp32/package_esp32_index.json

If the field already contains an address (for example, for another family of boards), do not delete it. Add the new URL after the existing one, separated by a comma, or click the icon on the right side of the field to enter one address per line. Then confirm by clicking OK.

Screenshot: the Arduino IDE Preferences window with the Additional Boards Manager URLs field filled in.

Step 2: Install the ESP32 Package

Open the Boards Manager(the board icon in the left sidebar, or Tools > Board > Boards Manager), search for "esp32", then install the packageesp32 by Espressif Systems. The download is fairly large, so allow a few minutes for the installation to finish.

  • Make sure you select the package published byEspressif Systems: other packages have similar names but are not official.
  • The download may appear to stop at times. Check the message area at the bottom of the IDE, which displays the installation progress.
  • If the installation fails, check your Internet connection and try again. It will usually resume from where it stopped.
Screenshot: the Boards Manager showing the esp32 by Espressif Systems package being installed.

Step 3: Install the USB Driver if Necessary

Connect the board to your computer. Depending on the USB-to-serial chip used by your board, your computer may need a driver to recognize it:

  • CP2102 (CP210x): driver provided by Silicon Labs.
  • CH340 or CH9102: driver provided by WCH.

On many modern computers, the board is recognized without installing anything. If no port appears in the IDE, install the driver corresponding to your chip. The chip's name is printed on the board, near the USB port.

How to Check Whether the Board Is Detected

  • Windows: open Device Manager and expand "Ports (COM & LPT)". Your board appears under a name such asCOM3.
  • macOS: the port name begins with/dev/cu., for example/dev/cu.usbserial-0001.
  • Linux: the port is usually named/dev/ttyUSB0or/dev/ttyACM0.

Linux: Permission Issue

If the port appears but uploading is denied ("Permission denied"), your user account does not have permission to access the serial port. Add your user to the appropriate group using the command below, then log out and log back in.

Linux Terminal
sudo usermod -a -G dialout $USER

Step 4: Select the Board and Port

In the Tools menu:

  • Board: select "ESP32 Dev Module" (the generic option suitable for most DevKit boards).
  • Port: select the port that appears when the board is connected.

If you are unsure which port to select, disconnect the board and check the list, then reconnect it. The new port that appears is the correct one. If your board is a specific model (ESP32-S3, ESP32-C3, etc.), look for its exact name in the board list instead of keeping "ESP32 Dev Module".

Screenshot: the Arduino IDE Tools menu showing ESP32 Dev Module as the selected board and the corresponding port.

Step 5: Your First Test

Copy this small program, which displays a message in the Serial Monitor every second, then click the Upload button.

test.ino
void setup() {
  Serial.begin(115200);
}

void loop() {
  Serial.println("Hello from the ESP32!");
  delay(1000);
}

Next, open the Serial Monitorand set the speed to 115200 baud(the standard speed used with the ESP32, faster than the 9600 baud commonly used with Arduino Uno).

Screenshot: the Serial Monitor set to 115200 baud, displaying several lines of Hello from the ESP32!

The Stages of Uploading

When you click Upload, the IDE performs several operations in sequence. Understanding them helps you identify where a potential problem occurs.

  • Compilation: your C++ code is translated into machine language. An error at this stage (a red message) indicates a problem in your program.
  • Connection: the IDE communicates with the board through the selected port. Getting stuck at "Connecting..." indicates a cable, port, or boot mode issue.
  • Writing: the program is transferred to flash memory, with a progress percentage displayed.
  • Restarting: the board restarts and runs your program.

A Second Test: Reading Chip Information

To verify that the IDE has correctly identified your model, upload this program. It asks the chip for its model, number of cores, frequency, and available memory using functions from the ESP32-specificESPobject.

chip_info.ino
void setup() {
  Serial.begin(115200);
  delay(1000);

  Serial.print("Model: ");
  Serial.println(ESP.getChipModel());

  Serial.print("Number of cores: ");
  Serial.println(ESP.getChipCores());

  Serial.print("Frequency: ");
  Serial.print(ESP.getCpuFreqMHz());
  Serial.println(" MHz");

  Serial.print("Free memory: ");
  Serial.print(ESP.getFreeHeap());
  Serial.println(" bytes");
}

void loop() {
}

The information is displayed only once, insidesetup(). If you open the Serial Monitor too late, you will miss it. In that case, press theEN button to restart the board and display the information again.

A Third Test: Blinking an LED

The classic final test is to blink the built-in LED. On many boards, it is connected toGPIO2. If nothing blinks on your board, it may use a different pin or have no built-in LED. In that case, connect an external LED with a 220-ohm resistor to a suitable output pin of your choice.

blink.ino
const int led = 2;   // Built-in LED on many boards

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

void loop() {
  digitalWrite(led, HIGH);
  delay(500);
  digitalWrite(led, LOW);
  delay(500);
}

When Uploading Fails

The "Connecting........_____" Message Gets Stuck

On some boards, you need to manually put the ESP32 into upload mode. Hold down the BOOTbutton when the IDE displays "Connecting...", then release it when the transfer begins. If the problem persists, try another USB cable, another USB port on your computer, or reduce the upload speed in the Tools menu (Upload Speed, for example 115200).

  • No port visible: the USB cable may be charge-only, or the driver may be missing.
  • Unreadable text in the Serial Monitor: the monitor speed is not set to 115200 baud.
  • Startup messages: every time the ESP32 restarts, it displays a few technical lines before your program runs. This is normal.
  • Port busy: only one program can use the port at a time. Close any other Serial Monitor or software using it before uploading.
  • Compilation error: read the first red error message, which indicates the problematic line. Missing punctuation is often the cause.

Keeping Your Installation Up to Date

Espressif regularly releases updates to the esp32 package to fix bugs and add new features. You can install them through the Boards Manager, which displays an update button when a new version is available. If you experience unexpected behavior after an update, you can also reinstall a previous version by selecting it from the package's version dropdown menu.

Key Takeaways

  • The IDE must first recognize the ESP32: add Espressif's URL in Preferences, then install the esp32 package.
  • Use a data USB cableand install the driver for your USB-to-serial chip if the port does not appear.
  • Select ESP32 Dev Moduleand the correct port in the Tools menu.
  • Set the Serial Monitor to 115200 baud.
  • If the connection fails, hold down theBOOT button during uploading.

Exercise

Install the esp32 package, upload the test program, then modify the message and the duration ofdelay. Press the board's EN button and observe what appears in the Serial Monitor.

Exercise: Chip Dashboard

Modify thechip_info.inoprogram so that it also displays the flash memory size (usingESP.getFlashChipSize()) and the SDK version (usingESP.getSdkVersion()). Write down the values obtained and compare them with your board's advertised specifications.

Go Further

Combine the first two tests: make the LED blink and display a message in the Serial Monitor every time its state changes ("LED ON" followed by "LED OFF"), along with the time elapsed since startup provided bymillis().