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.

We will start our exciting journey of exploration into the scientific domain of supercomputing and scientific programming with Raspberry Pi. But for us to begin the journey, we must be comfortable with the basics of the single board computers and Raspberry Pi. In this chapter, we will study the definition, history, and philosophy behind single board computers. We will first compare it with a regular computer. We will then move on to the most popular and best-selling single board computer of all time, the Raspberry Pi. By the end of this chapter, readers will have adequate knowledge to set up their own Raspberry Pi independently. This chapter aims to make the readers comfortable with the very basic concepts of single board computers and the setup of the Raspberry Pi.

Single Board Computers (SBCs)

A single board computer (which will be referred to as SBCs from henceforth throughout the entire book) is a fully functional computer system built around a single printed circuit board. An SBC has microprocessor(s), memory, input/output, and other features required of a minimal functional computer . Unlike a desktop personal computer (PC), most of the SBCs do not have expansion slots for peripheral functions or expansion. As all the components such as processor(s), RAM, GPU, etc., are integrated on a single PCB, we cannot upgrade an SBC.

Few SBCs are made to plug into a backplane for system expansion. SBCs come in many varieties, sizes, shapes, form factors, and sets of features. Due to the advances in electronics and semiconductor technologies, prices of most SBCs are very low. One of the most important features of SBCs is cost effectiveness. With a price around $50 apiece, we have in our hands a development tool suitable for new applications, hacking, debugging, testing, hardware development, and automation systems.

SBCs are usually manufactured in the following form factors :

  • Pico-ITX

  • PXI

  • Qseven

  • VMEbus

  • VPX

  • VXI

  • AdvancedTCA

  • CompactPCI

  • Embedded Compact Extended (ECX)

  • Mini-ITX

  • PC/104

  • PICMG

Differences Between SBCs and Regular Computers

The following is a table (Table 1-1) of the differences between SBCs and regular computers .

Table 1-1. Differences Between SBCs and Regular Computers

System on Chip

All the SBCs are predominantly SoCs. A system on a chip or system on chip (SoC or SOC) is an integrated circuit (IC) that has all the components of a computer on a single chip. SoCs are very common in mobile electronic devices because of their low power consumption and versatility. SoCs are widely used in mobile phones, SBCs, and embedded hardware. A SoC has all the hardware and the software needed for its operation.

SoC vs. Regular CPU

The biggest advantage of using a SoC is its size. If we use a CPU, it’s very hard to make a compact computer, only because of the sheer number of individual chips and other components that we need to arrange on a board. However, using SoCs, we can place complete application-specific computing systems in smartphones and tablets, and still have plenty of space for batteries, antennae, and other add-ons required for remote telephony and data communication.

Due to the very high level of integration and compact size, a SoC uses considerably less power than a regular CPU. This is a significant advantage of SoCs when it comes to mobile and portable systems. Also, reducing the number of chips by eliminating redundant ICs on a computer board results in the compact board size.

History of SBCs

Dyna-Micro was the first true SBC. It was based on the Intel C8080A and used Intel’s first EPROM, the C1702A. The dyna-micro was re-branded and marketed by E&L Instruments of Derby, CT in 1976 as the MMD-1 (Mini-Micro Designer 1). It became famous as the leading example of microcomputers. SBCs were very popular in the earlier days of computing, as many home computers were actually SBCs. However, with the rise of PCs, the popularity of SBCs declined. Since 2010, there has been a resurgence in the popularity of SBCs due to lower production costs associated with SBCs.

Apart from the MMD-1, a few popular historical SBCs are the following:

  • BBC Micro was built around a MOS Technology 6502A processor running at 2 MHz.

  • Ferguson Big Board II was a Zilog Z80 based computer running at 4MHz.

  • Nascom was another Zilog Z80 based computer.

Popular SBC Families

Based on manufacturers and designers, SBCs are grouped into families, models, and generations. A few popular SBC families are

  • Raspberry Pi by Raspberry Pi Foundation

  • Banana Pi and Banana Pro

  • Intel Edison and Galileo

  • Cubieboard

  • Beaglebone and Beagleboard

