Using Visual Studio Code With Raspberry Pi Network Share [Windows]

Introduction

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

Samba Workgroup Settings Image
Samba Workgroup Settings

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”

Raspberry Pi on Windows Network Image
Raspberry Pi on Windows Network
Upon double clicking your Pis network share, you will be prompted for a username and password. Simply enter the details you created in the “Creating a Samba User” section of this tutorial and you should then be able to see your shared locations!
Pi Shared Folders on Windows Network Image
Pi Shared Folders on Windows Network

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.

Happy Intellisense!

Using Visual Studio Code Raspberry Pi Network Share [Mac]

Introduction

This post is not describing how to run Visual Studio Code on the Pi. This post shows you how to create a network share on your Pi where your scripts reside so that you can edit them from your computer (this post is aimed at Mac users, go here to setup visual studio code for Windows).

Setup

The first thing you want to do, is ensure that you have Visual Studio Code installed on your Mac. You can install plugins you require specifically, but I recommend this Python plugin as Python is usually the goto language with Pi development.
First, update the packages that are installed on the Pi by entering the following in the terminal:
> sudo apt-get update

Creating the Network Share

To allow our Mac to see a network share on the Pi, we must first install Netatalk., To do this, we simply use the Raspbian package manager “apt-get”. Here is the command to install Netatalk
> sudo apt-get install netatalk

apt-get will start installing Netatalk upon pressing enter.

Note: You may need to press “Y” when it asks you to confirm the install.

Surprisingly, that is all there is to creating a network share on the Pi (for Mac). Some users may want to reboot their Pi at this point, although it isn’t strictly necessary.  If you would like to check that you can access the Pis files, open up Finder and go to your network locations.

You should see a computer with the name “raspberrypi” (or whatever you have called your Pi, if you had changed it’s name using raspi-config).

Raspberry Pi on Mac Network
Raspberrypi available on Mac network thanks to Netatalk

Upon double clicking the raspberrypi computer, you will need to click “connect as” in the top right corner of the Finder window.

Connect As Button Displayed
Connect As Button Displayed

This will bring up a prompt for a username and password. This is basically the user you wish to log in as. Assuming default settings, this is usually “pi” and “raspberry” as the username and password respectively.

Entering Pi Username And Password
Entering Pi Username And Password

Upon logging in, you will see the home directory of the user you are logged in as.

Using Visual Studio Code

Now that we have Visual Studio Code installed on our Mac, 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.
Happy Intellisense!