In this series, we are using the latest, high-performance Raspberry Pi 4 Model B to review once again everything from the Raspberry Pi setup to the fundamentals of electronic kits.
In this lesson, we will setup a screenless (headless) remote connection, which we will frequently use going forward. This will enable us to use the Raspberry Pi anywhere and learn the basic commands of the Raspberry Pi.
For other necessary components, refer to the first lesson article.
1. Directly installing Raspbian Buster on the Raspberry Pi 4
2. Setting up the Raspberry Pi in a completely headless mode
3. Configuring the Raspberry Pi environment settings from the command tool
4. Summary
Placing NOOBS on the SD card and ran the Raspberry Pi setup from there while viewing the screens over an HDMI connection is the most intuitive way to use the Raspberry Pi in a simple manner like a PC. However, it is convenient to know how to operate the Raspberry Pi remotely from another PC or iPad, etc. to take advantage of its compact size to program it from anywhere or implement active electronic kits. A method for setting up the Raspberry Pi in a completely screenless (headless) mode will be explained in detail below.
We will go to the Downloads screen on the official Raspberry Pi page. This time, we will choose the Raspbian option on the right side instead of NOOBS.
https://www.raspberrypi.org/downloads/
This Raspbian option allows you to download what is called an OS image file. This option includes three different packages. There is the full OS which was also installed with NOOBS (upper left of the image below), the Desktop version (upper right), and the Lite version (lower left) which does not come with a Desktop. The size of the Full OS is 2.5 GB while the Lite version is 430 MB. Using the Lite version allows you to build a lightweight Raspberry Pi which uses absolutely no screens and the smallest size SD card.
Select the full OS ZIP file here and download it to your PC, etc.
Next, open the archive using Unzip, etc. to extract the image file (.img).
We will write this image file to the SD card. Insert the SD card into the PC, etc. Here we are using a 32 GB micro SD card which is not the same card used for the NOOBS install. (Be careful not reuse the same card, because the contents will be overwritten!)
When using a Mac, open the Console and enter the following command (blue text).
First, confirm the location where the SD card is recognized with the diskutil command. In this example, the SD card is recognized as the 32 GB disk under /dev/disk2 (yellow text).
Now unmount this disk2. When you run this command, the disk disappears from the screen.
Next, use the dd command to write the OS image to the SD card. When doing so, be careful to specify the correct disk in the “of=” part of the command. When selecting a Mac disk, it is completely overwritten.
When writing the full OS, it may take several minutes. At the end, the “transferred” message shown in yellow above appears. If a boot directory is displayed on the screen, then the write process is complete.
[If boot appears, then the image write process is complete]
On Windows, we will download and use a disk writing tool such as Win32 Disk Imager.
Obtain the zip file from this link, extract the file, and double-click it in Windows to launch the tool.
https://sourceforge.net/projects/win32diskimager/
The following screen appears when Disk Imager starts. Specify the image file from before in the Image File section. Specify the SD card disk under Device and press the “Write” button below to write the image file.
The Raspbian Buster OS should now be directly installed to the SD card.
The OS is on the SD card, but there is a way to start setting up the Raspberry Pi in a completely headless (screenless) mode even without an HDMI connected display.
After writing the Raspbian image file, move to the boot disk on the SD card from the PC. Use the Console or Explorer to create a file called “ssh” without an extension directly under the boot disk. You do not need to write anything inside the file. When this ssh file is placed under the boot disk, a secure ssh connection is enabled (ssh is disabled under the OS default settings) when this disk is read for the first time by the Raspberry Pi, which will enable you to immediately establish a remote connection even without a screen-based setup.
Moreover, placing a file called “wpa_supplicant.conf” directly under the boot disk will load this file during the initial startup and enable Wi-Fi without using the graphical interface.
[Placing ssh and wpa_supplicant.conf directly under boot]
The following type of information about the Wi-Fi connection must be written in the wpa_supplicant.conf file. Fill in the appropriate information about your wireless network and save the file.
[wpa_supplicant.conf file sample entry]
Insert the SD card which contains the ssh and wpa_supplicant.conf files into the Raspberry Pi. Turn on the power (in this case, the power is supplied by the Mac) to the Raspberry Pi without connecting an HDMI screen or keyboard, etc.
The PC you are using should be connected to the same network as the Wi-Fi environment described in the wpa_supplicant.conf file above.
Now we will launch the Console from the PC. To establish an ssh (secure connection) connection from the Console, enter the command “ssh pi@” (connection name of the Raspberry Pi). The default user name is “pi” and the connection name is “raspberrypi.local”. When asked for the password as shown in the yellow text, enter the default password “raspberry”.
When the password is entered, you can connect to the Raspberry Pi without an HDMI screen.
Enter the “ls” command on the Raspberry Pi to view the folders directly below Home.
Now you can remotely connect to the Raspberry Pi. Users who installed the OS using NOOBS in the previous lesson can also connect in a screenless manner using the same method by enabling ssh from the screen. If you have changed the host name and password from the screen, login using the updated information.
So let’s continue the Raspberry Pi setup over the remote connection. You can perform the basic setup previously conducted from the screen by entering the command “sudo raspi-config”.
The Software Configuration Tool launches when running raspi-config. This tool includes nine menus.
[Software Configuration Tool Menus]
Here we will change the password and host name (1 and 2) as we did from the screen interface.
In addition, we will select “4. Localisation Options” to configure the language and keyboard settings.
Select “I2. Change Timezone” and set it to Tokyo time.
Also select “5. Interface Options” to configure the camera and other settings.
The P2 SSH setting should already be set to “Enable,” so enable the P1 Camera so that it can be used when connected. Also enable the P5 I2C setting for connecting external devices to be able to recognize sensors which support I2C.
Finally, when you navigate to at the bottom of the screen and press Enter, you will be asked if you wish to restart and enable all of the changes by rebooting.
Connect to the Raspberry Pi over ssh once again after it restarts.
This time, we will update to the latest Raspberry Pi and libraries by using the “apt update” and “upgrade” commands.
It may take some time when you run these commands for the first time. However, this will also allow you to check the Internet connection and update the Raspberry Pi to the latest version.
In this lesson, we installed and setup the Raspberry Pi over a remote SSH connection without connecting an HDMI screen or keyboard. This method might not be very elegant, but we will continue to remotely connect to the Raspberry Pi and run commands, so be sure to remember how to do this.
In the next lesson, we will finally cover electronic kits using the Raspberry Pi 4.
Please look forward to it!