1

Introduction

The Raspberry Pi went on general sale at the end of February 2012 and immediately crashed the websites of the suppliers chosen to take orders for it.

Since then a number of new models culminating in the Raspberry Pi 2 have been released. So what was so special about this little device and why has it created so much interest?

 

What Is the Raspberry Pi?

The Raspberry Pi 2, shown in Figure 1-1, is a computer that runs the Linux operating system. It has USB sockets you can plug a keyboard and mouse into and HDMI (High-Definition Multimedia Interface) video output you can connect a TV or monitor into. Many monitors only have a VGA connector, and Raspberry Pi will not work with this. However, if your monitor has a DVI connector, cheap HDMI-to-DVI adapters are available.

Images

Figure 1-1 The Raspberry Pi.

When Raspberry Pi boots up, you get the Linux desktop shown in Figure 1-2. This really is a proper computer, able to run an office suite, video playback capabilities, games, and the lot. It’s not Microsoft Windows; instead, it is Windows’ open source rival Linux (Debian Linux), and the windowing environment is called LXDE.

Images

Figure 1-2 The Raspberry Pi desktop.

It’s small (the size of a credit card) and extremely affordable (starting at $25). Part of the reason for this low cost is that some components are not included with the board or are optional extras. For instance, it does not come in a case to protect it—it is just a bare board. Nor does it come with a power supply, so you will need to find yourself a 5V micro-USB power supply, much like you would use to charge a phone (but probably with higher power). A USB power supply and a micro-USB lead are often used for this.

 

What Can You Do with a Raspberry Pi?

You can do pretty much anything on a Raspberry Pi that you can on any other Linux desktop computer, with a few limitations. The Raspberry Pi 2 uses a micro-SD card in place of a hard disk. The older Raspberry Pi models A and B use a full-size SD card, although you can plug in a USB hard disk. You can edit office documents, browse the Internet, and play games (even games with quite intensive graphics, such as Quake).

The low price of the Raspberry Pi means that it is also a prime candidate for use as a media center. It can play video, and you can just about power it from the USB port you find on many TVs.

 

A Tour of the Raspberry Pi

Figure 1-3 labels the various parts of a Raspberry Pi. This figure takes you on a tour of the Raspberry Pi 2, which differs from the other current Raspberry Pi version, the Model A+, by virtue of having a RJ-45 LAN connector, allowing it to be connected to a network.

Images

Figure 1-3 The anatomy of a Raspberry Pi 2.

The RJ-45 Ethernet connector is shown in the bottom-right corner of the figure. If your home hub is handy, you can plug your Raspberry Pi directly into your local network. While we are on the subject, it is worth noting that the Raspberry Pi does not have Wi-Fi built in. For wireless networking, you will need to plug in a USB wireless adapter.

Immediately above the Ethernet socket you’ll find two pairs of USB sockets. You can plug a keyboard, mouse, or external hard disks into the board.

In the bottom-center of the figure you’ll find an audio socket that provides a stereo analog signal for headphones or powered speakers. This socket also provides a composite video signal. The HDMI connector is also sound capable.

You are unlikely to use the composite video feature of the audio/AV socket connector unless you are using your Raspberry Pi with an older TV. You are far more likely to use the HDMI connector. HDMI is higher quality, includes sound, and can be connected to DVI-equipped monitors with a cheap adapter.

At the top of the Pi 2 are two rows of pins. These are called GPIO (General Purpose Input/Output) pins, and they allow the Raspberry Pi to be connected to custom electronics. Users of the Arduino and other microcontroller boards will be used to the idea of GPIO pins. Later, in Chapter 12, we will use these pins to enable our Raspberry Pi to be the “brain” of a little roving robot by controlling its motors. In Chapter 11, we will use the Raspberry Pi to make an LED clock.

The Raspberry Pi 2 has a micro-SD card slot underneath the board. This SD card needs to be at least 2 to 4GB in size. It contains the computer’s operating system as well as the file system in which you can store any documents you create. The SD card is an optional extra feature when buying your Raspberry Pi. Preparing your own SD card is a little unusual, and suppliers such as SK Pang, Farnell, and RS Components all sell already-prepared micro-SD cards. Because no disk is built into your Raspberry Pi, this card is effectively your computer, so you could take it out and put it in a different Raspberry Pi and all your stuff would be there.

