Coding Your ESP32 Firmware with Cursor (or VSCode) + PlatformIO

:hammer_and_wrench: Getting Started: Coding Your ESP32 Firmware with Cursor + PlatformIO

If you want to prototype hardware (like ESP32) using Gen AI and LLMs, this guide will help you set up your environment and print your first “Hello World” to the Serial Monitor.


:toolbox: Prerequisites

  • A computer with macOS, Linux, or Windows
  • Cursor
  • PlatformIO IDE extension
  • An ESP32 board (e.g., ESP32 DevKit V1 or ESP32 Dev Module)
  • USB cable to connect the board

:puzzle_piece: Step-by-Step Setup

:one: Install PlatformIO Extension

In Cursor or VSCode:

  • Open the Extensions panel (Ctrl+Shift+X)
  • Search for PlatformIO IDE
  • Click Install

PlatformIO is a full toolchain to compile, upload, and monitor firmware for various boards, including the ESP32.


:two: Connect Your ESP32

Plug your ESP32 board into your computer via USB. Make sure it’s detected by your system. On Windows, you might need drivers like CP210x or CH340 depending on your ESP32 model.


:three: Open PlatformIO Home

  • Press Ctrl+Shift+P (Command Palette)
  • Type PlatformIO Home
  • Select it and wait for the UI to load

:four: Create a New Project

In PlatformIO Home:

  • Click New Project
  • Name your project (avoid spaces or special characters)
  • Select your board: e.g., Espressif ESP32 Dev Module
  • Choose Arduino as the Framework (recommended for community support)
  • Click Finish and wait for dependencies to download (~30 seconds)

:memo: Modify Project Files

:five: Write Firmware in src/main.cpp

Replace the contents of src/main.cpp with the following:

#include <Arduino.h>

// Optional: declare any custom functions here
int myFunction(int, int);

void setup() {
  Serial.begin(115200); // Start serial communication
  Serial.println("Hello world from setup!");
  int result = myFunction(2, 3); // example call
}

void loop() {
  Serial.println("Hello world from ESP32 loop!");
  delay(1000); // wait 1 second
}

int myFunction(int x, int y) {
  return x + y;
}

:six: Edit platformio.ini

In the root of your project, open platformio.ini and add this line:

monitor_speed = 115200

This ensures your serial monitor communicates at the correct baud rate for debugging.


:white_check_mark: Build, Upload, and Monitor

At the bottom of the Cursor/VSCode window, you’ll find three buttons provided by PlatformIO:

  • :white_check_mark: Check mark: Compiles your code (build)
  • :rocket: Arrow: Uploads the firmware to your ESP32
  • :electric_plug: Plug icon: Opens the Serial Monitor

After uploading, open the serial monitor. You should see:

Hello world from setup!
Hello world from ESP32 loop!
Hello world from ESP32 loop!
...

Congratulations — your firmware is running! :tada:

1 Like

great, thanks. As it happens my ESP32 is arriving in a few days!

1 Like

After last update (Cursor 1.0) not working make ++ and serial monitor (on Platformio and ESP32)

@cxemnet
Got it working.

Intellisense Engine is disabled by default. Edit /home/{username}/.config/Cursor/User/settings.json & enable C_Cpp.intelliSenseEngine.

I can’t install it. Anyone know why cursor doesn’t show anything in the extensions marketplace for platformio? Also can’t install from the CLI

2 Likes

Same as rob3, Im unable to find PlatformIO IDF in the Extensions pane. any update on this?

Same, platform IO not showing up in the list of extensions

Install works on windows, but not on macos

Same here, can’t find platformIO among extensions. But if I installed VS code and platformio in there, I could get it installed in cursor via the dialog box import all extensions from VS code.