Upload Arduino Sketch Through Visual Studio and Windows 10 Iot

Larn how to program the ESP32 and ESP8266 NodeMCU boards using VS Code (Microsoft Visual Studio Code) with PlatformIO IDE extension. Nosotros cover how to install the software on Windows, Mac OS 10 or Ubuntu operating systems.

Getting Started with VS Code and PlatformIO IDE for ESP32 and NodeMCU ESP8266 boards: Windows, Mac OS X, Linux Ubuntu

The Arduino IDE works great for pocket-sized applications. Yet, for avant-garde projects with more than 200 lines of code, multiple files, and other advanced features similar auto completion and fault checking, VS Lawmaking with the PlatformIO IDE extension is the best culling.

In this tutorial, we'll cover the post-obit topics:

  • Installing VS Lawmaking (Visual Studio Lawmaking):
    • A) Windows
    • B) Mac Bone X
    • C) Linux Ubuntu
  • Installing PlatformIO IDE Extension on VS Code
  • Visual Studio Quick Interface Overview
  • PlatformIO IDE Overview
  • Uploading Code using PlatformIO IDE: ESP32/ESP8266
  • Irresolute the Serial Monitor Baud Charge per unit – PlatformIO IDE
  • Installing Libraries on PlatformIO IDE

A) Installing VS Code on Windows (Visual Studio Code)

Become to https://code.visualstudio.com/ and download the stable build for your operating system (Windows).

Microsoft Visual Studio Code VS Code Download Page for Windows PC

Click on the installation wizard to start the installation and follow all the steps to complete the installation. Accept the agreement and press the Next push.

Microsoft Visual Studio Code VS Code Installation wizard

Select the following options and click Adjacent.

Microsoft Visual Studio Code VS Code Installation wizard step 2

Press the Install button.

Microsoft Visual Studio Code VS Code Installation wizard step 3

Finally, click Finish to finish the installation.

Microsoft Visual Studio Code VS Code Installation wizard final step

Open up VS Code and you'll be greeted by a Welcome tab with the released notes of the newest version.

Microsoft Visual Studio Code VS Code Installation wizard welcome screen on a Windows PC

That'south it. Visual Studio Code was successfully installed.

Installing Python on Windows

To plan the ESP32 and ESP8266 boards with PlatformIO IDE yous demand Python 3.v or higher installed in your computer. We're using Python 3.8.five.

Go to python.org/download and download Python 3.8.5 or a newest version.

Open the downloaded file to start the Python installation magician.

The following window shows upwards.

Installing Python 3.8.5 on a Windows PC and Add to Path

IMPORTANT: Make sure you lot bank check the option Add Python 3.eight to PATH. Then, y'all tin click on the Install Now button.

When the installation is successful you'll get the following message.

Python Installation successful on Windows PC

You lot can click the Close button.

Now, go to this section to install PlatformIO IDE extension.


B) Installing VS Lawmaking on Mac OS X (Visual Studio Lawmaking)

Go to https://code.visualstudio.com/ and download the stable build for your operating system (Mac OS X).

Microsoft Visual Studio Code VS Code Download Page for Mac OS X

Later downloading the Visual Studio Code application file, you'll be prompted with the following message. Press the "Open" button.

Microsoft Visual Studio Code VS Code Downloading application file for Mac OS X

Or open your Downloads folder and open up Visual Studio Code.

Microsoft Visual Studio Code VS Code Downloading application file for Mac OS X

After that, y'all'll be greeted past a Welcome tab with the released notes of the newest version.

Microsoft Visual Studio Code VS Code Installation wizard welcome screen on Max OS X

That's information technology. Visual Studio Code was successfully installed.

Installing Python on Mac OS X

To plan the ESP32 and ESP8266 boards with PlatformIO IDE you demand Python 3.5 or higher installed in your figurer. Nosotros're using Python 3.8.five.

To install Python I'll exist using Homebrew. If you don't have the mash control bachelor, blazon the next command:

          $ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"                  
Microsoft Visual Studio Code VS Code installing homebrew

And then, run the brew control to install Python three.X:

          $ brew install python3        
Microsoft Visual Studio Code VS Code installing Python 3 with brew command

At present, go to this department to install PlatformIO IDE extension.


C) Installing VS Code on Linux Ubuntu (Visual Studio Code)

Get to https://code.visualstudio.com/ and download the stable build for your operating system (Linux Ubuntu).

Microsoft Visual Studio Code VS Code Download Page for Linux Ubuntu

Salvage the installation file:

Microsoft Visual Studio Code VS Code Save installation file for Linux Ubuntu

To install information technology, open a Final windows, navigate to your Downloads folder and run the following command to install VS Code.

          $ cd Downloads ~/Downloads $ sudo apt install ./code_1.49.1-1600299189_amd64.deb        

When the installation is finished, VS Code should be available in your applications menu.

Microsoft Visual Studio Code VS Code Open application Linux Ubuntu

Open VS Code and yous'll be greeted by a Welcome tab with the released notes of the newest version.

Microsoft Visual Studio Code VS Code Installation wizard welcome screen on Linux Ubuntu

That's it. Visual Studio Lawmaking was successfully installed.

Installing Python on Linux Ubuntu

To program the ESP32 and ESP8266 boards with PlatformIO IDE you need Python 3.5 or higher installed in your computer. We're using Python 3.8.

Open the Terminal window and check that you already have Python 3 installed.

          $ python3 --version python 3.eight.2                  
Linux ubuntu installing Python3 testing version

Every bit you lot tin run into in the preceding figure, Python iii.8.2 is already installed.

If you don't have Python 3.eight.X installed, run the next control to install it:

          $ sudo apt install python3        

Whether you already accept Python installed or not, you need to run the following control to install Python utilities.

          $ sudo apt install python3-distutils        
Installing python3-distutils Linux Ubuntu for PlatformIO IDE

Now, go to this department to install PlatformIO IDE extension.


Installing PlatformIO IDE Extension on VS Code

It is possible to program the ESP32 and ESP8266 boards using VS Code with the PlatformIO IDE extension. Follow the next steps to install the PlatformIO IDE extension.

Open up VS Code:

  1. Click on the Extensions icon or press Ctrl+Shift+X to open up the Extensions tab
  2. Search for "PlatformIO IDE"
  3. Select the showtime option
  4. Finally, click the Install button (Note: the installation may take a few minutes)
Install PlatformIO IDE Extension on VS Code

Later on installing, make certain that PlatformIO IDE extension is enabled as shown beneath.

PlatformIO IDE Extension Enabled on VS Code

After that, the PlatformIO icon should show up on the left sidebar every bit well equally an Home icon that redirects you to PlatformIO dwelling house.

PlatformIO Extension Installed Successfully

That's it, PlatformIO IDE extension was successfully added to VS Code.

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 consequence.

Either way, nosotros recommend restarting VS Code earlier proceeding.

VS Code Quick Interface Overview

Open VS Lawmaking. The following impress screen shows the meaning of each icon on the left sidebar and its shortcuts:

VS Code Visual Studio Application Interface Overview
  • File explorer
  • Search across files
  • Source code management (using gist)
  • Launch and debug your code
  • Manage extensions

Additionally, you tin can press Ctrl+Shift+P or become to View > Command Palette… to show all the available commands. If yous're searching for a command and y'all don't know where it is or its shortcut, you merely demand to go to the Command Palette and search for it.

At the bottom, in that location's a blue bar with PlatformIO commands.

PlatformIO IDE extension Quick Tools Icons

Here's the what icon does from left to correct:

  • PlatformIO Home
  • Build/Compile
  • Upload
  • Clean
  • Serial Monitor
  • New Final

If you lot hover your mouse over the icons, it will show what each icon does.

Alternatively, you lot can also click on the PIO icon to see all the PlatformIO tasks.

PlatformIO IDE extension Tasks menu

If the tasks don't show upwardly on your IDE when you click the icon, you may need to click on the three dot icon at the peak and enable PlatformIO tasks every bit shown below.

Enable PlatformIO IDE extension tasks

PlatformIO IDE Overview

For you lot to get an overview on how PlatformIO works on VS code, we'll show y'all how to create, relieve and upload a "Blinking LED" sketch to your ESP32 or ESP8266 lath.

Create a New Project

On VS Code, click on the PlartfomIO Home icon. Click on + New Project to offset a new project.

Create New Project PlatformIO VS Code

Give your project a name (for example Blink_LED) and select the lath yous're using. In our case, we're using the DOIT ESP32 DEVKIT V1. The Framework should be "Arduino" to use the Arduino cadre.

Y'all tin can choose the default location to salve your project or a custom location.

The default location is in this path Documents >PlatformIO >Projects. For this test, you lot tin can use the default location. Finally, click "Cease".

PlatformIO with VS Code Create New ESP32 Project