Below the micro-SD card is a micro-USB socket. This is only used to supply power to the Raspberry Pi. Therefore, you will need a power supply with a micro-USB connector on the end. This is the same type of connector used by many mobile phones, including most Android phones. Do, however, check that it is capable of supplying at least 700mA; otherwise, your Raspberry Pi may behave erratically.

For those interested in technical specs, the big square chip in the center of the board is where all the action occurs. This is Broadcom’s “System on a Chip” and includes 1GB of memory as well as the graphics and general-purpose processors that drive the Raspberry Pi 2.

You may also have noticed flat cable connectors on the Pi 2. The connector on the far left is for an LCD display and the connector bottom-center is for the special Raspberry Pi Camera Module.

 

Setting Up Your Raspberry Pi

You can make your life easier by buying a prepared micro-SD card and power supply when you buy your Raspberry Pi, and for that matter you may as well get a USB keyboard and mouse (unless you have them lurking around the house somewhere). Let’s start the setup process by looking at what you will need and where to get it from.

Buying What You Need

Table 1-1 shows you what you will need for a fully functioning Raspberry Pi 2 system. The Raspberry Pi itself is sold through two worldwide distributors based in the UK: Farnell (and the related U.S. company Newark) and RS Components, as well as many online hobby electronics companies like Adafruit and Sparkfun.

Images

Table 1-1 A Raspberry Pi Kit

Power Supply

Figure 1-4 shows a typical USB power supply and USB-A-to-micro-USB lead.

Images

Figure 1-4 USB power supply.

You may be able to use a power supply from an old phone or the like, as long as it is 5V and can supply enough current. It is important not to overload the power supply because it could get hot and fail (or even be a fire hazard). Therefore, the power supply should be able to supply at least 500mA, but 1A would give the Raspberry Pi a little extra when it comes to powering the devices attached to its USB ports. If you have an older model B Pi, then you will need a 700mA power supply.

If you look closely at the specs written on the power supply, you should be able to determine its current supply capabilities. Sometimes its power-handling capabilities will be expressed in watts (W); if that’s the case, it should be at least 3W. If it indicates 5W, this is equivalent to 1A.

Keyboard and Mouse

The Raspberry Pi will work with pretty much any USB keyboard and mouse. You can also use most wireless USB keyboards and mice—the kind that come with their own dongle to plug into the USB port. This is quite a good idea, especially if they come as a pair. That way, you are only using up one of the USB ports. This will also come in quite handy in Chapter 11 when we use a wireless keyboard to control our Raspberry Pi–based robot.

Display

Including an RCA video output on the Raspberry Pi is, frankly, a bit puzzling because most people are going to go straight to the more modern HDMI connector. A low-cost 22-inch LCD TV will make a perfectly adequate display for the Pi. Indeed, you may just decide to use the main family TV, just plugging the Pi into the TV when you need it.

If you have a computer monitor with just a VGA connector, you are not going to be able to use it without an expensive converter box. On the other hand, if your monitor has a DVI connector, an inexpensive adapter will do the job well.

Micro-SD Card

You can use your own micro-SD card in the Raspberry Pi, but it will need to be prepared with the NOOBS (New Out of the Box Software) installer. This is a little fiddly, so you may just want to spend a dollar or two more and buy a micro-SD card that is already prepared and ready to go.

You can also find people at Raspberry Pi meet-ups who will be happy to help you prepare an micro-SD card. Look around on the Internet to find suppliers who sell prepared cards, with NOOBS. If you indeed want to “roll your own” SD card, refer to the instructions found at www.raspberrypi.org/downloads.

To prepare your own card, you must have another computer with a SD card reader.

A big advantage of making your own SD card is that you can actually choose from a range of operating system distributions. Table 1-2 shows the most popular ones available at the time of writing. Check on the Raspberry Pi Foundation’s website for newer distributions.

Images

Table 1-2 Raspberry Pi Linux Distributions

Of course, nothing is stopping you from buying a few micro-SD cards and trying out the different distributions to see which you prefer. However, if you are a Linux beginner, you should stick to the NOOBS installer and use the standard Raspbian distribution.

Case

The Raspberry Pi does not come in any kind of enclosure. This helps to keep the price down, but also makes it rather vulnerable to breakage. Therefore, it is a good idea to either make or buy a case as soon as you can. Figure 1-5 shows a few of the ready-made cases currently available.

