Just like the previous tutorial, we setup Visual Studio Code Raspberry Pi on our Mac, this tutorial describes the process of setting Visual Studio Code up on Windows for use with the Raspberry Pi.
I won’t duplicate information and state the steps to install VS Code and the plugins, they can be found here. We will jump straight into setting up a network share on our Pi so we can access it from our Windows Machine.
Setting up a Network Share
To allow Windows PCs to view shared folders on the Raspberry Pi, we must install Samba. Just like we did with Netatalk for the Mac, we will use the Raspbian apt-get package manager to do so.
First thing you want to do is log in via SSH to your Pi so we can install Samba and edit its config files.
To install Samba we need to install the package “Samba” and also an additional package known as “samba-common-bin”. Luckily, we can do this in one command (because we’re too lazy to do it twice, right?)
> sudo apt-get install samba samba-common-bin
If you are prompted to confirm install, type “Y” and hit enter.
Edit Samba Config
Unlike setting up a network share via Netatalk, we must edit the config file for Samba to tell it what folders we would like to share and what permissions we should allow.
To edit the config file simply open it in the Nano Text Editor by entering the following:
> sudo nano /etc/samba/smb.conf
Before we state what folders we want to share, we must first ensure that samba is to have Windows support enabled and to specify the workgroup our network is on.
To enable this, we must set the following:
workgroup = WORKGROUP wins support = yes
You must ensure that there is no “#” in front of these lines, as this is a comment and will result in the setting being ignored. It’s also worth mentioning that your workgroup name may differ. This guide shows you how to view the workgroup name
As an example, here are the settings on my Pi
The final step is to let Samba know what folders we want to share. To do so, simply scroll to the bottom of your file using the arrow keys on your keyboard and enter the following (changing the locations to what you require).
[pihome] # Name of share in network locations comment="share location containing code files" path=/home/pi # Location to the folder we want to share browseable=yes # Folder is visible in network writeable=yes # We can create files only guest=no # Username and password required create mask=0777 # permissions for creating files directory mask=0777 # permissions for directory public=no # remote access
Save the file by pressing “ctrl + X” then hitting “Y” to confirm.
Creating a Samba User
Unfortunately, Samba doesn’t use the Pis username and password by default. We have to tell Samba the username and password for the users we want to allow access. To do this, we must enter the following in the terminal
> sudo smbpasswd -a pi
It will then prompt you to enter (and again to confirm) the password for the user “pi” we just created.
Testing the Network Share
Now that we have created the shared directory and created a username and password we can go back to our windows machine and go to our network places. You should see your Raspberry Pi appear in your network. For me, my pi is called “RASPBERRYPI”
Using Visual Studio Code
Now that we have Visual Studio Code installed on our PC, and have access to the Pis home directory (where we save our scripts) we can start to edit our code!
Simply drag a file from the Raspberry Pi network share into Visual Studio Code. Any changes you make and save will be updated on the Pi itself.
Alternatively, you can open a folder from within Visual Studio code by clicking “file -> open folder” and navigating to the folder on the Pi that you want to open.