For this instance, we'll exist using the DOIT ESP32 DEVKIT lath. If you are using an ESP8266 NodeMCU lath the process is very similar, y'all just need to select your ESP8266 lath:

PlatformIO IDE extension with VS Code Create New ESP8266 Project

The Blink_LED projection should exist accessible from the Explorer tab.

PlatformIO IDE Extension Project Folder Structure

VS Code and PlatformIO have a folder structure that is different from the standard .ino project. If you click on the Explorer tab, you lot'll see all the files it created under your project binder. It may seem a lot of files to work with. But, don't worry, normally you'll but need to bargain with i or two of those files.

Warning: you lot shouldn't delete, modify or move the folders and the platformio.ini file. Otherwise, you will no longer be able to compile your project using PlatformIO.

platformio.ini file

The platformio.ini file is the PlatformIO Configuration File for your projection. It shows the platform, lath, and framework for your project. You can also add together other configurations similar libraries to be included, upload options, changing the Serial Monitor baud rate and other configurations.

PlatformIO IDE extension Configuration File for ESP32
  • platform: which corresponds to the SoC used by the board.
  • board: the development lath you're using.
  • framework: the software environment that will run the project code.

With the ESP32 and ESP8266, if y'all want to use a baud rate of 115200 in your Serial Monitor, y'all just need to add the following line to your platformio.ini file.

          monitor_speed = 115200        

Later on that, make sure y'all relieve the changes made to the file past pressing Ctrl+S.

In this file, you can also include the identifier of libraries yous'll utilize in your project using the lib_deps directive, as we'll see later.

src binder

The src folder is your working folder. Under the src folder, there'southward a main.cpp file. That's where you write your code. Click on that file. The structure of an Arduino program should open with the setup() and loop() functions.

PlatformIO IDE extension main.cpp file under src folder

In PlatformIO, all your Arduino sketches should start with the #include <Arduino.h>.

Uploading Lawmaking using PlatformIO IDE: ESP32/ESP8266

Copy the post-obit lawmaking to your main.cpp file.

          /*********   Rui Santos   Complete project details at https://RandomNerdTutorials.com/vs-code-platformio-ide-esp32-esp8266-arduino/ *********/  #include <Arduino.h>  #ascertain LED ii  void setup() {   // put your setup code hither, to run once:   Serial.begin(115200);   pinMode(LED, OUTPUT); }  void loop() {   // put your chief lawmaking here, to run repeatedly:   digitalWrite(LED, HIGH);   Serial.println("LED is on");   filibuster(1000);   digitalWrite(LED, LOW);   Serial.println("LED is off");   filibuster(1000); }                  

View raw lawmaking

This code blinks the on-board LED every 2nd. It works with the ESP32 and ESP8266 boards (both have the on-board LED continued to GPIO 2).

We recommend that you copy this code manually, and then that y'all run into the autocompletion and other interesting features of the IDE in action. Additionally, if you have a syntax error somewhere in your program, it will underline it in scarlet even before compiling.

After that, press Ctrl+S or go to File > Save to save the file.

Now, yous can click on the Upload icon to compile and upload the code. Alternatively, y'all tin go to the PIO Projection Tasks menu and select Upload.

Upload Code ESP32 board PlatformIO VS Code Visual Studio

If the code is successfully uploaded, you should get the following message.

Upload Code to ESP32 PlatformIO VS Code Success

After uploading the code, the ESP32 or ESP8266 should be blinking its on-board LED every second.

ESP32 board Built in LED turned on HIGH

At present, click on the Serial Monitor icon and you should see it printing the current LED state.

PlatformIO IDE VS Code Visual Studio Serial Monitor ESP32 board

Note: if you lot don't see the Terminal window, get to the carte du jour Terminal > New Last.

Detect COM Port

PlatformIO will automatically observe the port your board is connected to. To bank check the connected devices you can go to the PIO Dwelling house and click the Devices icon.

PlatformIO IDE extension VS Code Visual Studio Connected Devices COM Port Serial

Troubleshooting

If when trying to upload code you lot become the following error: "Failed to connect to ESP32: Timed out waiting for packet header" it usually ways that your board is not in flashing mode when you're uploading the code.

When this happens you lot need to press the ESP32 on-lath BOOT push button when you start seeing a lot of dots in the debugging window.

If you lot don't want to take to press the Kicking button every fourth dimension you lot upload new code, yous can follow this guide: [SOLVED] Failed to connect to ESP32: Timed out waiting for packet header.

