PlatformIO

6.1.19 · active · verified Sun Apr 12

PlatformIO is a powerful, open-source ecosystem for embedded software development, offering a collaborative environment that embraces declarative principles, test-driven methodologies, and modern toolchains. It features a cross-platform build system, unified package manager, and supports various development platforms and frameworks for microcontrollers and IoT devices. The current stable version is 6.1.19, with active and frequent minor updates.

Warnings

Install

Quickstart

This quickstart demonstrates how to programmatically interact with PlatformIO Core CLI from Python. It initializes a new PlatformIO project for an `esp32dev` board and then lists the packages installed for that project. This interaction pattern is common for integrating PlatformIO into automation scripts or custom applications, as PlatformIO's primary interface is its command-line tool (`pio`). Ensure 'pio' is in your system's PATH.

import subprocess
import os

# Create a dummy project directory
project_dir = "my_pio_project"
os.makedirs(project_dir, exist_ok=True)
os.chdir(project_dir)

try:
    # Initialize a PlatformIO project for a common board (e.g., esp32dev)
    # This will download necessary frameworks and tools into the project's .pio folder
    print(f"Initializing PlatformIO project in {os.getcwd()}...")
    result = subprocess.run(
        ["pio", "project", "init", "--board", "esp32dev"],
        capture_output=True, text=True, check=True
    )
    print("\n--- pio project init Output ---")
    print(result.stdout)
    if result.stderr:
        print("\n--- pio project init Errors ---")
        print(result.stderr)

    # List installed packages within the project
    print("\nListing installed packages...")
    result = subprocess.run(
        ["pio", "pkg", "list"],
        capture_output=True, text=True, check=True
    )
    print("\n--- pio pkg list Output ---")
    print(result.stdout)

except subprocess.CalledProcessError as e:
    print(f"Error executing PlatformIO command: {e}")
    print(f"Stdout: {e.stdout}")
    print(f"Stderr: {e.stderr}")
except FileNotFoundError:
    print("Error: 'pio' command not found. Ensure PlatformIO Core CLI is installed and in your PATH.")
finally:
    # Clean up the created project directory
    os.chdir("..")
    # In a real scenario, you might want to remove the directory:
    # import shutil
    # shutil.rmtree(project_dir)
    print(f"\nQuickstart finished. Project directory: {project_dir}")

view raw JSON →