9781119046028-co0101.tif

IN THE PAGES of this book you’ll discover how to do great things with your Raspberry Pi. You’ll create art and music, programs, games, even create your own jukebox! But first, you need to get your system working.

If you are new to Raspberry Pi, the initial tasks of getting it set up and running might seem a little daunting but it is not that complicated to do. By setting up the Raspberry Pi yourself you will learn more about how it and other computers work. You will encounter technical jargon and procedures that you may not have come across before. In this chapter, I show you how to set up your Raspberry Pi so it is ready for you to use for the first time. I explain what hardware and software you need, and tell you how to put it all together into a working system. You’ll also learn how to create a backup copy of your system in case you need to replace it at some stage in the future.

What Hardware Do You Need?

Of course, the first thing you need is a Raspberry Pi. If you have used games consoles or computing devices before, you’ll notice something different about Raspberry Pi—it doesn’t come with a power supply, a charger or any connecting cables. It doesn’t have a storage device to keep your programs on either, or even a case!

So, to get started, you will first need to get the following hardware together (see Figure 1-1):

  • A Raspberry Pi
  • A micro USB power adapter
  • A USB keyboard and mouse
  • A desktop computer or laptop with an SD card reader/writer—this is to enable you to prepare an SD card with the software you need to run your Raspberry Pi
  • An 8 GB SD card for use with the Model B or an 8GB micro SD card for the B+
  • An HDMI cable—you will be using this with an HDMI TV or monitor
  • A monitor or TV
9781119046028-fg0101.tif

FIGURE 1-1 The essential hardware you’ll need before you can use your Raspberry Pi Model B or Model B+.

What Other Equipment Is Helpful?

