Getting your R-Pi Ready

  1. Get a R-Pi 4
  2. Get a Samsung Evo Plus 32Gb card
  3. Download Raspbian Buster Lite - we will keep it light by installing only what we need and since this is a headless setup anyways we dont need raspbian with desktop.

Write image to SD Card “without any external software”

  1. No need to use Rufus, balenaEtcher etc. We will use the inbuilt Disks app in Ubuntu.
  2. Insert the SD Card, open Disks, click on your SD Card on the left.
  3. Goto the 3 lines on top right and select Restore Image.
  4. From the window select your extracted raspberry buster lite image and be patient. The writing process looks like the following -
    Disks-Utility

  5. Once its done you should see, boot and rootfs in your Nautilus Sidebar -
    Boot-Rootfs

Headless Setup with WiFi

Make R-Pi connect to WiFi on boot so that we may SSH to it

There is a great documentation by the R-Pi team itself on this. Read that or follow along -

  1. Let the SD Card be in your PC.
  2. Goto boot partition
  3. In root directory create a file named wpa_supplicant.conf. When you boot, this file would be automatically moved to /etc/wpa_supplicant/ directory and Raspbian would use the settings in it to start up wireless networking
  4. Copy the following code to the file you just created, making sure to enter your ISO 3166 alpha-2 country code, WiFi network name(SSID) and WiFi password -
    • Get your country code here, select Country Code and press Search and look for your country’s code.
        ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
        update_config=1
        country=<YOUR TWO LETTER COUNTRY CODE>
      
        network={
            ssid="<YOUR NETWORK NAME>"
            psk="<YOUR NETWORK PASSWORD>"
            key_mgmt=WPA-PSK
        }
      

      Enable SSH

      In the boot partition, simply create an empty file with the name ssh

Boot

Plug the SD Card to your R-Pi and power it ON

SSH to your R-Pi

We now need to find the IP Address of our R-Pi.

First Steps after booting

You can read on how to SSH to remote here or just follow along -

Don’t forget to replace the IP Addresses here with the IP Address of YOUR R-Pi.

For the first time the SSH login username is pi and the password is raspberry

Enter ssh pi@<your Pi's IP address> and provide raspberry when asked for password

$ ssh pi@192.168.0.112
pi@192.168.0.112's password: 
Linux raspberrypi 4.19.75-v7l+ #1270 SMP Tue Sep 24 18:51:41 BST 2019 armv7l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.

SSH is enabled and the default password for the 'pi' user has not been changed.
This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password.

How to do it without IP Address

Login using ssh pi@raspberrypi.local The guide below will use the exact IP Address, however note that you could just replace the IP Address with raspberrypi.local. So go ahead and use that freely.

Change Password

As mentioned in the prompt after you enter the password, lets change the password -

pi@raspberrypi:~ $ passwd
Changing password for pi.
Current password: 
New password: 
Retype new password: 
passwd: password updated successfully

Configure your Pi

Let’s configure our R-Pi using raspi-config. Read about the various options from the official documentation and make changes that suits you.

pi@raspberrypi:~ $ sudo raspi-config

Raspi config I performed the following -

Reboot after you are done

SSH into it again after rebooting and you are ready to play with it -

$ ssh pi@192.168.0.112
pi@192.168.0.112's password: 
Linux raspberrypi 4.19.75-v7l+ #1270 SMP Tue Sep 24 18:51:41 BST 2019 armv7l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Fri Oct 25 14:13:05 2019
pi@raspberrypi:~ $

Optional Checks

Getting Ready with Python and bluepy

Now we won’t be able to install any new python library as we don’t have python’s package manager - pip. So we will install it first.
Run the following in order -

  1. sudo apt update
    • apt list --upgradable # optional
  2. sudo apt upgrade
  3. sudo apt install python3-pip

For bluepy installation we need libglib2.0-dev

Install bluepy -

Finally let’s install Git too-

VSCode Remote Server Setup

We need to setup passwordless access in order to setup the remote VSCode development environment on our R-Pi.

Passwordless SSH

This is taken from the great documentation on passwordless remote access by the raspberry-pi team itself.
Read that or just follow along -

On your PC, check if you have created SSH Keys -

$ ls ~/.ssh
known_hosts

If you don’t see id_rsa.pub or id_dsa.pub it means you haven’t. So create a new key (still on your PC) now using ssh-keygen -
I pressed Enter for the two prompts that follow.

$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/<username>/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/<username>/.ssh/id_rsa.
Your public key has been saved in /home/<username>/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:azbFoUF1qv+vIIX9SvuPvOPLVM6AMklyuc/yK9Yo2Xs ---@---
The key's randomart image is:
+---[RSA 2048]----+
|        ... .    |
|       . . o     |
|      . = o      |
|       + X o     |
|        S * . .  |
|         X . =   |
|       oBo* o o  |
|      oo=*EO..   |
|       o.+=+@Bo  |
+----[SHA256]-----+

Right now inside the .ssh hidden folder in R-Pi there would be nothing -

pi@raspberrypi:~/.ssh $ ls
pi@raspberrypi:~/.ssh $

We now need to copy the public key on our PC to our R-Pi using ssh-copy-id pi@<pi's ip address> command -

$ ssh-copy-id pi@192.168.0.112
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
pi@192.168.0.112's password: 

Number of key(s) added: 1

Now try logging into R-Pi, with just - ssh 'pi@<your pi's ip address>' (no password) and check to make sure that only the key(s) you wanted were added.

$ ssh 'pi@192.168.0.112'
Linux raspberrypi 4.19.75-v7l+ #1270 SMP Tue Sep 24 18:51:41 BST 2019 armv7l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Fri Oct 25 14:15:43 2019 from 192.168.0.109
pi@raspberrypi:~ $ ls
pi@raspberrypi:~ $ exit
logout
Connection to 192.168.0.112 closed.

Yes We Can! So the login process was a success.

We will now just check if the key is the same -

Remote Development

They say to use VS Code Insiders Edition, but as of Oct 25, 2019, it seems to work just fine with the Stable version so you don’t have to install the Insiders Edition on your PC. Yay !
They also say that you have to use the Nightly version of the Remote SSH Extension, but for me the stable verisons worked just fine. I will show both the ways just for the sake of completeness -

Using Stable Versions

Install the Remote Development Extension and it will install all the necessary components for you. Do it the from the GUI or follow the steps below -

Remote Development

Using Nightly Remote SSH Version

  1. Install the Remote Development Extension as shown above.
  2. Remove the Remote -SSH Extension, apparently Disabling it doesn’t work.
  3. In it’s place install the Nightly Remote SSH Extension.
Stable Nightly
Remote-SSH Remote-SSH-Nightly

Once its done, your VSCode would look different - at the bottom left corner -
Installed Remote Dev

Setting up Remote development on R-Pi

Setting up server components on R-Pi -

While it’s installing it will look like the following -
installing...

After it installs it will look like this-
Installed!

You can check that the folders you see are those on the R-Pi by clicking on File -> Open Folder.
Moreover you will see the raspberry-pi prompt in VSCode’s integrated terminal -

pi@raspberrypi:~ $

Now you will have to install the extensions Python, Arduino, etc.
We will do this the regular way - click on Extension icon and type whatever extension you want to install, then just click on the green Install in SSH: <your R-Pi IP> button below the extension name to install the extension in your R-Pi environment.
Install Extensions

OR
do it the pro way using the command paletee as I had shown above.

Bluetooth development with Python

  1. From your VSCode Terminal at the bottom make a new folder -
    • mkdir bluetooth-tests
  2. Copy the code here (you will need Arduino Nano 33 BLE with this firmware) to your editor or write your own and save it inside the folder you made (Just press CTRL+S and follow the prompts, its self explanatory)
  3. From your VSCode Terminal Execute the python code
    • cd bluetooth-tests
    • python3 your_file_name.py
  4. Voila ! WorkingPythonBTLE

Link to install Docker

The END

Shutdown your R-Pi - sudo shutdown -h now