View home page for PlatformIO: Click home button at the bottom or click alien icon → PIO Home → Open
Create a PlatformIO Project
Open the Project Wizard:
In Visual Studio Code, click on the PlatformIO icon (an alien head) on the left sidebar.
Select “New Project” to open the project creation wizard.
Configure Your Project:
Project Name: Choose a descriptive name for your project (e.g., MyFirstProject).
Board: Select the microcontroller board you are using (e.g., Arduino Uno, ESP32, or STM32).
Framework: Pick the framework compatible with your board (e.g., Arduino, ESP-IDF, Mbed OS). PlatformIO will automatically determine this based on your board selection.
Location: Set the folder where the project will be stored. You can leave the default location or choose a custom directory.
Tip
To update the configuration manually, modify platform.ini, example:
[env:uno]platform = atmelavr; board = unoframework = arduino# Mega Uno settingsboard = megaatmega2560upload_port = COM12
Project Folder Structure:
After creating the project, PlatformIO will generate a folder structure like this:
In Arduino IDE, most files use the .ino extension, but in PlatformIO, all your code files will be kept in the src folder, and there will be a main.cpp file
main.cpp
#include <Arduino.h>// put function declarations here:int myFunction(int, int);void setup() { // put your setup code here, to run once: int result = myFunction(2, 3);}void loop() { // put your main code here, to run repeatedly:}// put function definitions here:int myFunction(int x, int y) { return x + y;}
Create a sample sketch
Here’s a simple example, Arduino Uno Blink Test, demonstrating how to define and call functions:
arduino_blink_test.ino
#include <Arduino.h>int led = LED_BUILTIN;void setup(){ // put your setup code here, to run once: pinMode(led, OUTPUT);}void loop(){ // put your main code here, to run repeatedly: digitalWrite(led, HIGH); delay(1000); digitalWrite(led, LOW); delay(1000);}
Build and Upload Your Code
Connect Your Board:
Plug in your microcontroller to your computer via USB.
Build the Project:
Click the checkmark icon in the PlatformIO toolbar or use the PlatformIO: Build command from the command palette.
Ensure there are no errors in your code.
Upload to Board:
Click the arrow icon to upload your code to the microcontroller.
Monitor the upload process in the Terminal.
Open the Serial Monitor:
Click the plug icon in the PlatformIO toolbar to open the Serial Monitor.
Set the baud rate to match your Serial.begin() call (e.g., 9600).