Images

Figure 1-5 Commercial Raspberry Pi cases.

The cases shown are supplied by (a) Adafruit (www.adafruit.com), (b) SK Pang (www.skpang.co.uk/), and (c) ModMyPi (www.modmypi.com). The case you choose will depend on what you plan to do with your Raspberry Pi. If you have access to a 3D printer, you can also use the following open source designs:

Images www.thingiverse.com/thing:685074

Images www.thingiverse.com/thing:665042

You can also find a folded card design called the Raspberry Punnet at www.raspberrypi.org/archives/1310.

People are having a lot of fun building their Raspberry Pi into all sorts of repurposed containers, such as vintage computers and games consoles. One could even build a case using Legos. My first case for a Raspberry Pi was made by cutting holes in a plastic container that used to hold business cards (see Figure 1-6).

Images

Figure 1-6 A homemade Raspberry Pi case.

Wi-Fi

None of the Raspberry Pi models has support for Wi-Fi. Therefore, to wirelessly connect your Raspberry Pi to the network, you have just two options. The first is to use a USB wireless adapter that just plugs into a USB socket (see Figure 1-7). To configure Wi-Fi you will need to use the Wi-Fi Configuration tool that you will find in the Preference menu once you have your Pi up and running.

Images

Figure 1-7 Wi-Fi adapter.

The Wi-Fi adapters in the list referenced in Table 1-1 are purported to work with the Raspberry Pi. However, there are sometimes problems with Wi-Fi drivers, so be sure to check the Raspberry Pi forum and wiki for up-to-date information on compatible devices.

The second option for Wi-Fi is to use a Wi-Fi bridge with a Model B Raspberry Pi. These devices are usually USB powered and plug into the Ethernet socket on the Raspberry Pi. They are often used by the owners of game consoles that have an Ethernet socket but no Wi-Fi. This setup has the advantage in that the Raspberry Pi does not require any special configuration.

USB Hub

If you have one of the original Raspberry Pi model B, you will have just two USB ports available; you will rapidly run out of sockets. The way to obtain more USB ports is to use a USB hub (see Figure 1-8).

Images

Figure 1-8 A USB hub.

These hubs are available with anywhere from three to eight ports. Make sure that the port supports USB 2. It is also a good idea to use a “powered” USB hub so that you do not draw too much power from the Raspberry Pi.

Connecting Everything Together

Now that you have all the parts you need, let’s get it all plugged together and boot your Raspberry Pi for the first time. Figure 1-9 shows how everything needs to be connected. You may also want to use a Wi-Fi adapter in one of the USB ports.

Images

Figure 1-9 A Raspberry Pi system.

Insert the micro-SD card with NOOBS, connect the keyboard, mouse, and monitor to the Pi, attach the power supply, and you are ready to go.

 

Booting Up

To make sure that your installer will get the latest version of Raspbian, you should connect your Raspberry Pi to your network using an Ethernet cable during the installation process.

When the Raspberry Pi boots into the NOOBS Installer, you will be presented with a list of operating systems (Figure 1-10). Click the checkbox next to the first option (Raspbian [RECOMMENDED]) and then click on the “Install” button.

Images

Figure 1-10 Selecting an operating system to install with NOOBS.

After a warning that everything on the SD card will be erased, the installation will begin. During this process, which takes quite a while, the installer will show a series of informative messages (Figure 1-11).

Images

Figure 1-11 Installing Raspbian.

When the installer has finished installing Raspbian, an alert will pop up to tell you that installation has finished. Your Raspberry Pi will then reboot and then automatically run the raspi-config tool that lets you configure your Raspberry Pi after it boots for the first time (Figure 1-12).

Images

Figure 1-12 The raspi-config tool.

Select the option “Enable Boot to Desktop/Scratch,” press the ENTER key and then select the option “Desktop Log in as user pi at the graphical desktop,” and press ENTER again. This will configure the Raspberry Pi to automatically start the windowing environment each time it reboots.

Finally, use the right cursor key to select “Finish” in raspi-config and then press ENTER.

You will be prompted to reboot and when that is complete, you will be booted up into the desktop and ready for action.

 

Summary

Now that we have set up our Raspberry Pi and it is ready to use, we can start exploring some of its features and get a grip on the basics of Linux.