I needed to do this help a friend debug a problem he had with Marlin code. Normally I try and avoid IDE’s other than Eclipse but in this case there does not seem a great deal of integration for Eclipse with Marlin and it was more important to get bug chasing
I cam across a number of poorly documented hurdles getting this set up for Marlin (2.1). Depending on how long it is since this got published then some/all of these issues may have gone away.
Download Visual Studio Code. You need the deb package. From here: https://code.visualstudio.com/download
Once downloaded you can easily install the thing on 22.04 by right clicking on the download deb file and then select “Open with other application” then select “Software Install” and you are away.
Alternatively, you can do this on the command line with:
sudo apt install ~/Downloads/filename.deb
You should end up with an icon in your Programming dropdown from the Applications menu top left of the Gnome desktop. The icon you need to click is obviously Visual Studio Code.
Open you newly installed Visual Studio Code IDE. Click on the extensions icon in the left hand column. It looks like four boxes.
Then in the search box type in “Auto Build Marlin” Install it.
You will end up with two new icons on the left hand side. One “M” is Marlin auto build.
The one that looks like an alien is actually not yet installed. That’s next. It’s called Platformio. It needs Python. But unfortunately it wont recognise the default Python3 in Ubuntu 22.04. So we have some kerfuffling to do with Python before we can install it. But first close down Visual Studio Code.
If you open a console and type “which python” the system wont find it. That is because on 22.04 you have python3. Type “which python3” and all is well. But that does not help us with Platformio.
If you open Visual Studio Code and try installing Platform IO by clicking the alien icon. It will fail with:
PlatformIO: Can not find working Python 3.6+ Interpreter. Please install the latest Python 3 and restart VSCode.
There were two things I tried to get this working. The first may be redundant or it may be necessary to have along with the second. Either way I only got PlatformIO to install after I had done the second of these.
Close down Visual Studio Code.
The first “fix” was to install this which sorts out an alias for Python3 so it can be invoked with “Python” as well as Python3
sudo apt install python-is-python3
This though still failed with installing PlatformIO. For me it it failed with the same error message. Though now the system could access the Python interpreter as “python” as well as “python3”
This was the bit I added next and was needed to be installed before Platform IO would then itself install.
sudo apt install -y python3-venv
So what is python3-venv? It appears to be a way of creating a multiple of virtual Python environments so keeping, I think, each Python program running with its own clone of the interpreter. But whatever – that solved the problem.
When you’ve done these two installs restart Visual Studio Code and then click on the aliens head. Platform IO should install.
Now we need to set up our MARLIN code
Download it from here… https://marlinfw.org/meta/download/
The latest version for me was a bugfix level but normally I’d go for a stable level.
Unpack the downloaded zip file somewhere you want it.
Then in VSC click on the Aliens head aka open PlatformIO. It will do some initialising in the left hand column then it’ll look like this.
Click on “Pick a Folder” and point it at your Marlin code you just unzipped.
Then Platform IO will start configuring the project. There’s also, for me, an opportunity to install “Dev Containers” from Microsoft. I waited until the PlatformIO had completed configuring the project then took my life in my hand and installed the “Dev containers”. It installed and I then closed the resulting window on it. Leaving me with this…
Of course we will need to modify the config files etc in the code. But first just to make sure the whole thing works go to “AutoBuild” and click build for one of the default environments.
It built this is what I get.
At the end, if successful, it opens the newly created directory holding the new files including the “firmware.hex”.