Migrating from Arduino IDE to Visual Studio Code to PlatformIO

Like every other beginner on ESP8266 I started with my first steps in the official Arduino IDE. I was impressed by the simplicity and easy to use examples that were build-in to the UI. Also the simple UI made it easy to start in uncharted land, especially for someone that did never develop embedded firmware. The library manager let me install additional libraries to play around with, and it also mostly worked.

Standard Arduino Editor (IDE)

Needless to say, I missed a lot of the features that I was used to from more powerful IDE's like IntelliJ or Visual Studio. I think even Visual Basic 6 had a better IntelliSense support than the Arduino IDE. In fact, Arduino IDE has none. Also, the lack of a dependency management (for libraries) makes it really hard to share code between multiple peers, as you have to manually install the correct version of a library in the global libraries folder. Guess what happens if you use different versions?

But overall the Ardunio IDE is a good place to start, and I'm still using it to play around with small Sketches or to validate vanilla implementations.

 What I like  What I missed
  • Low barrier, easy to start
  • Reference implementation
  • No auto completion
  • no code navigation
  • basic compilation logs
  • support for multiple files is limited
  • dependency manager

Moving to Arduino Extension for Visual Studio Code

Clearly it was not enough for the project I was about to start, Ondo (GitHub). Therefore I moved over to Visual Studio Code with the Arduino and C++ Extension, provided by Microsoft. It was a major improvement. IntelliSense, code completion and code navigation worked (most of the time, see later). The migration was rather smooth and I enjoyed the integrated development environment. The extension is still under active development and uses the Arduino IDE and its compiler under the hood.

Visual Studio Code with Arduino Extension. Not all squiggles are errors.

Features I used the most were compile and upload (Ctrl+Alt+U on Windows machines) and analyzing debug output with the built in serial monitor. Developing with Azure IoT is even more fun, because there is a Extension which allows you to monitor the device channel inside Visual Studio Code. 

While the Arduino Extension for Visual Studio Code profits from a lot of the Visual Studio Code itself, it still depends on the Arduino IDE. This means, that the major limitations of the Arduino IDE are still present. In addition to that, the Ardunio/C++ extension maintains its own list of includes, which you have to maintain as well, or you get errors in the VSCode but Arduino is still able to compile (and vice-versa). 

I also experienced a couple if annoying issues, like the most recent one: It always opens the Arduino Extension with the README.md and the Examples Page when you plug in a compatible device to your computer - even if you are working on a web project. 

Another great source of annoyance is the directory layout which you strictly have to follow. Your source files simply cannot live next to the ino-File and you have to place them under a src-Folder. The folder lib also has some special meaning and putting files over there will also impact the build. It might not be fault of the Arduino Extension, but rather an design decision of the Arduino tool chain to be fair. 


 What I like What I disliked
  • (Almost) Professional IDE for Arduino
  • Integrated Library Manager (based on the Arduino one)
  • More compilation output
  • Extensibility with other extensions in VS Code
  • Broken code navigation at times when includes are not in sync between VS Code and Arduino
  • weird directory restrictions
  • No support for data folder and image generation and upload
  • No support for Arduino IDE Plugins (like the Exception Decodes for ESP8266 an ESP32)
  • At times unstable due to active development
  • Not as fast as it should, as the Arduino build chain often is recompiling too much of the source 

Moving to PlatformIO

The things that I dislike grew and so I decided to give another plugin a shot: PlatformIO. I actually installed it already earlier but the distracting Icon and the additional menu bar in Visual Studio Code prevented me from immediately falling in love with this extension. I also realized that there might be a significant learning curve and investment to convert existing projects to be compatible with this extension, as it does not support Arduino Sketches (ino-Files).

Platform IO Extension. UI feels a bit alien to the rest of VS Code

Since I recently started with a new project (Skype Notifier on GitHub), I decided to give it another try. The extension is built as an extension to VS Code but it also supports Atom as the underlying editor. It also uses the same C++ Extension from Microsoft as the Arduino Extension is using. But as far as I could observe it completely bypasses the Arduino IDE. That's not that much of a surprise because it does support Arduino and even other embedded frameworks like RTOS. PlatformIO does handle library dependencies, and does install the necessary framework dependencies and tools also, like the Arduino Source and the Espessif tool chain to flash devices, etc.