The following additional accessories are not vital but you might want to consider acquiring some of them to improve your Raspberry Pi experience.

  • A case—To protect your Raspberry Pi from damage and make it easier for you to carry, think about buying a case like the PiBow shown in Figure 1-2, designed and manufactured by Pimoroni (http://shop.pimoroni.com/collections/customise-your-raspberry-pi). The great thing about this case is that it’s colourful and fun, and the ports are also labelled to remind you where each cable should be inserted.
    9781119046028-fg0102.tif

    FIGURE 1-2 The PiBow case can help protect your Raspberry Pi.

    Reproduced by permission of Pimoroni

    If you don’t want to spend cash on a case, why not create your own by using the Raspberry Pi Punnet? This template can be printed onto card stock, and then cut out and folded into a box. You can really let yourself get creative here and customise your case using pens, paints, stickers or coloured card stock to create a masterpiece. You can download the template from this site: http://squareitround.co.uk/Resources/Punnet_net_Mk1.pdf.

    Want a sturdier case? Build one with Lego blocks! You can find instructions to build the Lego Raspberry Pi case shown in Figure 1-3 on the official Lego website at http://www.thedailybrick.co.uk/instructions/.

.tif

FIGURE 1-3 Build a Lego case for your Raspberry Pi.

Reproduced by permission of The Daily Brick

  • A few spare SD cards—It’s worth having a few extra cards just in case the one you’re using becomes corrupted or stops working for any reason. They are also useful for backing up your files and projects—I explain how to do this at the end of the chapter.
  • An SD card reader/writer—You’ll need an SD card reader/writer to enable you to put the Raspberry Pi operating system software onto an SD card. You download the operating system software onto your computer, plug the card reader into a USB port on your computer and use it to copy the OS onto an SD card that you can then load onto your Raspberry Pi. Many desktop computers and laptops are already fitted with an SD card reader and writer but if your computer or laptop doesn’t have one, you will have to get an external USB card reader.
  • A Raspberry Pi camera moduleThe Raspberry Pi camera module is a Raspberry Pi camera board accessory for the Pi. It connects to the Pi with a flex cable and can be used to take digital images of whatever the camera is pointed at.
  • A Wi-Pi—The Wi-Pi is a small wireless dongle designed to be connected to a USB port on the Raspberry Pi so that you can add your Raspberry Pi to a wireless network, perhaps to share an Internet connection or files with other computers on the network.
  • A PiHub—As the Raspberry Pi has only two USB ports, you may find you run out of ports to plug in all your devices like a keyboard, mouse and WiFi dongle. The PiHub (http://shop.pimoroni.com/products/pihub) is a USB hub designed to work with the Raspberry Pi so that you can have access to more USB ports.

Setting Up the Raspberry Pi

Getting your Raspberry Pi up and running takes just three main steps. First, you need to download the operating system software and copy it onto an SD card. Next, you hook up the hardware—the mouse, keyboard and other components. Finally, you install the software onto your Pi and configure a few settings. The next few sections walk you through this process for a smooth launch. Don’t worry: Doing the actual steps is much easier than reading these instructions!

Downloading and Copying the Raspbian Operating System

All personal computing devices need an operating system (OS) to make them run. You’ve probably used a computer or laptop before, and the likelihood is that your computer’s operating system was Microsoft Windows for a PC, or Mac OS X for a Mac computer or Macbook. The Raspberry Pi can run a number of operating systems, but the OS most people use is Raspbian, which is a distribution of the free Linux operating system. The projects in this book assume you are using Raspbian on your Raspberry Pi, and the instructions in this section tell you how to download and install it.

Raspbian was created by a community of thousands of volunteers world-wide. You
can connect to this community and learn more about Raspbian and Linux at www.raspbian.org.

Preparing an SD Card to Store Your Software

A desktop or laptop computer uses a permanent storage device called a hard drive to store information and applications. The Raspberry Pi doesn’t have a hard drive, however, so your operating system, applications, and information all have to be stored on a removable SD card or micro SD card. This type of storage, known as flash memory, is the same as the kind you use with a digital camera to store all your photographs.

Before you plug in all the cables and so on, you first need to prepare (or flash) an SD card with the software the Raspberry Pi needs in order to run. This means that you format your SD card or micro SD card and copy the free Raspbian OS onto it. If you don’t do this step, your Raspberry Pi won’t recognise it as a storage device (like the hard drive of your computer) from which you can boot software. Don’t worry if these terms are unfamiliar to you—all will become clear as you read through this section.

Your card must be formatted, as described in the following steps, before any software is loaded onto it.

  1. The best way to ensure that the card is formatted correctly for use is to download, install and use SD Formatter 4.0 (www.sdcard.org/downloads/formatter_4) from the SD Association to your desktop or laptop computer. (The built-in Windows formatting tool will only format the first partition and not the entire disk, so it is important that you use the SD formatter 4.0 tool instead.)
  2. To download SD Formatter, follow the link in Step 1, and select either SD Formatter 4.0 for Windows Download or SD Formatter 4.0 for MAC Download. Read and agree to the terms and your download will begin. Once the download is complete, extract the file by clicking on Extract All and then run the setup application following the onscreen steps.
  3. With the SD Formatter installed on your computer, run the application. Make sure that it has the right drive selected for your card; for example it might be labeled D: or F: (see Figure 1-4).You can find out which drive is your SD card by looking in My Computer on a Windows computer or using Finder on Mac OS X.
  4. Click the Option button and select FULL (erase) from the drop-down menu. When you are ready, double-check that you have the correct drive selected, and click Format.
9781119046028-fg0104.tif

FIGURE 1-4 Formatting an SD Card using the SD Formatter application

Making It Easy with NOOBS

With your SD card formatted, you’re ready to copy the Raspbian software onto it. The New Out Of Box Software (NOOBS) produced by the Raspberry Pi Foundation allows you to copy the files you need straight onto the SD card like you would do with photo or document files. It gives you the option of selecting which operating system you want to install, and even provides recovery should you accidentally delete all your software files.

If you are using a micro SD card, then you may need an adapter so that it fits an SD card reader slot. The official Raspberry Pi NOOBS card has a micro SD card inside it, so you can use it as an adapter.

First, you need to download NOOBS onto a desktop or laptop computer with an SD card reader. After you download the software, you will save it to an SD card for use with your Raspberry Pi. The following steps walk you through the process:

  1. Navigate to the Raspberry Pi website at www.raspberrypi.org and click the Downloads tab at the top of the page. The New Out of Box Software that you are want to download is at the top of the page. Click the link to select the latest NOOBS .zip file.

    The download file is a compressed .zip file. Save the compressed file to your desktop or laptop computer, and then extract the files by right-clicking on the file and selecting the Extract All option (on a Microsoft Windows computer). You will then be given the option to extract the files to a directory or folder of your choice so that you will easily be able to find after the extraction is complete, as shown in Figure 1-5.

    9781119046028-fg0105.tif

    FIGURE 1-5 Extracting NOOBS to a directory on a windows computer

  2. Place your formatted card into the card reader slot on your desktop computer or laptop. Now copy the extracted NOOBS files from the directory or folder on your computer and paste them onto your newly formatted SD card. You can do this either by dragging the files from one window to another, or by highlighting them all with your mouse, right-clicking, and copy/pasting the files onto the card.

Plugging in the Hardware

Now it’s time to get your Raspberry Pi up and running. Find yourself a solid surface, like a desk or table, big enough to hold all your equipment. Make sure it’s near some main plug sockets. Ideally, you should also have access to a network device like a router because you will likely want to access the Internet on your Raspberry Pi at some point, but this is not necessary at this point to set up your Pi.

Set up your Raspberry Pi using the following steps:

  1. Place the card with the NOOBS files you have loaded onto it into the card slot of your Raspberry Pi on the back.
  2. Plug a USB keyboard and mouse into the USB slots on the Pi.
  3. Next, connect the HDMI cable from your TV or monitor to the HDMI port on the Pi and turn on your TV or monitor. Some TVs and monitors accept input from lots of different sources, so you may have to make sure that you set your TV or monitor to the HDMI setting. Some TVs and monitors will auto-detect the HDMI when you power up your Raspberry Pi.
  4. If you think you’ll be using the Internet on your Pi, connect a network cable to the Ethernet port.
  5. Finally, to start the Raspberry Pi, plug in the micro USB power supply. It is important to do this step last, as the Pi does not have a power button so the boot process will begin as soon as you plug it in.

Okay, your Pi is running!

Installing and Configuring the Software

When you power up your Raspberry Pi with a NOOBS SD card for the first time you will need to complete the setup of the software.

The new system will load and begin to resize the SD cards partition. Partitions are used to separate parts of a storage devices from each other. Once NOOBS completes this task your card will have three partitions: one called the boot partition, which holds all the files needed to start and run your Pi; one called the recovery partition; and one to store any files that you create, or applications that you add later.

The NOOBS software gives you the choice of installing one of several different operating systems, including RaspBMC and Pidora as well as Raspbian. To use the projects in this book, you should install Raspbian. See Figure 1-6.

9781119046028-fg0106.tif

FIGURE 1-6 Selecting an operating system to install using NOOBS

Follow these steps to install Raspbian:

  1. Select the operating system that you wish to install—Raspbian—and click Install OS. At this point you can also change any language settings.
  2. A warning will appear asking if you are sure you want to install the operating system as it will overwrite any file system already on the card. Click Yes.
  3. After installation of the operating system, on the first full boot, a window like the one shown in Figure 1-7 will load, asking you to provide some configuration settings. This screen is called the raspi-config. Here you can configure the following settings:
    • Internationalisation Options—This option lets you set the language and time zone for your Raspberry Pi. For example if you are in the UK, you may wish to set your language to English and time zone to GMT—Greenwich Mean Time.
    • Enable Camera—If you have a Pi Cam (a Raspberry Pi camera accessory), you should enable it here so that you will be able to use it.
    • Add to Rastrack—Rastrack (http://rastrack.co.uk/) is a website that pins your Pi’s location to a map of the world to let other people know you have a Pi and where you are located.
    • About raspi-config—Use this option to learn more about the raspi-config application.

You do not need to change any of the settings at this time, as you have the option of coming back to this window whenever you turn on your Pi, by typing sudo raspi-config after you log in.

9781119046028-fg0107.tif

FIGURE 1-7 The raspi-config menu

Logging in to Your Raspberry Pi

While your Raspberry Pi is booting up, you will see a lot of text moving very quickly on the screen. This tells you that the operating system is loading. It looks a little crazy, but don’t worry; you are not supposed to be able to read it. If something ever does go wrong, this text can be helpful to see where in the process the error occurred.

Once the startup (boot) of your Raspberry Pi has taken place, you will see the following prompts asking you to log in with your username and password:

raspberrypi login:
password:

The default user for the Raspberry Pi on Raspbian is called pi, and the default password is raspberry, so type pi for your login name at the first prompt and raspberry for your password in the second and press Enter.

Like many computing devices, you won’t be able to see what you type into the password box for security reasons. Don’t worry if you make a mistake, you will get another go.

After you log in and provide the password, the following text will appear:

pi@raspberry ~ $

The Raspberry Pi is asking you to give it a command. Type startx, as shown in
Figure 1-8.

9781119046028-fg0108.tif

FIGURE 1-8 Logging into Raspberry Pi and starting the desktop environment

The window shown in Figure 1-9, called Xwindows, will load. Congratulations! You’ve reached the graphical user interface for the Raspbian operating system. Read on to explore the interface a bit.

9781119046028-fg0109.tif

FIGURE 1-9 The Raspbian desktop

Exploring the Desktop in Raspbian

As you just saw, typing startx after logging into the Raspberry Pi loads Xwindows, or the graphical user interface, of the Raspbian operating system.

You will see the default Raspbian desktop shown in Figure 1-9, with the Raspberry Pi logo, a taskbar across the top with the time on the far right, and the main menu button icon on the far left. Some of the most commonly used applications can be launched from the Main Menu such as Scratch (see Adventure 3), Python (see Adventure 5), and a web browser that you can use to browse the World Wide Web if your Pi is connected to the Internet via an Ethernet cable or a wireless adapter like the Wi-Pi. There are even some games for you to try out using PyGame. Spend a few minutes checking out what applications are available by clicking on the main menu and then each of the submenus in turn. Figure 1-10 shows the applications available under the Accessories submenu.

To learn a little about how your Raspberry Pi is set up, try the following steps:

  1. Click on the main menu icon in the left corner of the taskbar.
  2. From the main menu, select AccessoriesImageDFile Manager to open the file browser. If you are logged in as the user pi, the browser will display the contents of your home directory (/home/pi). This directory will be fairly empty as you are yet to begin your programming adventures with Raspberry Pi. You will see a directory called Desktop. Right-click with your mouse on the desktop to open a drop-down menu and select Create NewBlank File. Name the file hello and click ok. You will see an icon appear on the desktop, and if you double-click the directory folder Desktop in the file manager window, you will see that it contains the hello file too.
.tif

FIGURE 1-10 Using the main menu and file browser in Raspbian

Shutting Down Your Raspberry Pi

When you shut down your Raspberry Pi, it is very important that you don’t simply remove the power supply, but make sure you always instruct the OS to shut down safely. The latest version of NOOBS has a Shutdown button for shutting down your Raspberry Pi cleanly if you are using the GUI—just click on Menu followed by Shutdown to open a menu with options to shut down, reboot, and log out.

However, if you are not using the GUI, you will not see this icon, and will need to use a text command to shut down your Raspberry Pi. You can learn how to do this in Adventure 2, in the section “Using Shutdown and Restart Commands”.

Backing up an SD Card Image

You have only used your Raspberry Pi once so far, but you have already made changes to the configuration of the operating system. As you move through the projects in this book, you may wish to make copies as you go along to make sure you don’t lose any of your work if your SD card or micro SD card stops working for any reason. It is very easy to do this using a free Windows application called Win32 Disk Imager. Download this application from http://sourceforge.net/projects/win32diskimager before continuing with the following steps.

  1. First, if you have not yet shut down your Raspberry Pi, follow the instructions in the previous section to do so now, using the following command:

    sudo shutdown -h now

  2. Take your SD card out of your Pi and place it into your computer’s SD card reader.
  3. Run the Win32 Disk Imager on your desktop computer by locating the folder into which you extracted it and double-clicking the application icon.
  4. In the Image File box (see Figure 1-11), type a name of your choice for your backed-up image—Adventures_In_Pi, for example.
  5. Click the folder icon to browse to a location on your computer where you would like to save your backed-up image.
  6. Click Read to copy the image from the SD card to your computer.
  7. Wait for the progress bar to become full before closing the software and removing your SD card.

In the future, when you become more skilled, it’s likely you will have multiple cards with different project images on them. You can save all these to your computer separately. It’s a good idea to back them up in this way, to keep all your files safe. It is also best to store one image on one card and use separate cards for each project you work on.

.tif

FIGURE 1-11 Using Win 32 Disk Imager to make a backup of an SD card or micro SD card

Raspberry Pi Startup Command Quick Reference Table

Command

Description

startx

Launches the Raspbian desktop environment (GUI).

sudo

Gives the user root or super user permissions.

sudo shutdown -h now

Shuts down (halts) the power to the Raspberry Pi.

sudo shutdown -r now

Shuts down the power to the Raspberry Pi and then restarts it.

1-badges-unlocked_fmt.tif

Achievement Unlocked: Your Raspberry Pi is up and running!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset