Hello and welcome to today's blog post.
Our blog posts and eBooks are primarily aimed at beginners.
However, there is also a very active part of our community with highly qualified professionals, amateur radio operators, engineers, software developers, etc.
People who have been working professionally in research and development for many years, and who blindly master tools like Atmel Studio, or even voluntarily use Eclipse as a code editor.
The Arduino IDE is very suitable for getting started. Most customers start the IDE, insert a sample code via Copy & Paste, possibly adjust a few more lines, and load the whole thing onto your microcontroller.
But if you want to implement larger projects, you will quickly reach the limits of the IDE. This starts with the lack of versioning, the lack of features such as code completion, and at the latest when you are working on multiple projects that require different versions of the same library, it becomes frustrating.
Today, we would like to introduce you to probably the most popular alternative at the moment: PlatformIO.
Those who have only recently started working with microcontrollers, going to the manufacturer's side, will probably be deterred first. There is talk of 'IoT', 'ecosystem', 'frameworks'. Then comes a list of features, and overloaded screenshots.
If you haven't been deterred by it yet, and go to "Install PlatformIO Now", you'll be offered two options: Atom or VSCode.
I could imagine that many have made it to this site, and then thought "this is not for me - I prefer to stay with the Arduino IDE".
This is a pity because PlatformIO is much more powerful than the Arduino IDE.
1. The beginner
This section is intended for people who have so far programmed little or not at all, and whose preferred program for editing texts and saving screenshots is MS Word.
Maybe you're wondering why you need your own "code editor"?
On a normal PC there are usually several programs to create a text:
- Word (Office) or Writer (LibreOffice/OpenOffice)
If you want to write a letter, with letterhead, header and footer, etc., you usually resort to a word processor like Word. A word processor is a powerful tool and offers a variety of functions and options such as spell checking. It therefore makes sense for such a text document to take a word processor.
Of course, you could also write the letter in Notepad. Notepad is not a word processor, but a text editor. This is usually used to edit configuration files. However, as soon as someone tries to write a letter in Notepad, you quickly reach the limits.
The same is true of a code editor. You can easily write and save a program for the Arduino in Notepad. Here you can see the same code in both a simple text editor and in the Arduino IDE:
The most striking is the fact that the source code is displayed in color in the Arduino IDE. However, the Arduino IDE offers some practical tools that are not available in the simple text editor. It is e.g. possible to mark a text area with the mouse and to indent the entire text block with the TAB key. In the options we can also turn on line numbering and enable code folding to easily show and hide logically related sections of code such as classes or methods.
This functionality makes working with source code a lot more convenient. However, there are a variety of other editors that outshine the Arduino IDE.
2. The code editor
The range of text editors is rather confusing. When asked which is now best suited for programming your microcontroller, everyone will answer you differently. I made my first steps in programming in an editor called "vi" on Solaris. For years I was convinced that I would never need another text editor because I can do everything much faster in "vi" than in these "klickibunti" alternatives. In the meantime I am happy if I manage to edit a configuration file in the vi editor the first time without inserting an unwanted line break, daring the change and opening the file again.
Since we want to use PlatformIO, we have the choice between the Atom Editor or VSCode. Both are very popular and powerful editors. If you already use and love the Atom Editor, you will almost certainly want to stick with it and install the PlatformIO extension for Atom. For everyone who comes from the Arduino IDE I recommend installing VSCode.
There are 2 arguments I keep hearing when it comes to VSCode:
- VS stands for Visual Studio and I don't want to use Visual Studio
- VSCode comes from Microsoft
VSCode stands for Visual Studio Code and is a free, open source program. The name is somewhat unfortunate because it is a newly developed product and only shares the name with the existing Visual Studio products. Even though Microsoft tiredly laughed at the open source idea in the past and did not have the best reputation in the open source community, the company has been active in this area since 2004. A list of all open source releases is available at https://opensource.microsoft.com/. Microsoft has been actively involved in a variety of open source projects over the years.
Microsoft itself advertises the editor with the following highlights:
- it uses IntelliSense - color syntax highlighting and auto completion
- extensive debugging functions
- Version control using Git
- expandable via extensions
The first three highlights describe exactly the functions that we lack in the Arduino IDE. And the fourth highlight, the integration of extensions, enables us to use PlatformIO.
3. Installation of VSCode
First we go to the side https://code.visualstudio.com/, download the current version and install it.
After the download, we install the software. With the installation options there is nothing that you really have to consider. You can adjust it according to your wishes or always click on "Next":
After the first start, a couple of messages appear at the bottom right. The first allows the installation of a language pack. We go to "Install and Restart".
After the restart the message appears that Git is not installed. Git is a version management tool and should be installed at this point by clicking on "Download Git".
A browser window opens with the Git page. Using the link "Download 2.18.x for Windows" we can download the current version and start the installation.
There are a few options to consider when installing Git. Therefore, I document the complete installation using screenshots:
In this window, we select Visual Studio Code as the editor. If the "Next >" field remains grayed out, please go to "< Back" and then it should go further.
After restarting VSCode, the following screen should appear.
Now we have installed a powerful text editor, but it does not bring us much in its current form. When I insert my Arduino code it doesn't look much different than in the notepad.
There is no way to compile the code, install libraries, or select a microcontroller. This is where the extensions come in: PlatformIO extends VSCode with these functions.
3. Install the PlatformIO extension
There are 5 icons on the left side of the VSCode window. The lowest symbol (quadrangular) opens the panel to manage the extensions.
In the search box, we now enter PlatformIO and install the latest version of the PlatformIO IDE by clicking "Install".
After a few moments, the button changes to "Restart" . After the restart, the "Microsoft C/C++ Extension for VS Code" is automatically installed. A little patience is required here.
The message "Installing PlatformIO Core..." appears in the output. Depending on the system, the installation will take some time.
Please wait until the message "PlatformIO IDE has been successfully installed! Please reload window" appears:
After the restart, a message appears that extensions have been modified on the hard disk and are prompted to reload the window.
After a few moments, the home page of PlatformIO will appear.
Here you can start a new project, import an existing Arduino project, and see the news.
Now it's done. It wasn't that hard.
I hope today's post was a little bit of a joke in installing PlatformIO.
In a future post, we'll show you how to install libraries, and how to compile and upload your first project.
Until then, I say goodbye and wish everyone a lot of fun experimenting with PlatformIO.
Yours Markus Neumann