Existing Arduino projects (Sketches/Ino-Files) can be imported but need some manual adjustments. The tool provides a lot of support during that process, usually by printing URLs to related articles that show how to solve that issue. It also comes with a library manager that's worth the name. Dependencies can be specified on a project basis and even GitHub links are supported! Yay!

I was able to set up my project including all the libraries I needed, except one: log4esp. There seems to be a caching bug somewhere, which prevented me from installing the application, because the framework did not match. Strangely the framework value on GitHub was correct, but the version installed by PlatformIO was not. Luckily I was able to solve that by referencing the library as a link pointing to the GitHub repository.

A great improvement is the integrated data upload and the extend of configuration possibility. It really feels like an integrated development environment. Builds are faster than on Arduino and Visual Studio Code. The log output is even more detailed, including showing warnings from the last build in your editor. The tool chain does only re-compile change files, unless you change the project settings. 

The only thing that is slower then in the Arduino Extension is the Serial Monitor. It can take up to five seconds to show the output from the console. Depending on how you run it, it blocks the serial port, which causes the upload process to fail more often.
  
 What I like  What I disliked
  • Mature and Professional Integrated Development Environment
  • Pure C++, no ino-files that require special pre-processing
  • Fast, partial build
  • Integrated data partition upload
  • Powerful and extensive documentation
  • Support for Arduino and other frameworks
  • Library and dependency manager
  • Fast builds
  • Integrated Exception Decoder for ESP8266 and ESP32
  • Learning curve
  • Somehow alien and less integrated to VS Code than other extensions
  • Non-Intuitive way to edit project settings in UI

The good thing about all Visual Studio extensions is that they can be enabled or disabled per project. Means you don't need to migrate all your projects to PlatformIO, you can use the Android Extension and PlatformIO at the same time, just for different projects.

Comments

  1. Dear Michael,

    Thanks for the great blog post, honest review, and kind words about PlatformIO! Please note that you can hide the PlatformIO icon from the sidebar and PlatformIO menu from the status bar. Just do "Right Click" on icon or menu and hide them :)

    Happy coding with PlatformIO!

    ReplyDelete
    Replies
    1. Thank you PlatformIO for your feedback and thanks for the suggestion. Was not aware that icons can be hidden from the sidebar!

      My confusion came from the fact that only the status bar is entirely scoped to the current project. When I open the PlatformIO extension, i get both project specific content, like the Project Tasks and general functionality like the Platform IO Home screen on the right. The Quicklinks are again special, they link to project related tasks and to general Platform IO functionality.

      As for the project settings that flow is therefore not entirely consistent. To open the editor, I had to open the "general" Platform IO extension, Navigate to the projects, and then open the project again. There might be a better way to do that thou :)

      Delete
    2. You can control all these things from PlatformIO IDE Extension Settings: https://docs.platformio.org/en/latest/integration/ide/vscode.html#settings

      - platformio-ide.activateOnlyOnPlatformIOProject
      - platformio-ide.disableToolbar

      So, extension will not be loaded if you work on non-PlatformIO project.

      Delete
  2. Hi Michel,

    What do you think about Arduino IDE Pro? It´s a interesting choice?
    What´s the pros and against?

    ReplyDelete
    Replies
    1. Haven't heard about the Pro Version of Arduino IDE till now, and found it over here
      * https://github.com/arduino/arduino-pro-ide
      * https://www.arduino.cc/pro/arduino-pro-ide

      It seems that it is under heavy development and not yet ready for production or even hobby usage, but haven't tested it so far. Seems that it is based on Theia and could become a strong competitor to PlatformIO, depending on the roadmap they have. I would like to see a vision and roadmap for their product, to better understand what the target workloads and audience of the IDE will be.

      Delete
  3. The Arduino Pro IDE needs a lot of work still ... especially the library management. VSCode with PlatformIO ... and an ESP-Prog is awesome !

    ReplyDelete

Post a Comment