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.
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):
The following additional accessories are not vital but you might want to consider acquiring some of them to improve your Raspberry Pi experience.
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/.
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!
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.
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.
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:
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.
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:
Okay, your Pi is running!
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.
Follow these steps to install Raspbian:
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.
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.
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.
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:
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”.
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.
sudo shutdown -h now
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.
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. |