Raspberry Pi Zero 2 W + VS Code Remote = Awesome!

You remember Jim Bennett: he of Visual Studio Code (VS Code) obsession fame. Well, he got hold of our newest board and, of course, he had to try out running his favourite software on it straight away.

I love Raspberry Pi, and I love Visual Studio Code. It’s a fantastic free developer text editor, with a load of extensions that make it so nice to do all the things I love doing in my day job and when I muck around in my own time. From writing and debugging code, to configuring my cloud services.

Every time those great folks at Raspberry Pi announce new hardware, my first thought is always “will it run VS Code?” Well, not my first thought — my first thought is “where can I get one from quickly so I can play with it?” — but after that it’s “will it run VS Code?”

There are two ways that I use to run VS Code on Raspberry Pi — either installed directly running under the Raspberry Pi desktop, or connecting via the Remote SSH extension to develop remotely on Raspberry Pi from your PC or Mac. With the more powerful devices, like Raspberry Pi 400 or Raspberry Pi 4, both of these are viable options. It’s the tiny devices, Raspberry Pi Zero, that in the past haven’t been able to run VS Code with either of these two techniques. The architecture wasn’t supported, and there was no interest to support it as the boards were just not powerful enough.

Recently Raspberry Pi Zero 2 was announced. This provides a few interesting upgrades over Raspberry Pi Zero, including the use of the same processor that is in Raspberry Pi 3 — a device that has an architecture supported by VS Code.

So obviously I ordered one as soon as I could to test out VS Code.

Test 1: install VS Code as a desktop app

My first test was to install the full desktop version of Raspberry Pi OS and see how well VS Code runs as a desktop app. Installation instructions are here in the VS Code docs if you are interested.

The results were — not great. It installs and runs, but the performance is far from ideal. You could visibly see screen redraws sometimes, with menus taking a few seconds to appear. I also tried to install the Python extension, and it just hung. It’s fine for occasional use, but Raspberry Pi Zero 2 is just not really powerful enough.

This really isn’t surprising, mainly due to Zero 2’s 512MB RAM. VS Code ideally needs 1GB to run locally, and more depending on the language server being used.

Test 2: use Remote SSH

This to me was the important test. I like to use Raspberry Pi Zero in setups such as lighting, where you can’t easily connect a monitor when you want to dive in and debug code when it (inevitably) goes wrong. The limited memory on Raspberry Pi means that I wasn’t expecting VS Code to run on the desktop OS, but having the Raspberry Pi 3 chip means the architecture is supported for the Remote SSH extension, allowing me to remotely connect from my Mac to edit, debug and run code.

I re-flashed an SD card with Raspberry Pi OS Lite for headless development, powered it up and connected from VS Code. Instructions are here in the VS Code Remote SSH docs if you are interested. I always use Lite for headless development as it saves SD card space and memory usage, and boots up quicker. There’s no point in increasing the memory load for VS Code Remote with a desktop that isn’t needed.

Success! Everything worked perfectly. The SSH extension connected and installed the necessary bits and pieces on the Raspberry Pi with no issues. I opened folders, navigated around, and it felt as buttery smooth as I’ve seen from other Raspberry Pi boards.

The next test was extensions. Language extensions need a lot of memory, so how would Raspberry Pi Zero 2 cope with the Python extension? The answer is: pretty well. Took a bit longer to install than I was expecting, but otherwise no issues. It gave me all the code navigation, code completion and debugging that I use every day, with no obvious slow down.

I even tested a Python and Flask-based Tetris game and was able to run and debug this with no issues.

Brilliant board

Raspberry Pi Zero 2 is a brilliant board for the price and it works great with VS Code using the Remote SSH extension. Because of this, Raspberry Pi Zero 2 is my small-form-factor board of choice for all my IoT projects!

Nice tash, Jim

4 comments
Jump to the comment form

Avatar

I am a big fan VS Code, use this every day on a RPI to build cross platform apps in .Net Core and use it for scripting in PS core as well.
The great things about this is the you get :
Code intellisense, syntax coloring, tab completion, …
Save time and reduce errors when creating scripts.
Improve script debugging and testing.
Lot’s of extensions available

Here are a few of my projects built with help of VSC on RPI.
https://audministrator.wordpress.com/2021/11/14/powershell-core-scripting-gui-controls-widgets-possible-on-rpi/
https://audministrator.wordpress.com/2021/11/08/raspberry-pi-powershell-create-xlsx-without-excel/
https://audministrator.wordpress.com/2021/10/13/raspberry-pi-asp-net-core-web-sqlite-app/
https://audministrator.wordpress.com/2021/10/14/raspberry-pi-net-core-winforms-or-wpf-possible/
And many more …
I took it a step further not only using 1 IDE on multiple platforms but also using 1 source code for multiple platforms.

Reply to audministrator

Avatar

Thanks for posting this. It’ll save me a fair bit of time & gives me some ideas for things I’d like to try.

Reply to Graham Hughes

Avatar

So I have a problem that I don’t understand. As soon as I open the ssh remote connection from studio code, my CPU goes up to 99% and doesn’t go down anymore. Even without sending any code :( Weird :(

Reply to Mike

Avatar

Ooh nice. I’ve been doing lots of Pi0W development work and the best I could manage was WinSCP sync to keep updating files, but this looks potentially very handy, esp for Python work…

Reply to Alan

Leave a Comment