Raspberry Pi

Raspberry Pi is a family of credit card-sized SBCs developed in the United Kingdom by the Raspberry Pi Foundation. The Raspberry Pi Foundation was founded in 2009. The aim behind developing Raspberry Pi is to promote the teaching of basic computer science in schools and developing countries by providing a low-cost computing platform .

The Raspberry Pi Foundation’s Raspberry Pi was released in 2012. It was a massive hit which sold over two million units in two years. Subsequently, the Raspberry Pi Foundation revised versions of the Raspberry Pi. They also released other accessories for the Pi.

You can find more information about the Raspberry Pi Foundation on the Raspberry Pi Foundation’s website ( www.raspberrypi.org ).

The product page for Raspberry Pi’s current production models and other accessories is www.raspberrypi.org/products .

I have written, executed, and tested all the code examples of this book on Raspberry Pi Models B+, 2B, and 3B. Raspberry Pi 3 Model B (also known as 3B) is the most recent model of Raspberry Pi. Let us look at the specifications (Refer Table 1-2) of Raspberry Pi 3 Model B.

Table 1-2. Specifications of Raspberry Pi 3 Model B

The following (Figure 1-1) is the top view of Raspberry Pi 3 Model B.

Figure 1-1.
figure 1

Raspberry Pi 3 Model B top view

The following (Figure 1-2) is the bottom view of Raspberry Pi 3 Model B.

Figure 1-2.
figure 2

Raspberry Pi 3 Model B bottom view

We can get more information on Raspberry Pi 3 Model B by visiting its product page ( www.raspberrypi.org/products/raspberry-pi-3-model-b ).

The following table (Table 1-3) lists the specifications of Raspberry Pi 2 Model B.

Table 1-3. Specifications of Raspberry Pi 2 Model B

We can get more information on Raspberry Pi 2 Model B by visiting its product page ( www.raspberrypi.org/products/raspberry-pi-2-model-b/ ).

The following table (Table 1-4) lists the specifications of Raspberry Pi 1Model B+.

Table 1-4. Specifications of Raspberry Pi 1 Model B+

We can get more information on Raspberry Pi 2 Model B by visiting its product page ( www.raspberrypi.org/products/model-b-plus/ ).

Raspberry Pi Setup

We have to set up Raspberry Pi before we can begin to use it for exploration and adventure. Let’s see in detail how to set it up. As I have mentioned earlier, I am using Raspberry Pi 3 Model B for the setup. The setup process is exactly the same for Raspberry Pi 2 Model B and Raspberry Pi 1 Model B+. Let’s see the list of hardware materials you will need for setup.

Hardware required for Raspberry Pi setup

The following hardware is required for setup.

Raspberry Pi

We need to use Raspberry Pi 3 Model B or Raspberry Pi 2 Model B or Raspberry Pi 1 Model B+ for the setup.

Computer

A Windows computer or laptop with an Internet connection is required. We need to use a computer to prepare a microSD card with a Raspbian OS image for the Pi.

I/O Devices

A standard USB keyboard and a USB mouse are needed.

MicroSD card

A microSD card (see Figure 1-3 for example) with storage capacity of at least 8 GB is needed. We will use the card for secondary storage for the Pi. A card of Class 10 is recommended as the data transfer speed with class 10 is great. I recommend using at least an 8 GB card to be on the safe side. Choosing a 16 GB card will be adequate for most cases.

Figure 1-3.
figure 3

Class 10 microSD card (image from www.flickr.com/photos/ssoosay/ )

Note

Before purchasing the card, do visit the link http://elinux.org/RPi_SD_cards to check the compatibility of the card with the Raspberry Pi.

Power Supply

For all the Raspberry Pi models a 5V Micro USB power supply unit (PSU) is required. The recommended current capacity of PSU for Raspberry Pi 3 Model B is 2.5 Amp. For all the other models 2 Amp PSU is more than enough.

