[VS Code PlatformIO IDE Arduino LED Blinking Tutorial]

Welcome to our tutorial on how to blink an LED using the Arduino platform and the VS Code PlatformIO IDE. In this guide, we'll walk you through the process of setting up your development environment, connecting your Arduino board, and writing code to blink an LED. We will also introduce some basic concepts of digital electronics and the Arduino programming language. By the end of this tutorial, you'll have a solid foundation to build on and create more advanced projects using Arduino and the VS Code PlatformIO IDE.

In this tutorial, it shows how to install PlatformIO IDE in Visual Studio Code, how to write LED blinking program in VS Code PlatformIO IDE, how to use PlatformIO IDE to compile and upload to Arduino board, and how to use serial monitor in PlatformIO. The LED used here is connected to digital pin 7 of the Arduino Uno.

Content
PlatformIO and VS Code (Visual Studio Code)
VS Code (Visual Studio Code) is a popular open source code editor developed by Microsoft. It supports almost all coding languages, from high-level languages ​​such as C/C++, web code languages, JavaScript, html, css to assembly language. It has rich built-in features like smart code (smart code completion), faster seek in files, live preview, auto save, extensions, .net support and more.

PlatformIO is an open source IDE (Integrated Development Environment) for rapid embedded software development with smart code completion, advanced debugging, terminal, support for more than 50 development platforms () supports more than 1000 boards and development kits (Arduino boards, espressif32 , atmel avr, stm32, etc.). The PlatformIO IDE is used as an extension to the VS Code source code editor and is useful for large-scale and complex embedded firmware development for microcontrollers.

Install PlatformIO in VSCode
First, we need to install PlatformIO in VSCode via extension.

vscode extension

Then search for PlatformIO and install it.

installation platform

The PlatformIO installation process will begin.

installation platform

This may take a while. Restart the visual studio code IDE after installation.

After restarting, find the PlatformIO IDE icon as shown below and click on it to start the IDE.

platformio ide icon

Then from the PlatformIO IDE, click Open and then New Project as shown below.

new platform project

Then enter some name for your project such as "Arduino_LED_Blink", select Arduino Uno (or select your board by typing in search) as your board, frame (selected automatically), and save in the default location or uncheck the location box and provide the directory where you want to save the project. Then click Finish, and the project is created.

Create a platformio project

After creating the project, you will see the project tree. In the project tree, click the src folder icon, then click main.cpp. The main.cpp file will open in a code editor. main.cpp contains the minimal code needed to program using the include <Arduino.h> statement and the standard Arduino sketch functions setup() and loop().

new program code file

Then write the LED blinking program.

LED Blinking Program

The LED blinking program code is provided below.

#include <Arduino.h>

void setup() {
    
    
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(7,OUTPUT);
}

void loop() {
    
    
  // put your main code here, to run repeatedly:
  digitalWrite(7, HIGH);
  delay(200);
  Serial.println("HIGH");
  digitalWrite(7, LOW);
  delay(200);
  Serial.println("LOW");
}

The next step is to compile the code and upload it to the Arduino. At this point Arduino will be connected to PC/Laptop via USB cable. The following shows where the compile, upload and serial monitor buttons are located in the PlatformIO IDE.

PlatformIO compile upload and serial port monitoring button

Click the compile or compile and upload button to compile and upload the LED blinking program code to the Arduino board. After uploading the code, you will see "avrdude done. Thank you." The message is as follows.

Complete the upload in platformio ide

You can also see messages displayed on the serial monitor. The button to open the serial monitor in the PlatformIO IDE is located as described above. Click on it and you should see a message printed on the Arduino PlatformIO IDE serial monitor as shown below.

insert image description here

As shown above, the PlatformIO serial monitor shows HIGH and LOW encoded in the LED blink program.

You should see the LED connected to pin 7 of the Arduino blink. The following video shows all the process of installing PlatformIO IDE in Visual Studio Code (VS Code), writing Arduino programs, compiling and uploading firmware to Arduino Uno, using the Arduino PlatformIO serial monitor and blinking the LEDs on the Arduino Uno board.

Tutorial Summary
In this tutorial, we have covered the process of setting up an Arduino LED blinking project using the VS Code PlatformIO IDE. We discussed how to install the PlatformIO extension in VS Code, how to connect an Arduino board, and how to write code to blink an LED. We also explain the basic digital electronics concepts and the Arduino programming language used in this project. By the end of this tutorial, readers should have a solid understanding of how to set up and execute an Arduino LED blinking project using the VS Code PlatformIO IDE, and have a foundation for building more complex projects.

If you are interested in using PlatformIO IDE as a programming IDE for NodeMCU, please refer to the tutorial NodeMCU PlotformIO IDE LED Blinking.

Guess you like

Origin blog.csdn.net/m0_46509684/article/details/128945683