How to Program Arduino Using VS Code with PlatformIO IDE Extension
step by step guide to visual studio code free opensource platform for MCU Programming
Introduction
Hello Makers and Embedded Enthusiasts! 👋 Are you just starting out in embedded development or already familiar with platforms like Arduino IDE, Keil, or STM32CubeIDE? If yes, then it’s time to explore another powerful and user-friendly development environment — VS Code with the PlatformIO IDE extension.
While the traditional Arduino IDE is excellent for small projects, it can feel limited when your code grows beyond a few hundred lines or requires multiple files and advanced debugging. That’s where PlatformIO shines!
In this tutorial, you’ll learn how to program Arduino boards using VS Code (Microsoft Visual Studio Code) with the PlatformIO IDE extension. We’ll guide you step-by-step through installation, setup, and usage on Windows, helping you unlock a more efficient and professional way to develop Arduino projects.
Installing VS Code(Visual Studio Code) on Windows
To get started, visit the official Visual Studio Code website:
👉 https://code.visualstudio.com/Download the stable version of VS Code suitable for your operating system (for this tutorial, we’ll use Windows).
Once the download is complete, open the installation wizard and follow the on-screen instructions. Accept the license agreement, then click Next to continue.
When prompted, select the recommended options such as:
- Create a desktop icon
- Add “Open with Code” to the context menu
- Add VS Code to PATH (for easier command-line access)
After selecting the options, click Next, and then click Install to begin the setup process.
Once the installation is complete, click Finish to close the setup wizard. Now, open Visual Studio Code, and you’ll see the Welcome Screen along with the Release Notes of the latest version.
Congratulations! 🎉 You’ve successfully installed VS Code on your computer.
Our next step is to install the PlatformIO IDE extension — the powerful tool that makes programming Arduino boards inside VS Code simple and efficient. Let’s move on!
Installing PlatformIO IDE Extension on VS Code
With VS Code installed, you can now program a wide range of development boards — including Arduino (Atmel AVR), STMicrocontrollers, NXP, Teensy, and ESP series boards — all using the PlatformIO IDE extension.
This extension turns VS Code into a powerful embedded development environment, supporting multiple platforms and advanced features like auto-completion, project management, and debugging.
ollow the steps below to install the PlatformIO IDE extension in VS Code.
- 1. (Click on the Extensions icon or press Ctrl+Shift+X to open the Extensions tab
- 2.Search for “PlatformIO IDE”,Select the first option
- 3.Finally, click the Install button (Note: the installation may take a few minutes)
Verify PlatformIO IDE Installation
Once the installation is complete, ensure that the PlatformIO IDE extension is enabled in VS Code. You’ll notice a small PlatformIO icon appear on the left sidebar, along with a Home icon that takes you directly to the PlatformIO Home Dashboard.
That’s it! 🎉 The PlatformIO IDE extension has been successfully added to Visual Studio Code, and you’re now ready to start creating and uploading your Arduino projects from this powerful environment.
Explore the VS Code Interface
Open VS Code. The following Main screen shows the meaning of each icon on the left sidebar and its shortcuts:
- 📁 File Explorer – View and manage your project files
- 🔍 Search – Find text or code across all files
- 🌿 Source Control – Manage version control (e.g., Git)
- 🐞 Run and Debug – Launch and debug your code
- ⚙️ Extensions – Install and manage extensions like PlatformIO
For quick access to commands, press Ctrl + Shift + P or navigate to View > Command Palette… The Command Palette lets you search and execute any command in VS Code — perfect when you’re unsure where a specific option or shortcut is located.
Alternatively, you can click on the PlatformIO (PIO) icon on the left sidebar to open the PlatformIO dashboard and access all PlatformIO tasks and tools directly.
Note : If you don’t see the PIO icon and the quick tools at the bottom, you may need to restart VS code for the changes to take effect.
PlatformIO IDE Overview
Now that PlatformIO is installed and running inside VS Code, let’s create a simple project to see how it works in action.
In this example, we’ll show you how to create, save, and upload an “LCD Blink Welcome Text” sketch to your Arduino UNO board.
🧰 Requirements:
- 1. Arduino UNO Board
- 2. 16x2 Liquid Crystal Display (LCD)
This project will help you understand the basic workflow of PlatformIO, including project creation, code editing, and uploading the sketch to your Arduino board.
Create a New Project
To create a new project in PlatformIO, follow these steps:
- 1.Open VS Code and click on the PlatformIO (PIO) icon on the left sidebar.
- 2.In the PIO Home dashboard, click on the Home icon if you’re not already on the welcome page.
- 3.On the Welcome Page, select the “+ New Project” tab to start creating your project.
This will open the new project setup wizard, where you can configure your project name, board type, and framework before starting to code.
First, click on the PlatformIO (PIO) icon in VS Code. Then, select the Home icon to go to the Welcome Page. On the welcome screen, click the “New Project” tab to begin creating your project. by clicking you will get below screen Project Wizard
Configure Your New Project
- 1.Project Name: Enter a name for your project as you prefer.
- 2.Board: Select your development board. In this tutorial, we’re using Arduino UNO, but you can choose any board you are working with..
- 3.Framework: Choose the appropriate framework for your board. For Arduino UNO, select Arduino.
Once all settings are configured, click the Finish button. After that, your new project will be created, and you’ll see the PlatformIO project workspace ready for coding, as shown below.
VS Code with PlatformIO uses a folder structure that’s different from the standard Arduino .ino project. Click on the Explorer tab in VS Code, and you’ll see all the files and folders that PlatformIO automatically created under your project directory. This structure helps manage multiple files, libraries, and configurations efficiently for more advanced Arduino projects.
Understanding the platformio.ini File
The platformio.ini file is the main configuration file for your PlatformIO project. It defines key settings such as:
- Platform: (e.g., Atmel AVR for Arduino UNO)
- Board: (e.g., Arduino UNO)
- Libraries to include in your project
- Upload options for your board
- Serial Monitor baud rate
- Other project-specific configurations
Adding Libraries in platformio.ini
In the platformio.ini file, you can include the libraries your project needs using the lib_deps directive. For this tutorial, we’ll add the LiquidCrystal library to our project. To do this:
- 1. Click on the PlatformIO (PIO) Home icon in VS Code.
- 2. Go to the Libraries section.
- 3. On the Registry tab, search for the library you want to add.
This makes it easy to include and manage all the required libraries directly within PlatformIO for your Arduino project.
As show in below figure there are Registry where you can search any library for your project , installed library and built-in library and , also id any update available you can check it in updated tab.
for click on Add Project button will add library to your project wizard will come
It will reflect on platformio.ini file as shown below.One more thing we would need to explain here is, if you are using programmer. We should make some change in platformio.ini. As Right now I am using USBASP programmer for that below code need to write.
For different programmer you can chek given link
Different ProgrammerAs show in workspace Project detail... Project has there are three folder main Scr, include and lib folder. Main.cpp file is inside src folder. In PlatformIO , all your Arduino sketches should start with the #include"Arduino.h" Same as setup() and loop().
At the bottom, there’s a blue bar with PlatformIO commands.
Here’s the what icon does from left to right: PlatformIO Home, Build/Compile, Upload, Clean, Serial Monitor, New Terminal
That’s it — our setup is complete! 🎉 We hope you found this tutorial helpful. If you have any questions or need further assistance, feel free to leave a comment below, and we’ll do our best to help you get started.
0 comments:
Post a Comment