AVR MCU: PlatformIO Setup
Set up with your favorite AI
Gemini & other AI
Copy the setup prompt into your AI. Work through each step together, from checking your kit to getting it running.
Copy the prompt, then paste it into Gemini’s message box.
View prompt
Use PlatformIO IDE to set up the development environment for the AP01 AVR MCU leaf (ATmega328P, 3.3 V, 8 MHz).
Introduction
Section titled “Introduction”Visual Studio Code (VS Code) is Microsoft’s lightweight source-code editor for Windows, macOS, and Linux. PlatformIO IDE is a VS Code extension with fast builds and per-project management of library and board versions.
What to prepare
Section titled “What to prepare”- Basic Kit 2
- A Windows, macOS, or Linux computer
Advance preparation
Section titled “Advance preparation”
Install PlatformIO IDE
Section titled “Install PlatformIO IDE”- Install VS Code.
- Open Extensions, search for
PlatformIO IDE, and install the extension published by PlatformIO. - Wait for setup to finish and restart VS Code if prompted.
PlatformIO Core and the serial monitor are included. A portable Python interpreter is used when available. If prompted to install Python, follow PlatformIO’s instructions. Linux also needs python3-venv.
Install Japanese Language Pack for Visual Studio Code for a Japanese interface or Teleplot for plotting only if you need them. See the official PlatformIO IDE setup guide for details.
Getting Started
Section titled “Getting Started”Uploading replaces the program currently on the MCU. To run the kit demo again later, follow Restore the demo.
Create a new project
Section titled “Create a new project”This Hello World example introduces the PlatformIO IDE workflow.
- Start VS Code and open File → New Window.
- Select PlatformIO in the left sidebar to open PLATFORMIO QUICK ACCESS.
- Select PIO Home → Open.
- Select New Project and fill in the Project Wizard, then select Finish. The first setup for a board may take several minutes to download its files.
- Name:
Hello_World_Pjt - Board:
Arduino Pro or Pro Mini ATmega328(3.3v,8Mhz) - Framework:
Arduino
- Name:
- Open
platformio.iniand check the board and framework settings:
[env:pro8MHzatmega328]platform = atmelavrboard = pro8MHzatmega328framework = arduino- The AVR MCU upload workflow detects the serial port automatically, so a COM port number does not need to be specified.
- Add the serial monitor baud rate to
platformio.ini:
monitor_speed = 115200- Open
src/main.cppand paste the following code. PlatformIO requires#include <Arduino.h>at the beginning of an Arduino sketch.
#include <Arduino.h>
void setup() { Serial.begin(115200); delay(10);}
void loop(){ Serial.println("Hello World"); delay(1000);}Source code: Hello_World_Pjt
- Use Project Environment Switcher in the bottom PlatformIO toolbar to select the correct active project, then select Build.

- Connect Leafony to the computer as shown in Connecting to PC.
- Select Upload to upload the program to the MCU.
- Press the MCU reset button to run the program.
- Open Serial Monitor and check that
Hello Worldappears.

Install the library
Section titled “Install the library”Add only the libraries your example needs to lib_deps in the active [env:...] section of platformio.ini. See Libraries and board definitions for sources, syntax and existing version specifications. Hello World needs no additional libraries.
Serial plotter
Section titled “Serial plotter”To plot serial data as in Arduino IDE, use the Teleplot for VSCode extension. Download and try the sample below.
- Download Teleplot_Example_1 from GitHub and save it in your project folder.1
- Run the program.
- Select teleplot at the bottom of the window, choose the COM port, and select Open to display the graph.
- Teleplot plots serial messages in the form
>varName:1234\n. See the Teleplot documentation for details.
// Plot a sinus Serial.print(">sin:"); Serial.println(sin(i));
// Plot a cosinus Serial.print(">cos:"); Serial.println(cos(i));AVR Beginner Examples
Section titled “AVR Beginner Examples”Download the sample projects from GitHub, save them in your project folder,1 and run them in PlatformIO IDE.
| Item | Source code |
|---|---|
| Temperature and humidity sensor | Thermo-Hygrometer_Pjt |
| Illuminance sensor | Illuminance_Meter_Pjt |
| Accelerometer | Accelerometer_Pjt |
MCU and board settings
Section titled “MCU and board settings”See Choose a board definition for the mapping between AP model numbers and board settings. Follow each MCU’s setup page for upload and port configuration.
Differences from Arduino IDE sketches
Section titled “Differences from Arduino IDE sketches”- Add
#include <Arduino.h>at the beginning of the program. Arduino IDE includes basic type definitions and commonly used headers automatically; PlatformIO requires the explicit include. - Define custom functions before they are called, or add a prototype declaration. Arduino IDE prepares declarations automatically, while PlatformIO follows normal C++ rules.
The following example fails to build because the function is defined after its first use:
void setup() { // put your setup code here, to run once: func();
}
void func() { ;}This example builds because the function is defined before its use:
void func() { ;}
void setup() { // put your setup code here, to run once: func();
}This example also builds because it includes a prototype:
// Prototypesvoid func(void);
void setup() { // put your setup code here, to run once: func();
}
void func() { ;}Rename or delete a project folder
Section titled “Rename or delete a project folder”New Project in the Project Wizard creates a folder under ~/Documents/PlatformIO/Projects by default. Rename or delete that folder directly in your file manager.
Change the project folder location
Section titled “Change the project folder location”Configure the location from the terminal:
- Start VS Code and open File → New Window.
- Select PlatformIO in the sidebar to open PLATFORMIO QUICK ACCESS.
- Select PIO Home → Open.
- Run
pio settings set projects_dir <absolute-path>with your desired folder’s absolute path. - Restart VS Code.