feature image for blog post on setting up PlatformIO within Microsoft Visual Studio Code for editing Marlin firmware

Setting up PlatformIO for Marlin Firmware


Without a doubt Setting up the Marlin firmware editor PlatformIO isn’t the most logical for newcomers. Especially as a requirement is to run PlatfomIO via the Microsoft Visual Studio Code software. Nonetheless this guide will see you through the initial steps of setting up PlatformIO to edit the Marlin 2 firmware.

Whereas previously I have included the topic of installing PlatformIO for each mainboard installation. However there is only so many times you can wright about the same subject. Consequentially it is time to restructure certain components within newer articles. Hopefully the result will make the 3D printing guides easier to find and follow along.

Setting up PlatformIO for Editing Marlin Firmware
Software Downloads
Microsoft Visual Studio Code
Installing PlatformIO within Microsoft Visual Studio Code for Linux, PC and Mac
Loading Marlin into PlatformIO
What files need editing?
platform.ini

Software Downloads

Without a doubt to begin editing the Marlin firmware for your 3D printer you are going to need the right tools. Moreover when it comes to updating the Marlin firmware on the 3D printer, we need an editor. Furthermore this comes in the form of PlatformIO which is a Integrated Development Environment. Specifically this has many uses including editing firmware. However PlatformIO is not a standalone application, instead it requires another program to operate and that is Visual Studio Code by Microsoft.

Microsoft Visual Studio Code

logo of Microsoft Visual Code required for PlatformIO ignorer to edit Marlin 2 firmware for 3D printers.

Fortunately Microsoft Visual Code works on Linux, Mac and PC Operating Systems. Firstly let’s begin by downloading the software from https://code.visualstudio.com. Once the Microsoft Visual Studio Code software is downloaded it is usually installed the same way as any other software on your computer.

Installing PlatformIO within Microsoft Visual Code

As previously mentioned PlatformIO is not a standalone app and needs installing within Microsoft Visual Studio Code (MVSC). If you haven’t already done so install and launch the MVS application.

screenshot of Microsoft visual studio code installing the platformio plugin

Once MVSC is loaded, on the left hand side is a tool bar. Specifically there is an icon that looks like building blocks, click on the icon. Consequentially a search bar will appear, click on it and type in PlatformIO. A list will now be shown of suggested plug-ins, click on the PlatformIO IDE icon. As a result an extension page will open to the right of the PlatformIO IDE icon, click on the install button.

Sometimes the install can take a little while to download and configure itself. However it does give us an opportunity to download the latest version of Marlin 2 firmware for your 3D printer.

A point of note, do not close Microsoft Visual Studio Code while the PlatformIO IDE is installing and configuring itself.

Download Marlin 2 Firmware

Logo for the open-source Marlin 3D printer firmware

Whereas we need to begin by downloading the open-source Marlin 2 firmware for 3D printers. However you have a choice of two locations from which to download it from.

Marlin Firmware Website

Firstly there is the Marlin website https://marlinfw.org/meta/download/ where you would want to select the Latest Release. It is also worth having a look around the Marlin firmware website with useful topics such as the help section on G-Codes, Commands, and what they do.

Marlin Github

Alternatively there is the Marlin Github repository https://github.com/MarlinFirmware/Marlin, which stores different firmware versions. But the most useful part of the GitHub is that you can see a list of potential issues and problems that others maybe experiencing. Furthermore if they have fixed an issue this is released into a bug fix until updated into the next major build.

screenshot of the code icon used to download the Marlin firmware

Importantly to download the latest release click on the green Code icon followed by download ZIP.

screenshot of how to select the marlin firmware bug fix version on GitHub

But if you wanted to download the latest bug fix version because of a specific issue. Then click on the 2.0x icon which cascades downwards and select bugfix-2.0, followed by the green Code icon. Finally click download ZIP.

Importantly with the Marlin 2 firmware downloaded extract and move the files to a safe location. Such as My Documents on a PC. However if you are using a cloud based folder such as on an Apple Mac, this can cause issues with the firmware compiling correctly.

Moreover space is saved by removing the files from the computer and storing them online. But when compiling the Marlin firmware the files can not be downloaded fast enough and give unexpected error messages. Thus its is better to place the folder and files into a folder that is not used by a cloud based system. For example the Pictures folder on an Apple Mac.

Loading Marlin into PlatformIO

Presumably at this point the PlatformIO has finished configuring itself within Microsoft Visual Studio Code. Importantly before we go any further close the MVSC application completely and restart the MVSC again. This ensures everything is freshly loaded from the new PlatformIO installation.

screenshot of platformio welcome screen with import new project

While the Microsoft Visual Studio Code (MVSC) is quick to load, sometimes PlatformIO can take a bit longer and may appear not to be working. However be patient and give it a little longer and it will load.

Despite this, when the PlatformIO plugin is loaded, click on the Ants head icon on the toolbar on the left hand side. As a result a welcome to PlatformIO screen will appear. Importantly to import the freshly downloaded Marlin firmware click on Open Project.

screenshot of the file explorer in platformio used to import new project

A new window will now be displayed on the screen. Furthermore this window allows you to find the Marlin 2 firmware folder that you recently downloaded. Moreover search and locate the Marlin firmware folder. Once you have found the folder double click on it to go inside. Furthermore you will notice a file called platformio.ini and that the Open button has changed to blue. Begin importing the Marlin 2 firmware by clicking on the Open button.

screenshot of platformio collapsed folder structure

Importantly in order to find you freshly imported Marlin 2 files you can use the icon resembling sheets of paper. However if the files are not visible then click on the folder name such as Marlin 2 and the folder will expand, Revealing the files.

What files need editing?

In general there are three files that need editing for Marlin firmware. However on the odd occasion there may be an additional one or two files that are specific to the 3D printers mainboard.

Furthermore I have listed the location of the three main files below for quick reference.

  • Marlin-2.0.x/platformio.ini
  • Marlin-2.0.x/Marlin/Configuration.h
  • Marlin-2.0.x/Marlin/Configuration_adv.h

platform.ini

screenshot of platformio and the platformio.ini file within Microsoft visual code, setting the environment build for marlin 2 firmware for the SKR E3 Turbo as env_default = LPC1769

Nonetheless lets begin with the first file platformio.ini, which should be visible in the explore file list. For the most part there is only a single line that needs changing within the platformio.ini file. Importantly this sets the additional libraries of code required for the mainboard.

For example the image above shows the default_envs changed from mega2560 to LPC1769 for use with 3D printer mainboards that use the LPC1769 chipset. Such as the SKR V1.4 Turbo and SKR E3 Turbo. Importantly to check what environment to select, check with the manufacture of the mainboard.

default_envs = LPC1769

Well that’s great, you have downloaded and installed Microsoft Visual Studio Code and installed the plugin PlatformIO. As a result you can now edit the Marlin 2 firmware that you have just imported into PlatformIO

If you found this guide useful, please consider a donation to help keep the Make ‘N’ Print website running. For further information please have a look at our support us page

Thank You


© 2019-2021 Copyright - All Rights Reserved.