-
Notifications
You must be signed in to change notification settings - Fork 2
Setting up Work Environment
To develop and write programs on Raspberry Pi or (other single board computers), it would be convenient to edit, debug, and run the target code directly from your laptop or personal computer, without having to connect a mouse/keyboard and monitor to your Pi.
Of course one quite popular approach is to use SSH but it has several shortcomings for development:
- To move files back and forth, you have to use
scp
(secure copy) which can slow down the workflow - You are limited to using
vi/vim
,nano
,emacs
for writing/editing your code - You don't get the full advantage of a debugger / IDE
- You can keep your GitHub credentials (private key) on your local machine
This tutorial specifically focuses on the Raspberry Pi 4 (Raspbian OS, 32 and 64-bit) and explains how you can streamline your work environment by using Visual Studio Code and a plug-in called Remote-SSH. With this setup, you do not need to connect a separate mouse/keyboard/monitor to your Raspberry Pi, and you can use your laptop (Mac/Windows/Linux) to write, edit, debug, and run your programs on Raspberry Pi (even remotely) with full capability of VS Code IDE.
We found this workflow so convenient at Ubo that we ended up adopting it as our main way of coding and running our code on Ubo Pods.
In this section, we walk you through the steps to setup and configure this environment.
Visual Studio Code (VS Code) is a popular, free, open-source code editor developed by Microsoft. It has quickly become one of the most popular code editors in the developer community due to its ease of use, powerful features, and extensive customization options.
To setup VS Code on your machine, download the installer for your target operating system from here.
Once download is completed, follow the instructions posted here to install and run VS Code.
The Remote SSH plug-in provided in Visual Studio Code allows you to work with a remote machine or device as if it were your local machine.
This means that you can edit, debug, and run code on a remote machine or device using the same interface and tools that you would use on your local machine (e.g. your laptop). You can access the remote file system and copy or move files easily between machines.
The plug-in works by establishing a secure SSH connection between your local machine and the remote machine or device.
To use the Remote SSH plug-in, you will need to have SSH access to the remote machine or device.
Install the plug-in in Visual Studio Code and configure it to connect to the remote machine or device.
data:image/svg+xml,%3csvg%20xmlns=%27http://www.w3.org/2000/svg%27%20version=%271.1%27%20width=%2730%27%20height=%2730%27/%3e
-
Open Visual Studio Code on your development host machine.
-
Install the Remote SSH extension by clicking on the Extensions icon on the left-hand side menu, searching for "Remote SSH" in the search bar, and clicking on "Install" for the extension by Microsoft.
-
Once the extension is installed, click on the "Remote Explorer" icon in the left-hand side menu, then click on the gear icon at the top of the Remote Explorer panel and select "Add SSH Host..." from the dropdown menu.
-
In the "Add Remote Connection" dialog that appears, enter the hostname or IP address of your target device (e.g. Raspberry Pi 4), and select "SSH" as the connection type. If you have set up SSH key-based authentication, select "Open Config File" and enter the path to your SSH config file. Otherwise, enter your username and password for the target device.
-
Once you've entered the necessary information, click "Connect" to establish the SSH connection. You should see the target device appear in the Remote Explorer panel.
-
To open a folder on the target device, right-click on the device in the Remote Explorer panel and select "Connect to Host...", then select the folder you want to open.
-
Once you've opened a folder on the target device, you can edit files and folders as you would on your development host machine. Any changes you make will be reflected on the target device.
-
To disconnect from the target device, right-click on the device in the Remote Explorer panel and select "Disconnect from Host".
That's it! You can now use the Remote SSH extension on Visual Studio Code to develop on your target device remotely. This can be useful for debugging, testing, and deploying code on devices with limited resources, such as the Raspberry Pi 4.
- Visual Studio Code. (2021). Retrieved from https://code.visualstudio.com/ This is the official website for Visual Studio Code, maintained by Microsoft. It provides detailed documentation, tutorials, and resources for using VS Code.
- Brown, B. (2020). Visual Studio Code: The Ultimate Guide. Packt Publishing Ltd. This book provides a comprehensive guide to using Visual Studio Code, including installation, customization, and advanced features. It is a great resource for both beginners and experienced developers.
- Thomsen, F. (2021). Visual Studio Code: A Complete Guide for Beginners. Skillshare. This online course is designed for beginners who want to learn how to use Visual Studio Code for web development. It covers basic features such as code editing and debugging, as well as more advanced topics such as extensions and plugins.