You can find Raspberry Pi’s official power supply at https://thepihut.com/products/official-raspberry-pi-universal-power-supply .

SD/microSD Card Reader

We also need a card reader. Many laptops have a built-in SD card reader.

In case the laptop or the card reader works with SD cards only, then we need an additional microSD-to-SD card adapter. The following figure (Figure 1-4) shows an adapter.

Figure 1-4.
figure 4

Card reader and microSD-to-SD adapter (image from www.flickr.com/photos/sparkfun/ )

Monitor

We need an HDMI monitor or a VGA Monitor.

For HDMI monitors we need an HDMI cable (see Figure 1-5). It is usually packaged with the HDMI monitor.

Figure 1-5.
figure 5

HDMI male-to-male cable (image from www.flickr.com/photos/sparkfun/ )

For VGA monitors, we need a VGA cable (see Figure 1-6). This too is usually packaged with the VGA monitor.

Figure 1-6.
figure 6

VGA cable (image from www.flickr.com/photos/124242273@N07/ )

If we are using a VGA monitor, we will need an HDMI-to-VGA adapter, as Raspberry Pi only has an HDMI port for video output (Figure 1-7).

Figure 1-7.
figure 7

HDMI-to-VGA adapter (image from www.flickr.com/photos/sparkfun/ )

Manual Preparation of the MicroSD Card for Raspberry Pi

Preparing the microSD card for Pi manually is the best way of installing an OS into a microSD card for single board computers. Many users (including me) prefer it because it allows the contents of the microSD card to be modified manually (if needed) before it is used for booting. The other way to prepare the microSD is to use NOOBS (New Out Of the Box Software), which I have not used in this book.

Manual preparation allows us to access the configuration files like /boot/config.txt before booting. We might have to modify the configuration files in a few cases (we will discuss that soon) before booting up the Pi. The default Raspbian image has two partitions, boot and system. Please use at least a 16 GB microSD card for the Pi, considering any possible future upgrades to the OS.

Download the Required Free Software

Let’s download the required software .

Download Accelerator Plus

Download the Download Accelerator Plus setup from its download page ( www.speedbit.com/dap/download/downloading.asp ). This freeware is used to manage downloads. It is useful for large downloads as we can pause and resume downloads. If your computer shuts down suddenly or the internet is interrupted, it resumes the download from the last checkpoint. Once you download and install it, use it to manage the following downloads.

Win32DiskImager

