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.
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
Step-by-Step Setup
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.
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.
Open PlatformIO Home
- Press
Ctrl+Shift+P
(Command Palette) - Type
PlatformIO Home
- Select it and wait for the UI to load
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)
Modify Project Files
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;
}
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.
Build, Upload, and Monitor
At the bottom of the Cursor/VSCode window, youâll find three buttons provided by PlatformIO:
Check mark: Compiles your code (build)
Arrow: Uploads the firmware to your ESP32
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!