🛠️ Install PlatformIO and Flash a Blink Sketch

Learning Objectives

By the end of this lesson you can:

  • Install the PlatformIO extension in VS Code and open the PlatformIO Home screen.
  • Create a new ESP32 project, choosing the correct board and the Arduino framework.
  • Explain what platformio.ini, src/main.cpp, setup(), and loop() do.
  • Build and upload a blink sketch, and recognize a successful upload in the terminal.
  • Know what to do when the upload says "Failed to connect".

Quick Review

In the last lesson you learned that your board is powered over USB and that its pins speak 3.3 V logic only. You also learned to leave GPIO 6 to 11 alone, since those pins are wired to the internal flash memory.

That is all you need here. The USB cable you plug in for power is also the cable you will use to send code to the board, and today you will use it for exactly that.

Theory

What PlatformIO gives you

PlatformIO is an extension for VS Code that turns it into a full embedded development environment. You get one window for writing code, building it, uploading it, and watching the board's output. It also downloads the correct compiler and ESP32 libraries for you, so you never install a toolchain by hand.

A useful mental model: VS Code is the desk, PlatformIO is the assistant who fetches the tools and runs the commands.

flowchart LR
Edit["✍️ Write code"] --> Build["🔨 Build"] --> Upload["⬆️ Upload"] --> Run["💡 Board runs"]

Anatomy of a PlatformIO project

When you create a project, PlatformIO generates a small folder structure. You only touch two of these files today.

esp32-blink/
  platformio.ini      <- project settings (board, framework, speeds)
  src/
    main.cpp          <- your code goes here
  .pio/               <- build output, ignore it

platformio.ini is the control panel. A typical ESP32 project looks like this:

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200
upload_speed = 921600

Sign in to view the full content of this lesson. Sign in