Download the Win32DiskImager setup from its download page ( https://sourceforge.net/projects/win32diskimager/files/latest/download ). Install.

WinZip or WinRaR

We need a file extraction utility. Download WinZip ( http://www.winzip.com/win/en/index.htm ) or WinRaR ( http://www.win-rar.com/download.html ). Install either of them.

Download and Extract the Raspbian OS Image

We will use the Raspbian OS for the Pi. We will discuss Raspbian in detail in the later part of the chapter. For now, download the latest zip of the image of the Raspbian OS from www.raspberrypi.org/downloads/raspbian . Extract the image zip file with WinZip or WinRaR.

Writing the Raspbian OS Image to the MicroSD Card

Insert the microSD card into the card reader. If your computer or laptop has a built-in card reader, insert it there. You might have to use a microSD-to-SD card adapter if the card reader or your computer only has a slot for SD cards.

Open Win32DiskImager . Select the location of the image file and click the Write button. See the following Figure 1-8.

Figure 1-8.
figure 8

Win32 Disk Imager

If you see the following warning message (Figure 1-9), then toggle the write protection notch of the card reader or the SD card adapter (or both). Then click the Write button again.

Figure 1-9.
figure 9

Write protection error message

The following (Figure 1-10) warning message will be displayed. Click the Yes button to continue.

Figure 1-10.
figure 10

Overwrite warning message

Once the OS image is written on the SD card, the following (Figure 1-11) message will be displayed. Click the OK button.

Figure 1-11.
figure 11

Write successful message

The Raspbian OS has been flashed to the microSD card.

Altering the Contents of the config.txt File for VGA Monitors

Note

This step is a must if you are planning to use a VGA monitor. Please skip this step if you are using an HDMI monitor.

We must use an HDMI-to-VGA cable with a VGA display. We also need to change the contents of config.txt to get the Pi working with VGA monitors. We will learn more about config.txt in the later part of the chapter.

Insert the microSD card into the card reader again and browse it in Windows Explorer. In Windows Explorer, it will be represented as a removable media drive labeled as boot.

Open file config.txt and make following changes to the file:

  • Change #disable_overscan=1 to disable_overscan=1

  • Change #hdmi_force_hotplug=1 to hdmi_force_hotplug=1

  • Change #hdmi_group=1 to hdmi_group=2

  • Change #hdmi_mode=1 to hdmi_mode=16

  • Change #hdmi_drive=2 to hdmi_drive=2

  • Change #config_hdmi_boost=4 to config_hdmi_boost=4

Save the file after making the above-mentioned changes.

The microSD card is now ready for the Pi and a VGA Monitor.

Booting up the Pi

Let’s boot the Pi up with the prepared microSD card. The steps for that are as follows:

  1. 1.

    If you are using an HDMI monitor, connect the monitor directly to the Pi’s HDMI port using the HDMI male-to-male cable. If you are using a VGA monitor, use the HDMI-to-VGA adapter to convert HDMI signals to VGA.

  2. 2.

    Insert the microSD card into the microSD card slot of the Pi.

  3. 3.

    Connect the USB mouse and the USB keyboard.

  4. 4.

    At this point, make sure that the power is switched off. Connect the Pi to the power supply with the micro USB power cable we discussed earlier.

  5. 5.

    Connect the monitor to the power supply.

  6. 6.

    Check all the connections. Switch on the power supply of the Pi and the monitor.

At this point, the Raspberry Pi will boot up.

For all the models of Raspberry Pi with the single core processor , the boot screen will be as follows (Figure 1-12).

Figure 1-12.
figure 12

Single-core CPU RPi model boot screen

For all the models of Raspberry Pi with the quad-core processor , the boot screen will be as follows (Figure 1-13).

Figure 1-13.
figure 13

Quad-core CPU RPi Model boot screen

Once the Pi boots up, the monitor displays the desktop as follows (Figure 1-14).

Figure 1-14.
figure 14

Raspbian Desktop (as of February 2017)

Configuring the Pi

We need to configure the Pi now for further use. Let’s do that.

On the desktop, there is a taskbar. In the taskbar, we find the following icon (Figure 1-15).

Figure 1-15.
figure 15

LXTerminal icon

Click the icon and LXTerminal window (Figure 1-16) will open.

Figure 1-16.
figure 16

LXTerminal Window

The terminal is a desktop-independent VTE-based terminal emulator for LXDE without any unnecessary dependency. Type sudoraspi-config in the prompt and press Enter. The raspi-config is the configuration tool for Raspberry Pi.

Navigate to the boot options (highlighted in Figure 1-17).

Figure 1-17.
figure 17

raspi-config with boot options highlighted

Set the Boot Options to Desktop Autologin as shown in Figure 1-18 below.

Figure 1-18.
figure 18

Desktop Autologin highlighted

In the Internationalization Options, change the timezone and the Wi-Fi country (see Figure 1-19). Change the Keyboard Layout to US.

Figure 1-19.
figure 19

raspi-config internationalization options

Once done, go back to the main screen and select Finish as shown in the following screenshot (Figure 1-20).

Figure 1-20.
figure 20

Finish

It will ask to reboot (Figure 1-21). Choose Yes.

Figure 1-21.
figure 21

Reboot Prompt

It will reboot the Pi.

Our job is not done yet. We need to learn how to connect the Pi to the Internet and how to update it.

Raspbian

An operating system is the set of basic programs and utilities to make the computer work. It is an interface between the user and the computer. Raspbian is a free operating system based on the popular Linux distribution Debian. Raspbian is optimized for the Raspberry Pi family of SBCs. It is even ported to the other similar SBCs like Banana Pro.

Raspbian has more than 35,000 packages and pre-compiled software bundled in for easy installation and use on the Raspberry Pi. The first build of Raspbian was completed in June of 2012. Raspbian is still under active development and updated frequently. Visit the Raspbian homepage ( www.raspbian.org ) and the Raspbian documentation page ( www.raspbian.org/RaspbianDocumentation ) for more information on Raspbian.

config.txt

Raspberry Pi does not have a conventional BIOS. A BIOS (Basic Input/Output System) is the program that a computer’s microprocessor uses to get the computer system started and load the OS into the memory after the computer is powered on. It also manages data flow between the computer’s operating system and attached peripheral devices such as the hard disk, video adapter, keyboard, mouse, and printer.

As Raspberry Pi does not have a BIOS, the various system configuration parameters that are normally stored and modified using the BIOS are now stored in a text file named config.txt.

The Raspberry Pi config.txt file is a file on the boot partition of the Raspberry Pi. It is normally accessible as /boot/config.txt from Linux. However, from Windows and Mac OS, it is seen as a file in the accessible part of the microSD card. The accessible part of the card is labeled as boot. As we have already learned in earlier in this chapter, we must edit the /boot/config.txt file if we want to connect it to a VGA display.

On Raspberry Pi, we can edit this file with the following command in LXTerminal:

sudo nano /boot/config.txt

Note

nano is a simple and easy to learn text-based text editor for Linux. Visit its homepage ( www.nano-editor.org ) to learn more about it. I find it easier to use than vi or vim editors.

To learn more about config.txt, visit the page http://elinux.org/RPiconfig . Also, a sample configuration can be found at http://elinux.org/R-Pi_configuration_file .

Connecting Raspberry Pi to a Network and the Internet

To connect the Pi to any network, we have to edit the /etc/network/interfaces file. If the network that Pi is connected to is connected to the Internet, then the Pi can access the Internet.

WiFi

Raspberry Pi 3 Model B has built-in WiFi. For all the other models of Pi, we need to use a USB WiFi adapter.

Once the USB WiFi adapter is attached to the Pi, make a backup of the /etc/network/interfaces file with the following command:

sudo mv /etc/network/interfaces /etc/network/interfaces.bkp

The original /etc/network/interfaces file is safe this way, and can be restored if something goes wrong.

Now create a new /etc/network/interfaces file.

sudo nano /etc/network/interfaces

Type the following lines (Listing 1-1) into that:

Listing 1-1. /etc/network/interfaces

source-directory /etc/network/interfaces.d auto lo iface lo inet loopback auto wlan0 allow-hotplug wlan0 iface wlan0 inet dhcp wpa-ssid "ASHWIN" wpa-psk "internet"

In the file above (Listing 1-1) replace "ASHWIN" with the ssid of your WiFi network and replace "internet" with the password of your WiFi network. Save the file by pressing CTRL+X and then Y.

Run the following command to restart the networking service:

sudo service networking restart

If you have followed the steps correctly, the Pi should connect to the WiFi network and the Internet (provided that WiFi network is connected to the Internet).

To verify connectivity with the Internet, use the following command:

ping -c4 www.google.com

It should show output similar to that below.

PING www.google.com (216.58.197.68) 56(84) bytes of data. 64 bytes from maa03s21-in-f4.1e100.net (216.58.197.68): icmp_seq=1 ttl=55 time=755 ms 64 bytes from maa03s21-in-f4.1e100.net (216.58.197.68): icmp_seq=2 ttl=55 time=394 ms 64 bytes from maa03s21-in-f4.1e100.net (216.58.197.68): icmp_seq=3 ttl=55 time=391 ms 64 bytes from maa03s21-in-f4.1e100.net (216.58.197.68): icmp_seq=4 ttl=55 time=401 ms --- www.google.com ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 3003ms rtt min/avg/max/mdev = 391.729/485.695/755.701/155.925 ms

Output like the above means the Pi is connected to the Internet.

To find the IP address of the Pi, use the ifconfig command. In its output, check the section for wlan0. It will be as follows:

wlan0     Link encap:Ethernet  HWaddr 7c:dd:90:00:e2:1e           inet addr:192.168.0.122  Bcast:192.168.0.255  Mask:255.255.255.0           inet6 addr: fe80::7edd:90ff:fe00:e21e/64 Scope:Link           UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1           RX packets:1974 errors:0 dropped:0 overruns:0 frame:0           TX packets:1275 errors:0 dropped:0 overruns:0 carrier:0           collisions:0 txqueuelen:1000           RX bytes:195049 (190.4 KiB)  TX bytes:1204336 (1.1 MiB)

In the output above, 192.168.0.122 is the IP address of the Pi. As the IP address is allocated with DHCP protocol, it will be different for you depending on the WiFi network settings.

Ethernet

We can also connect the Pi to a LAN network. Based on the LAN switch’s settings, we can allocate an IP address to the Pi statically or dynamically.

Static IP address

If the LAN network allocates IP addresses statically, then configure the /etc/network/interfaces as follows (Listing 1-2):

Listing 1-2. /etc/network/interfaces

source-directory /etc/network/interfaces.d auto lo iface lo inet loopback auto eth0 allow-hotplug eth0 iface eth0 inet static # Your static IP address 192.168.0.2 # Your gateway IP gateway 192.168.0.1 netmask 255.255.255.0 # Your network address family network 192.168.0.0 broadcast 192.168.0.255

In the file above, the parameters address, gateway, netmask, network, and broadcast are based on the LAN’s configuration. Please check the manual of the LAN switch or router. If you are working in an organization, then check with the network administrator for these parameters.

Dynamic IP address

This is an easy one. If the LAN has DHCP capability, then configure the /etc/network/interfaces as follows (Listing 1-3):

Listing 1-3. /etc/network/interfaces

source-directory /etc/network/interfaces.d auto lo iface lo inet loopback auto eth0 allow-hotplug eth0 iface eth0 inet dhcp

This will configure the Pi to acquire the IP address automatically with DHCP.

Note

All the information needed for network setup on Debian and its derivatives can be found on https://wiki.debian.org/NetworkConfiguration .

Updating the Pi

Pi must be connected to the internet for this.

Updating the Firmware

The firmware is the software embedded into the ROM chip of an electronic device. It provides control and monitoring of the device. To update the firmware of the Pi, run sudo rpi-update. It will update the firmware.

Updating and Upgrading Raspbian

We will use APT for this. APT stands for Advanced Package Tool. It is a program that handles the installation and removal of software on Debian and other Debian derivatives. APT simplifies the process of managing software on Debian systems by automating the fetching, configuration, and installation of software packages. We will need an Internet connection for this too.

First, update the system’s package list by entering the following command in LXTerminal:

sudo apt-get update

apt-get update downloads the package lists from the respective remote repositories and updates them on the local computer to get information on the newest versions of packages and their dependencies which are available for installation and update. It should be run before running the install or upgrade command.

Next, upgrade all the installed packages to their latest versions with the command:

sudo apt-get dist-upgrade -y

apt-get dist-upgrade fetches new versions of packages existing on the machine which are marked for upgrade on the local machine. It also detects and installs dependencies. It might remove obsolete packages.

Doing this regularly will keep the RaspbianOS installed on the Pi up to date. After entering these commands, it will take a while to update the OS as these commands fetch data and packages from the remote repositories.

Note

sudo apt-get --help will list all the options associated with apt-get

Updating raspi-config

In raspi-config, go to the advanced options (see Figure 1-22) and choose Update.

Figure 1-22.
figure 22

Updating raspi-config

Shutting Down and Restarting Pi

We can shutdown Pi safely with sudo shutdown -h now.

We can restart Pi with sudo reboot -h now.

Conclusion

In this chapter, we were introduced to the concept and philosophy of SBCs. We also got started with a popular family of SBCs, Raspberry Pi. Now we can confidently move ahead with further exploration. In the next chapter, we will learn a few important Linux commands and how to connect to the Pi remotely.