Raspberry Pis are everywhere. From the tiny new Pico microcontroller to the low-cost desktop PC that’s the Raspberry Pi 400, the ARM-based single board computer is a powerful tool that works as well in education as it does as an IoT device. Pis have been to space, track aircraft around the world, manage home media collections, run development Kubernetes clusters, and much more. If it can be done on a computer, it’ll be done on a Pi.
Microsoft’s Visual Studio Code development environment is another of those ubiquitous tools. Like the Pi, it’s everywhere, and is used for nearly everything a developer wants, from learning to code, to building and running large-scale cloud-native applications. It’s for more than Windows, with macOS and Linux versions, and for Intel and ARM processors, with tools for local and remote development.
With ARM and Linux support, Visual Studio Code is an ideal development tool for the Raspberry Pi, using either its remote development tools to work directly with headless IoT devices, or now running a full installation on a Pi hooked up to a keyboard, monitor and mouse. This makes for a flexible combination for both hobbyist and professional alike.
Visual Studio Code: Now on ARM
Microsoft has recently released a version of Visual Studio Code that runs on both ARMv7 and ARM64 Linux devices. With support for 32- and 64-bit ARM code, you can now run Code on both the 32-bit Raspberry Pi OS (recently renamed from Raspbian, as it’s no longer a direct port of Debian) and its 64-bit beta. As the Raspberry Pi 4 hardware supports ARM64, it’s now more attractive for mainstream Linux distributions, and Ubuntu 20.10 now offers an official Raspberry Pi desktop build, targeted at Pi 4 hardware with more than 4GB of memory.
The Linux ARM versions of Visual Studio Code are available in rpm, deb, and tar formats, so should install on most Raspberry Pi Linux releases. There’s even an Ubuntu Snap release, to simplify installing on 20.10. You get the full Electron-based Code editor, with support for the marketplace. Not all extensions are supported, where they need to access external Intel binaries, but most should work.
Visual Studio Code can be a demanding application; with the Electron platform it’s built on needing significant system resources. In many cases your Pi won’t have the horsepower to run the full Code user interface. You might be able to use the new Raspberry Pi 400, which is, at heart, a 4GB Pi 4 built into a keyboard, but we’d recommend using an 8GB Pi 4, with an SSD drive rather than a SD Card, for speed and storage longevity.
I’ve been using a Pi 4 as a Linux desktop, running the ARM release of Ubuntu 20.10, and installed Code on it, downloading it as a 64-bit deb package from Microsoft’s repository. You need to click through the available versions on the Code site, as the ARM64 release isn’t visible from the main screen. However, it’s a quick download that can then be installed using the familiar apt install syntax, although referencing a local deb file rather than searching the various Ubuntu and Debian repositories.
A modular editor for remote development
Another advantage of Visual Studio Code is its modular nature, which has allowed Microsoft to split it into two parts: a user interface and everything else you need to edit, manage, debug, and test code. This allows a copy of Visual Studio Code running on a PC or a Mac to connect securely to a remote device or into a container, download its core components, and edit code directly on the remote device from your PC. You don’t need virtual machines, and you can develop on ARM and Linux without leaving the familiar Windows environment.
Remote access is best considered if you’re using a Pi as an IoT device, and aren’t using a screen, or where it’s resource-limited. Using the open SSH protocol, Visual Studio Code connects to a device and sets up the appropriate secrets needed for a secure connection. Once connected it will download much of the core Code environment, so you can debug and test code directly on your Pi, using Code extensions to manage your application environment and link to source code management services like GitHub. Connections run over the familiar secure SSH protocol, for editing, for file transfer, and for terminal access to a remote device.
SEE: 10 ways to prevent developer burnout (free PDF) (TechRepublic)
A built-in terminal allows you to step outside your editing environment, to test code, to check your logs, or monitor system performance. It’s a useful way of checking code running on a Pi from a remote PC, as well as evaluating commands for use in shell scripts. The terminal can help debug setting up the remote service components on your Pi, using the Output view.
Setting up SSH on a Raspberry Pi
If you’re using Ubuntu on Raspberry Pi, you first need to set up an openssh server to use Visual Studio Code’s remote access tooling. That’s easy enough: just use the built-in package management tools to install the appropriate packages, and then use the Windows command line to ssh to your Pi to set up the appropriate keys. If you see the Raspberry Pi bash prompt, you’re ready to go.
One of my Pis runs as a headless aircraft tracker, with no monitor or keyboard. Here I have used the built-in Raspberry Pi OS (previously known as Raspbian) SSH support. This is easy enough to enable: simply add a blank file called ‘ssh’ to the boot partition of your Raspberry Pi SD card or SSD from your PC before you put the card into the device. It’ll then boot up ready to use SSH. You won’t be able to do this from a booted Pi — it needs to be done from another machine.
SEE: These are the programming languages most in-demand with companies hiring (TechRepublic)
Alternatively you can use the Raspberry Pi configuration tool to enable SSH support. Choose Interface Options and enable SSH here. However, you do need to be logged into a Pi to do this, so it won’t work for a headless appliance. In this case, you can quickly plug your Pi into a screen and keyboard to set up SSH before installing the device where you plan on using it.
Code for the Pico in Code
The Raspberry Pi Foundation’s latest device, the Raspberry Pi Pico microcontroller, is based on its own RP2040 silicon. It’s programmable in MicroPython and C/C++, with Visual Studio Code the preferred development environment for C/C++ applications. It works well with the command-line debugging tools from the RP2040 SDK, using a Raspberry Pi 4 as a development host. Code written and compiled in Code can be debugged on the Pico over a wired connection to your host Pi.
The combination of Raspberry Pi and Visual Studio Code is a powerful one. As Pis have become more capable, they’re now an alternative to desktop PCs in educational environments and a good-quality free code editor turns them into an effective development environment for teaching programming and for building your own IoT applications. Remote development tools mean you can stay in your chosen platform, whether it’s Windows, macOS, or Linux. And if you prefer, you can simply plug a Pi into a keyboard and screen and start coding.