Raspberry Pi

Coding on Raspberry Pi remotely with Visual Studio Code

Coding on Raspberry Pi remotely with Visual Studio Code raspberry pi 64
Coding on Raspberry Pi remotely with Visual Studio Code Picture3

Do you always find it hard to program and code on your Raspberry Pi? every time you need to connect it to a display, keyboard, and mouse every time?  Well, here’s the solution! After this guide, you can use only your PC for everything. Just power up your Raspberry Pi, and let your PC handle it. We’ll be using something called SSH to make this happen. But what’s SSH?

1- SSHCoding on Raspberry Pi remotely with Visual Studio Code Picture2

SSH or Secure Shell is a network communication protocol that enables two computers to communicate.

And for our luck, Raspberry Pi OS has a built-in future which allows us 

to enable SSH with simple steps.

2- Enable SSH in Raspberry Pi 

First of all, we need to open “Terminal” if we are using “Raspberry Pi OS with desktop” or just start typing the commands if we are using “Raspberry Pi OS Lite”

Enter   sudo raspi-config  This command will show you all the available options. Now with the arrows select Interfacing Options, navigate to and select SSH, choose Yes, and select Ok.

Coding on Raspberry Pi remotely with Visual Studio Code Picture4

Now we have to set our Visual Studio code.

3- Install the Extensions on VS Code

Visual Studio Code offers a lot of extensions, and to install any extension we have to click on the extensions button and then search for “Remote – SSH” and it will show up, click install to install it. 

Coding on Raspberry Pi remotely with Visual Studio Code Picture5

4- Add Raspberry Pi IP to SSH

Once you’ve successfully installed the extension, you’ll notice a new section dedicated to it. Go to this section and select the small ‘+’ button to incorporate a new host 

Coding on Raspberry Pi remotely with Visual Studio Code Picture6

5- Enter the SSH credentials

You will be prompted to provide the SSH connection command. If your Raspberry Pi is running the Raspberry Pi OS, the username is typically ‘pi’. Also, you can type “raspberrypi” instead of your IP. Once you have input the connection command, as illustrated below, press Enter.

ssh pi@raspberrypi  or  ssh pi@192.168.1.16

Coding on Raspberry Pi remotely with Visual Studio Code Picture7

6-  Select the configuration file

SSH keys need to be stored on your local file system, and VS Code will inquire about your preference for their location. I opted for the .ssh folder under my user directory, as depicted in the image.

Coding on Raspberry Pi remotely with Visual Studio Code Picture8

You will see a notification that says ‘Host added!’

7- Establish a connection with your Raspberry Pi.

You should be able to see your Raspberry Pi as listed under the ‘SSH’ on the left side. Click on the small folder icon to connect to your host.

Coding on Raspberry Pi remotely with Visual Studio Code Picture10

You’ll be prompted for the password; enter it and then press ‘Enter’.

Coding on Raspberry Pi remotely with Visual Studio Code Picture11

VS Code will ask you to select the OS of your Raspberry Pi, which is Linux, and then it will inform you that it is installing ‘VS Code Server’ on the Raspberry Pi, which is necessary for synchronization between the development environment and its file system.

Coding on Raspberry Pi remotely with Visual Studio Code Picture12

8- Navigate through your folders 

Click ‘Open Folder’ to show all your folders, then choose one to start coding in

Coding on Raspberry Pi remotely with Visual Studio Code Picture13
Coding on Raspberry Pi remotely with Visual Studio Code Picture14

Great job! You’ve successfully learned how to remotely code on a Raspberry Pi using VS Code on your computer with the Remote – SSH extension.

9-Conclusion

Time is precious in software development, whether it’s a professional pursuit or a hobby. The repetitive task of synchronizing files between systems can significantly impact your productivity. This guide will assist you in establishing an efficient and productive workflow.

Leave a Reply