Changing the Series Monitor Baud Rate – PlatformIO IDE

The default baud rate used past PlatformIO is 9600. However, information technology is possible to gear up up a unlike value as mentioned previously. On the File Explorer, under your projection binder, open the platformio.ini file and add together the following line:

          monitor_speed = baud_rate        

For example:

          monitor_speed = 115200        
PlatformIO IDE extesion Change Serial Monitor Baud Rate 115200

Later that, salvage that file.

Installing ESP32/ESP8266 Libraries on PlatformIO IDE

Follow the next process if y'all demand to install libraries in PlatformIO IDE.

Click the Abode icon to become to PlatformIO Home. Click on the Libraries icon on the left side bar.

Search for the library you desire to install. For example Adafruit_BME280.

PlatformIO IDE extension VS Code Visual Studio Search for BME280 Library

Click on the library you want to include in your project. So, click Add to Project.

PlatformIO with VS Code Add Library to Project

Select the project were you want to utilize the library.

PlatformIO with VS Code Add Library to Project Choose Project

This will add the library identifier using the lid_deps directive on the platformio.ini file. If you lot open your project's platformio.ini file, it should look as shown in the following paradigm.

Add Library Identifier to Configuration File PlatformIO

Alternatively, on the library window, if yous select the Installation tab and scroll a bit, y'all'll meet the identifier for the library. You can choose whatsoever of those identifiers depending on the options you want to utilize. The library identifiers are highlighted in reddish.

PlatformIO IDE Extension Library Registry menu

Then, go to the platformio.ini file of your project and paste the library identifier into that file, like this:

          lib_deps = adafruit/Adafruit BME280 [email protected]^2.one.0        

If yous demand multiple libraries, yous can carve up their name by a blackout or put them on different lines. For example:

          lib_deps =   arduino-libraries/Arduino_JSON @ 0.1.0   adafruit/Adafruit BME280 Library @ ^2.1.0   adafruit/Adafruit Unified Sensor @ ^i.i.4        

PlatformIO has a congenital-in powerful Library Manager, that allows y'all to specify custom dependencies per project in the Project Configuration File platformio.ini using lib_deps. This will tell PlatformIO to automatically download the library and all its dependencies when you save the configuration file or when you compile your projection.

Open a Project Folder

To open an existing project binder on PlatformIO, open up VS Lawmaking, go to PlatformIO Dwelling house and click on Open Projection. Navigate through the files and select your project binder.

VS Code with PlatformIO Open Project Folder

PlatformIO will open up all the files inside the project folder.

VS Code Color Themes

VS Code lets you choose between dissimilar color themes. Get to the Manage icon and select Color Theme. You can then select from several different low-cal and dark themes.

VS Code Visual Studio Change Color Themes Dark Light

Shortcuts' List

For a complete list of VS Code shortcuts for Windows, Mac OS 10 or Linux, check the side by side link:

  • VS Code Keyboard Shortcuts Reference.

Wrapping Upwards

In this tutorial you've learned how to install and prepare Visual Studio Lawmaking to work with the ESP32 and ESP8266 boards. VS Code with the PlatformIO IDE extension is a great culling to the classical Arduino IDE, especially when yous're working on more avant-garde sketches for larger applications.

Here's some of the advantages of using VS Code with PlatformIO IDE over Arduino IDE:

  • It detects the COM port your board is connected to automatically;
  • VS Code IntelliSense: Auto-Complete. IntelliSense code completion tries to approximate what you want to write, displaying the unlike possibilities and provides insight into the parameters that a part may look;
  • Error Highlights: VS Code + PIO underlines errors in your lawmaking before compiling;
  • Multiple open up tabs: you can have several lawmaking tabs open at once;
  • You tin hide sure parts of the code;
  • Advanced code navigation;
  • And much more…

If you're looking for a more advanced IDE to write your applications for the ESP32 and ESP8266 boards, VS Code with the PlatformIO IDE extension is a great choice.

We hope you've found this tutorial useful. If you lot like ESP32 and ESP8266, check the following resource:

  • Learn ESP32 with Arduino IDE (eBook + course)
  • Domicile Automation using ESP8266 (eBook)
  • More ESP32 Projects and Tutorials…
  • More ESP8266 Projects and Tutorials…

barnhartlabley.blogspot.com

Source: https://randomnerdtutorials.com/vs-code-platformio-ide-esp32-esp8266-arduino/

0 Response to "Upload Arduino Sketch Through Visual Studio and Windows 10 Iot"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel