Keywords

These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.

Raspberry Pi is a development board that can be applied to build IoT applications. Various sensors and actuator devices can be attached to the board. In this chapter, we explore Raspberry Pi and cover its models. We also learn how to set up the board for the first time.

The following list of topics is covered in this chapter:

  • Learn about the Raspberry Pi

  • Review the Raspberry Pi models

  • Learn about the Raspbian OS

  • Set up Raspbian OS on a Raspberry Pi board

  • Perform headless Raspbian SSH network setup

  • Configure a WiFi network

  • Explore the Raspbian OS desktop

  • Configure the VNC server

  • Learn to power off the Raspbian

1.1 What Is Raspberry Pi?

Raspberry Pi is a mini computer that you can operate as a normal computer. This board was developed by Raspberry Pi Foundation in the UK. Currently, Raspberry Pi runs on the top of an ARM processor. Raspberry Pi is not a PC, so we couldn’t expect more in computation. Raspberry Pi is designed to be small in size to perform some processes. The small form size of the Raspberry Pi form has advantages. We can put sensor and actuator devices on the Raspberry Pi board and then perform measurement and sensing.

The first Raspberry Pi Model B board was released in February 2012. The latest model is the Raspberry Pi 3 B+ board and it was released in March 2018. You can see this board in Figure 1-1. This board can run an operating system to perform computations.

Figure 1-1
figure 1

Raspberry Pi 3 B+ board

The Raspberry Pi board usually exposes GPIO pins, to which we can attach sensors or actuator devices. Some Raspberry Pi models also provide network stacks such as Ethernet, WiFi, and Bluetooth. Raspberry Pi can also be connected to monitor through an HDMI connector.

Various operating systems can be applied to Raspberry Pi boards. A list of supported operating systems for Raspberry Pi can be found at this site: https://www.raspberrypi.org/downloads/ . Raspbian OS is the official operating system of the Raspberry Pi. This book focuses on Raspbian OS for implementation and evaluation.

1.2 Reviewing the Raspberry Pi Board Models

There are several Raspberry Pi models that we can use to perform specific purposes. The latest model as I am writing this book is Raspberry Pi 3 Model B+. This board consists of Broadcom BCM2837B0, Cortex-A53 (ARMv8) 64-bit SoC @ 1.4GHz, with 1GB LPDDR2 SDRAM. The board also provides Ethernet, WiFi, and Bluetooth 4.2 (BLE). You can see the Raspberry Pi 3 Model B+ board in Figure 1-1. For further information about Raspberry Pi 3 Model B+, see https://www.raspberrypi.org/products/raspberry-pi-3-model-b-plus/ .

If you have concerns about hardware size, Raspberry Pi Foundation has an even smaller version, which is half the size of a credit card. It is called the Raspberry Pi Zero. There are two models—Raspberry Pi Zero and Raspberry Pi Zero Wireless. The first model was released in November 2015. The last model that has a WiFi module was released in February 2017. Both models run Broadcom BCM2835 MCU with 512MB RAM. You can see the Raspberry Pi Zero Wireless board form in Figure 1-2.

Figure 1-2
figure 2

Raspberry Pi Zero Wireless board

You also can see and compare several Raspberry Pi models based on processor, RAM, and network module availability in Table 1-1.

Table 1-1 Raspberry Pi Model Comparison

Technically, all the Raspberry Pi models that are shown in Table 1-1 are designed for personal makers and hobbyists. There are limited GPIO pins on each Raspberry Pi model. If you need more GPIO pins on the board, you can extend it using GPIO extender modules. The Raspberry Pi Foundation also released the Raspberry Pi model for industry purposes. It is called the Raspberry Pi Compute Module. Currently, the latest model is Raspberry Pi Compute Module V3.

Raspberry Pi Compute Module V3 board hosts 120 GPIO pins, an HDMI port, a USB port, two camera ports, and two display ports. You can see the board form in Figure 1-3. For further information about the Raspberry Pi Compute Module V3, visit the official website at http://socialcompare.com/en/comparison/raspberrypi-models-comparison .

Figure 1-3
figure 3

Raspberry Pi Compute Module v3

1.3 Introducing the Raspbian OS

Raspbian is an operating system-based Debian optimized for the Raspberry Pi hardware. When the Raspberry Pi board is released, Raspbian OS becomes the official OS for Raspberry Pi boards. Raspbian OS is an open source operating system that was initiated by Mike Thompson and Peter Green. The official Raspbian project can be found on this site: https://www.raspbian.org /.

If you have experience using Debian and Ubuntu Linux, you should be familiar with Raspbian OS since this OS is built based on Debian Linux and optimized on a Raspberry Pi board with ARMv6 CPU.

This book uses Raspbian OS for testing and evaluation. You can download the Raspbian image file at https://www.raspberrypi.org/downloads . Currently, Raspbian provides desktop and lite versions. You can see the download image in Figure 1-4. The Raspbian desktop version is running Raspbian OS with an installed desktop runtime. The Raspbian lite version is designed for light usage. It means you will obtain the Terminal runtime.

Figure 1-4
figure 4

Download the Raspbian OS image

Next, I show you how to set up Raspbian OS on the Raspberry Pi 3 board.

1.4 Setting Up Raspbian OS on Raspberry Pi Boards

The Raspberry Pi models don’t have internal storage unless you’re using the Raspberry Pi Compute Module. You should attach external storage, such as an SD card or a microSD card. The new Raspberry Pi board model uses microSD for external storage.

I recommended that you use a microSD card that’s 16GB. You can install some libraries, frameworks, and tools for your personal and business needs. In this section, I’m going to show you how to set up Raspbian OS on a Raspberry Pi 3 board.

First, download the Raspbian OS image. You can download it at https://www.raspberrypi.org/downloads . For demo purposes, I chose the Raspbian Stretch with desktop, as shown in Figure 1-4. To flash the Raspbian image into the microSD card, you can use Etcher. It’s free and available for Windows, Mac, and Linux. You can see the Etcher application in Figure 1-5. Download it from https://etcher.io , based on your platform, and then install it.

Figure 1-5
figure 5

Etcher application

The Etcher application is easy to use. You can just select your Raspbian image and target the drive of the microSD card on your computer. Some computers don’t have microSD card readers, so you need an SDcard reader. Then put your microSD card into the reader.

After completing the flashing Raspbian step, you can plug your keyboard, mouse, and monitor into the Raspberry Pi board.

Details about Raspbian installation on the Raspberry Pi board can be found in the official guideline manual at https://www.raspberrypi.org/documentation/installation/installing-images/README.md .

1.5 Headless Raspbian SSH Network Setup

Sometimes you won’t want to use a keyboard or monitor to manage the Raspbian network. We can perform a headless Raspbian network in this case. In this scenario, the Raspberry Pi board will be connected to a network via Ethernet. You’ll want to enable an SSH service on the Raspberry Pi without configuring your keyboard and monitor.

First, load your Raspbian microSD card into your computer. You should see a Raspbian drive. Now you want to enable SSH on Raspbian. You can create a file, called ssh without a file extension, with blank content. Put this file into the Raspbian drive. You can see it in Figure 1-6.

After you’re done, you should plug the Raspbian microSD card into the Raspberry Pi board. Plug your LAN cable into the Raspberry Pi Ethernet connector. After that, turn on your Raspberry Pi board.

Figure 1-6
figure 6

Adding an ssh file into Raspbian disk

Wait several minutes to ensure Raspbian has started. You should get your Raspbian IP address from your router. Now open the SSH client application. For Windows, you can use the PuTTY application at https://www.putty.org . For Linux and Mac, you can use the Terminal. For instance, the Raspbian IP address is 192.168.1.21 and the username is pi. Then type this command.

$ ssh pi@192.168.1.21

You should be able to access the Raspbian Terminal remotely. You can see an example of remote SSH in Figure 1-7.

Figure 1-7
figure 7

Connecting to Raspbian via SSH

1.6 Expanding Storage

Before you install any libraries, frameworks, or tools, I recommend that you expand the Raspbian disk. You can open Raspbian Terminal from the desktop or by using remote SSH. Type this command.

$ sudo raspi-config

You should see the form shown in Figure 1-8.

Figure 1-8
figure 8

Select Advanced Options

From the main menu (see Figure 1-8), you can select the Advanced Options menu. Then, you should see the form that is shown in Figure 1-9.

Select the Expand Filesystem option. After that, you will obtain confirmation. If you’re done, Raspbian will expand your disk.

Figure 1-9
figure 9

Expand the filesystem

1.7 Configuring a WiFi Network

Raspberry Pi 3 has a built-in WiFi network. You can connect this WiFI to existing WiFi networks. If you are working on the Raspbian Desktop, you can see the WiFi icon on the top right. Figure 1-10 shows an arrow pointing to the connect WiFi option.

Figure 1-10
figure 10

Connect to existing WiFi

After you select one of the WiFi SSIDs, you probably will be asked for the SSID pin. Fill in the SSID pin and then your Raspbian will connect to the network.

1.8 Exploring the Raspbian OS Desktop and Terminal

The Raspbian OS desktop has a look and feel like other operating systems. Some applications have been installed for you, such as the Chrome browser, Wolfram, Mathematica. A form of the Raspbian OS can be seen in Figure 1-11.

Figure 1-11
figure 11

Raspbian Scratch OS desktop on Raspberry Pi 3

If you click on the Raspberry Pi logo on the top-left, you should see a main menu, as shown in Figure 1-12. You can see a list of applications and the managing systems.

Figure 1-12
figure 12

Main menu on Raspbian desktop OS

For instance, open a browser from the Internet menu. You can surf the Internet as you do in a normal browser. Raspbian installed Chromium as its default browser application. You can see this browser in Figure 1-13.

Figure 1-13
figure 13

Opening a browser for Internet access

1.9 Configuring the VNC Server

You will probably access Raspbian desktop remotely, so you don’t need to use the keyboard and monitor to access the Raspbian desktop. In this section, we install the VNC server. An Internet network is required to perform this task. Make sure your Raspberry Pi has connected to the Internet via a LAN or a WiFi network.

To do this, you will perform these steps:

  1. 1.

    Install the VNC server.

  2. 2.

    Enable the VNC server.

  3. 3.

    Configure the boot option for desktop.

  4. 4.

    Test with the VNC viewer.

Each task is presented in detail in the following sections.

1.9.1 Installing the VNC Server

To install the VNC server on Raspberry Pi 3, you can perform this task on the Terminal. First, open the Terminal via SSH. After that, type these commands.

$ sudo apt-get update $ sudo apt-get install realvnc-vnc-server realvnc-vnc-viewer

This task will download and install the VNC server and viewer application on to your Raspbian.

1.9.2 Enabling the VNC Server

The next step is to enable the VNC server on the Raspbian. You can do this step via the Terminal. You can type this command.

$ sudo raspi-config

After the command is executed, you should see the form shown previously in Figure 1-8. Select Interfacing Options. You should then see the menu shown in Figure 1-14. From there, select VNC.

Figure 1-14
figure 14

Selecting VNC

Next, you are asked to confirm that you want to enable the VNC server, as shown in Figure 1-15. Select Yes.

Figure 1-15
figure 15

Confirmation for enabling the VNC server

Next, you need to enable the boot options for the desktop.

1.9.3 Configuring Boot Options for the Desktop

Since VNC remote needs desktop service, we should configure Raspbian to enable it running in desktop mode. You can configure this via raspi-config. You can call it via the Terminal.

$ sudo raspi-config

After it’s executed, you should get the form shown in Figure 1-16. Select Boot Options so you will have a form, as shown in Figure 1-17.

Figure 1-16
figure 16

Selecting Boot Options

Figure 1-17
figure 17

Selecting Desktop/CLI

Now you can select Desktop Autologin, as shown in Figure 1-18.

Figure 1-18
figure 18

Selecting Desktop Autologin Desktop GUI

When you’re done, your Raspbian will reboot.

1.9.4 Testing the Server

To test the VNC server, you need to install a VNC client. We can use the VNC Viewer application to do this. You can download this application based on your platform from https://www.realvnc.com/en/connect/download/viewer/ .

You can see VNC Viewer application in Figure 1-19. This application is easier to use.

Figure 1-19
figure 19

VNC Viewer application on the Mac platform

Now you can type the IP address of Raspbian into the textbox of the VNC Viewer application. If you’re connected, you will be asked to provide the username and password, as shown in Figure 1-20.

Figure 1-20
figure 20

Connecting to the Raspbian desktop via the VNC Viewer

If this succeeds, you should see the Raspbian desktop. For instance, you can see my Raspbian desktop in Figure 1-21.

Figure 1-21
figure 21

Accessing a Raspbian desktop through the VNC Viewer application

1.10 Powering Off the Raspbian

It’s a good idea to turn off your Raspberry Pi when you’re not using it. Don’t turn off the power directly because doing so can break your board. Instead, you turn off your Raspberry Pi by typing this command on the Terminal.

$ sudo shutdown -h -P now

After Raspbian shuts down, you’ll see the red LED light up. Then unplug the power cable from the board.

If you are working with Raspbian in desktop mode, you can turn off Raspberry Pi by choosing the Shutdown option from the main menu. After you choose this option, you should obtain the dialog shown in Figure 1-22. Click the Shutdown button.

Figure 1-22
figure 22

The Shutdown button on the Raspbian desktop

After the shutdown process is complete, you can unplug the power cable from your Raspberry Pi board.

This is the end of the last session in this chapter.

1.11 Summary

In this chapter, you learned briefly what Raspberry Pi and Raspbian are. You also set up Raspbian on a Raspberry Pi board. Last, you learned how to configure the network and the VNC desktop.

In the next chapter, we focus on the command line in Raspbian. You learn how to operate and manage Raspbian through the Terminal.