Chapter 1. Meet Raspberry Pi

In this chapter, you’ll learn how to

  • Set up your Raspberry Pi
  • Install an operating system—Raspbian—on your Pi
  • Find and open applications
  • Write your first bit of code in Python

What kinds of things do you think you can do with a Raspberry Pi?

1.  Play games.

2.  Watch videos.

3.  Create a video game.

4.  Listen to music.

5.  Make a sound mixer for a dance party.

6.  Build a robot.

Believe it or not, these are all projects you can do yourself, and if you learn to program in Python, the sky is the limit. You can achieve quite a lot on your Pi, as long as you can write a program to do it. But before we talk about that, let’s take a look at a Raspberry Pi and discover what makes it tick.

What is the Raspberry Pi?

The Raspberry Pi, sometimes referred to as the Pi, is a small, low-cost computer invented in the U.K. by the Raspberry Pi Foundation. It provides an easy-to-use tool to help you learn to code in Python (the Pi part of its name came from the focus on using it to code in Python).

About the size of a deck of cards, it isn’t as powerful as a laptop or desktop computer; its computing power is more similar to that of a smart phone. But what it lacks in processing power, it makes up for in its many features:

  • Its readiness for programming in Python
  • The many ways you can use it
  • Its small size and cost

The Pi, with its companion memory card, is preloaded with all the software you need to jump into programming in Python. Type in commands, and see what happens. Enter a program you find on the internet or in a magazine, run it, and see how it works. The Pi is made for you to learn to code by playing with it, using it, and interacting with it.

Once you learn to program in Python, you can use your Pi as a base for all sorts of projects—with your imagination, the possibilities are endless! The Pi’s small size makes it easy to carry around and include in projects. Hide it on a shelf or mount it on a wall with a camera to make a security system; power it with a rechargeable battery pack if you need it to be portable; or even attach it to a remote-controlled car or helicopter. And if you happen to mess something up, it’s simple to recover. Even if you manage to break the Pi, it’s pretty cheap to replace.

At its core, the Raspberry Pi is a circuit board that has all the components found in many computers. The next section checks out the components of the Pi and explores what they do. Let’s go!

Exploring your Raspberry Pi’s parts: hardware

Ever look closely at an insect under a magnifying glass, or take apart a toy? Humans are naturally curious about what makes things work. What are the different parts, and what do they do? What parts are unique? Let’s treat the Raspberry Pi the same way, explore its parts, and learn how to set it up.

Luckily, you don’t have to break it open to see its parts. You can see the Raspberry Pi’s components displayed before you on the green circuit board in your hand (see figure 1.1). Let’s walk through the parts of the Raspberry Pi and see what they do. We’ll be focusing on the Raspberry Pi 2 Model B; if you have a Raspberry Pi 1 Model B+ or B, see appendix B for more information.

Figure 1.1. The Raspberry Pi provides an excellent platform for learning to program in Python. It includes many input and output ports to give you flexibility in how you connect it. As you would with a desktop computer, you need to connect a keyboard, mouse, monitor, and power cable before you can start using your Pi.

Defining some tech terms

Input and output are terms used for communication to and from a computer.

USB refers to a common connector found on computers. It’s used to plug in a keyboard, a mouse, flash drives, and many other computer peripherals.

HDMI is a standard way to connect devices to high-definition TVs or monitors. We’ll talk about this more later, when we discuss connecting a TV or monitor to your Raspberry Pi.

Ethernet is a technology used to connect computers together into a network. This port provides a way to plug in and connect to the internet or your home network if a wireless connection isn’t available.

Giving your Pi a cozy home: Pi cases

We all like to be warm and cozy in our homes. A Raspberry Pi is no different. Do the right thing and protect your Pi by putting it in a case (see figure 1.2). If your Pi didn’t come with a case, you have a lot of options. You can buy one or make your own. My favorite approach is to make my own case from wood, cardboard, a plastic container, or even LEGOs. The key is making sure your Pi is protected from accidental drops and, ideally, spills. But before you close up your Pi in a case, let’s take a closer look at some of its features.

Figure 1.2. A case protects your Raspberry Pi from damage while making it easy to access the ports. Some people use a case to give their Pi a unique personality. You can purchase a case or, better yet, make your own. Plastic cases are the most common, but these pictures show examples of cases made from paper, plastic, and aluminum. You could even try using LEGOs to make one.

The brain of your Pi: system on a chip

Meet the brain of your Raspberry Pi. The system on a chip (SoC) is the black square in the middle of the Pi circuit board in figure 1.3. This incredible chip is a package of many parts: the central processing unit (CPU), the graphics processing unit (GPU), the digital signal processor, and the Pi’s working memory. The chip provides the computing power, graphics power, and memory to run apps and play videos.

Figure 1.3. The Raspberry Pi’s system on a chip (SoC) contains its computing and graphics processing power and working memory. The Pi uses the ARM11 microprocessor as its CPU and the VideoCore IV for its GPU. The ARM11 microprocessor is found in handheld electronics such as smart phones and gaming systems. The SoC in the Raspberry Pi 2 Model B comes with 1 GB of RAM.

The Pi’s CPU handles running applications and executing instructions. The same processor is also found in smart phones and e-readers. Think of it as the part of your brain that allows you to follow instructions and calculate the answer to math problems.

The GPU is like the visual part of your brain that allows you to visualize a 3D object in your mind or track a ball thrown to you. It handles the Pi’s multimedia tasks, like processing digital images, drawing graphics, and playing videos. The GPU gives your Pi surprisingly good high-definition video-playback capabilities. Both the central processor and the graphics processor share the Pi’s working memory, or RAM, which is part of the SoC.

Working memory: RAM

Question: Can you remember the following grocery store list? Bananas, milk, peanut butter, jam, bread. Read the list once more, and then look away from the book and try to recite the list from memory.

To remember it, you need to hold the names of the items in your memory. You only have to store them for a short time. Once you go to the store and buy the items, you can forget them.

When a computer is working, it does much the same thing. It may have to remember and process millions of instructions and bits of information each second, but it can often forget them once it’s done processing them. The computer does this using working memory or random access memory (RAM). It’s packed in the SoC, and it gives your Raspberry Pi the ability to process instructions quickly by remembering pieces of information as it’s working and forgetting them when they’re no longer needed—much like how the neurons in your brain work together to remember a grocery list. Later, we’ll talk about storing information for the long term and where that happens.

Connecting a keyboard and mouse: USB ports

Meet the USB ports on your Raspberry Pi. The two metal, rectangular boxes each contain two USB ports, shown in figure 1.4. USB stands for Universal Serial Bus.[1] The Pi provides USB ports to allow you to connect a keyboard, a mouse, flash drives, and other USB peripherals.

1

The U for Universal is because it provides computer makers and computer equipment makers with a standard way to connect things to computers. Things connected to a computer are often called peripherals.

Figure 1.4. The Raspberry Pi 2 Model B has four USB ports. They’re on the board in two sets of two, side by side. The USB ports are useful for connecting a keyboard and mouse to your Pi. A USB hub can also be plugged in to allow for even more peripherals.

Why are they called ports?

Back in ancient times, when Romans walked around and spoke Latin to each other, the word for a gate or door was porta. Although computers don’t have doors or gates, they have places where you plug things in, called ports.

Ports allow electrical signals to go in and out of your computer. Without ports, you wouldn’t be able to view your computer’s screen, download web pages, or move a mouse.

Let’s pretend you could shrink and that you had special glasses so you could see these electrical signals. What would you see when I pressed the E key on the keyboard? You’d see an electrical signal flying from the keyboard through the keyboard’s wire, through the port on the computer, and into the computer. The port acts like a gate, allowing signals to go into or out of your computer.

Get your keyboard and mouse. Let’s plug them into your Pi.

Connecting a keyboard

You’ll need a keyboard that plugs into a USB port. Figure 1.5 shows an example of a keyboard with a USB connector.[2]

2

If you don’t have a keyboard with a USB connector, have no fear. You can find one for under $15 online or at your local computer or electronics store.

Figure 1.5. You need a USB keyboard to type and enter commands on your Raspberry Pi. The keyboard plugs into one of the four available USB ports on the Raspberry Pi 2 Model B.

To attach your keyboard to your Pi, plug the wire from your keyboard into your Raspberry Pi’s USB port. There are four USB ports on your Pi. It doesn’t matter which one you choose.

Tip

If the keyboard’s USB connector doesn’t fit into the Raspberry Pi’s USB connector, flip over the connector and try again. USB connectors only fit in one way.

Fantastic! Your keyboard is connected to your Pi. It’s time to move on to adding a mouse.

Connecting a mouse

For this step, you need a mouse that plugs into a USB port. The keyboard is using one of your Raspberry Pi’s four USB ports. Plug your mouse into one of the other ports.

Another option: wireless keyboard and mouse combination

If you own a wireless keyboard and mouse combination, instead of using wires, you can plug the USB dongle into one of the USB ports on the Pi. This frees up one of your USB ports, which can be handy should you decide to attach multiple USB devices such as a USB Wi-Fi adapter or USB flash drives, or if you want fewer wires on your desk.

Excellent! Giving your Pi the ability to store and retrieve information is your next task.

Storing memories: your Pi gets a memory card

We all like to remember things that are important to us. Birthdays, vacations, and holidays are wonderful times, and we’ve invented ways to help us recall them. You might use a scrapbook or a photo album to store memories. Even after many years, you can open these books and remember these past events.

In addition to working memory (RAM), computers also need a way to remember things, even if they’re turned off for long periods of time. The Raspberry Pi, like all computers, has this capability for memory storage, letting it save and retrieve data, files, and applications. Much like a photo album lets you recall holidays, the Pi’s memory storage allows you to store important applications and information. You’ll use this capability when you learn how to save sets of Python instructions or programs.

SD memory card

A Raspberry Pi is different from most computers because its memory storage is contained on an SD memory card, whereas most laptops and desktops use a hard drive. Files, applications, and even the Pi’s operating system are all stored on the SD memory card, whether it’s a Python game you’re creating or a new music player app for your Pi. If you purchase a Raspberry Pi kit, it will come with an SD card (see figure 1.6).[3]

3

See http://elinux.org/RPi_SD_cards for more information on compatible cards.

Figure 1.6. An SD memory card provides the storage memory used by the Raspberry Pi to hold all the software and files, including the operating system. Raspberry Pi kits come with an SD memory card preloaded with the software needed to start up your Pi. The two left images show the location of the SD memory card slot on the underside of the Pi board. The right image shows an SD memory card inserted into the SD card slot.

SD cards come in various sizes

SD cards come in three sizes: the full-size SD card (largest), the miniSD, and the microSD (smallest). The Raspberry Pi 2 Model B uses a microSD card.

You can add more storage to your Pi by attaching USB peripherals such as a USB flash drive or a USB hard drive.

NOOBS

Your Raspberry Pi kit comes with an SD card preloaded with NOOBS. Developed by the Raspberry Pi Foundation, New Out of the Box Software (NOOBS) is a set of files that helps you set up your Pi for the first time. If you lose yours or need a NOOBS SD memory card, you can buy new ones online. Alternatively, if you have an SD card and want to install NOOBS on it, go to the Raspberry Pi Foundation website (www.raspberrypi.org/downloads) to learn how.

SD memory card slot

Figure 1.6 shows the location of the SD memory card slot. This thin, metal slot is on the underside of the Raspberry Pi. For your Pi to work when you plug it in, it must have some initial knowledge to start up and display something on the screen. In addition to this startup information, it must also have a place to store any new information.

Inserting the SD card in the slot

Hold the card so that the end with the metal contacts is facing up and toward the Pi. Insert the card along the underside of the board into the slot. You’ll hear a small click as the card is pushed into the slot. The card is held in place by a small spring mechanism. The card will only fit in one way, so if it doesn’t fit, flip it over. If you need to remove the card, push it in again (you’ll hear a click); then you can pull it out.

Replacing a lost or broken SD card

If you lose your SD card, you lose the information, applications, and operating system that are stored on the card. It’s as if you lost your hard drive on a home computer. You can easily replace the card, but you’ll be starting over fresh. Here are the two options for replacing the card:

  • Purchase an SD card at the store, and set it up anew. It’s recommended that you get an SD memory card with at least 8 GB of storage space. You can download and install the startup software from the Raspberry Pi Foundation at www.raspberrypi.org/downloads. See appendix A for instructions on how to make a new SD card for your Raspberry Pi.
  • Buy an SD memory card preinstalled with the Raspberry Pi startup software. You can find cards for sale on the Raspberry Pi Foundation website and at online retailers.
SD cards make your Pi’s memory portable

If your Raspberry Pi ever breaks, you can remove the SD memory card and insert it into a new Pi. All your files and software will be there. It’s like taking your photo album with you to a new house. The memories are safe in the photo album, ready for you to enjoy.

Tip

You can set up multiple SD cards for your Raspberry Pi and switch them whenever you want to give your Pi a whole different personality. Maybe set up an SD card for the Pi as a media center, complete with games, music, and videos. Set up another for your Pi robot project. Each memory card can be set up uniquely, with different operating systems, applications, and files. Swap out the SD card and reboot your Pi, and you instantly have a Pi with different traits to meet your needs.

Connecting a TV or monitor: HDMI port

The HDMI port, shown in figure 1.7, is for connecting your Raspberry Pi to a TV or monitor. HDMI stands for high-definition multimedia interface. The output provides a combined audio and video signal—meaning both sound and picture come out of this port and go to your TV or monitor. If you want a crisp, clear display and you already own a high-definition TV or monitor, then you’ll want to connect your Raspberry Pi to it using the HDMI output port. Because the HDMI output contains audio and video signals, if your TV or monitor has built-in speakers, the sound from your Raspberry Pi can be set to come out of the speakers rather than through the 3.5 mm audio output.

Figure 1.7. The HDMI port on the Raspberry Pi provides a high-definition audio and video signal that can be connected to a TV or monitor. Use an HDMI cable to connect your Pi to your TV or monitor. Depending on the connectors available on the TV or monitor, you may need an adapter.

Now that you know about the HDMI port, let’s see how you can connect your Pi to a TV or monitor.

Connecting your Pi to a TV or monitor

Once you decide on the TV or monitor you plan to use, you’ll need to look for the available video input ports on the TV or monitor (look on the back or sides to find them). What kinds of ports do you see? Unfortunately, manufacturers often provide a variety of different ports. Think of it like a matching game. Your goal is to match the connectors on your TV to the connectors on the Pi. If they don’t match, you’ll need to use one of the adapters discussed in a minute. Either way, you’re sure to get it solved.

Identifying ports and making the connection

Take time to study the connections on your TV or monitor. Try to identify the video ports, comparing them to the pictures of connectors in figure 1.8.

Figure 1.8. HDMI and DVI are common types of video input ports found on modern TVs and monitors. It’s easiest to connect a Raspberry Pi to a TV or monitor with an HDMI port. HDMI provides a highdefinition picture and doesn’t require any adapters or converters—only an HDMI cable, which is included in many Pi kits. The DVI port requires a special adapter to connect with a Pi.

This section provides instructions on how you can connect your Pi to a TV or monitor with either an HDMI or a DVI port. If your TV or monitor has different video input ports, check appendix B for tips on connecting to them.

HDMI

The HDMI port is a metal, mostly rectangular port that is labeled HDMI. Connect an HDMI cable from the screen’s HDMI port to your Raspberry Pi’s HDMI port (see figure 1.9). If you’ve connected your HDMI cable, you can now skip ahead to the discussion of other ports on the Pi.

Figure 1.9. A Raspberry Pi can be connected to a TV or monitor using an HDMI cable. Connect the cable from the Pi’s HDMI port to the TV’s or monitor’s HDMI input. In addition to video, the HDMI cable also contains the Pi’s audio output, which can be played through the TV’s or monitor’s speakers.

DVI

DVI ports on TVs and monitors come in several different forms. They’re all rectangular ports with three rows of eight square pinholes and a horizontal hole or set of holes next to them. If you already have an HDMI cable, the solution is to purchase an HDMI-to-DVI adapter. You can find these online or in a computer store. Plug the adapter into the computer screen’s DVI port, and then plug your HDMI cable into the back of the adapter and the other end into the HDMI port on your Raspberry Pi (see figure 1.10).

Figure 1.10. The Raspberry Pi can be connected to a TV or monitor with a DVI port using an HDMI-to-DVI adapter and an HDMI cable. One end of the HDMI cable plugs into the Pi’s HDMI port. The other is connected to the adapter, and the adapter is connected to the TV or monitor. Adapters are available through online retailers or local computer stores.

Another solution, rather than to use an adapter, is to purchase a DVI-to-HDMI cable. These can be found online or at a computer store. Plug the DVI connector on the cable into your computer screen, and plug the HDMI connector into your Pi’s HDMI port.

Great! You’ve completed an important step by connecting your Pi to a TV or monitor.

Other ports and connections

You’ll find other ports on your Raspberry Pi. We’ll cover those in later chapters, or you can reference appendix B for more information on specific ports and connections. Some of these include the following:

  • GPIO pins —The two long rows of pins on the Raspberry Pi are used to send and receive electrical signals. Part 3 of this book will cover how to program those pins and build projects.
  • Internet —You can connect your Raspberry Pi to the internet or your home network by plugging in an Ethernet cable. But you may find that the easiest way to get online is to use the USB Wi-Fi adapter that is provided in many Raspberry Pi kits. Appendix B has information on the Ethernet port and using USB Wi-Fi adapters.
  • 3.5 mm audio/video out —The small round connector is for plugging in headphones or powered speakers. Chapter 8 will show you how to play sounds as you turn your Raspberry Pi into a music player.

Let’s see how you can get power to your Pi.

Powering your Pi: microUSB power port

Power for your Raspberry Pi is supplied through the microUSB power port located near a corner of the board (see figure 1.11). This port is where you connect a power supply to your Pi; it’s the same as the port found on many mobile phones. Raspberry Pi kits come with a microUSB power supply.

Figure 1.11. The Raspberry Pi requires a microUSB power supply that provides at least 1.2 A of electric current. If you plan to use all the USB ports on your Pi, you may want one that provides 2 A or more of electric current. The recommended voltage is 5 volts (V), but the Pi can operate at voltages ranging from 4.8 to 5.2 V. If you have a power supply you want to use with your Pi, check its output voltage and current, which are listed on the charger in small print. In this example, the charger has an output of 5.1 V and 2.5 A of current, making it a suitable power supply for a Pi. Using the incorrect voltage or insufficient current can damage or destroy your Pi, so check carefully.

Note

Only certain mobile phone chargers can be used to power your Raspberry Pi. The charger must produce sufficient electrical current to power it. If you want to go this route, then you should read the fine print on the charger. The charger must produce 1.2 amp (A) or more for the Pi.

It’s alive! Plugging in the Pi

Before plugging your Raspberry Pi into the power supply, go through this quick checklist:

1.  Are you sure your keyboard, mouse, and monitor are connected to the Pi?

2.  Have you turned on your TV or monitor and set it to the correct input source? For example, if you plugged your Raspberry Pi into the TV’s HDMI port, make sure the TV is set to HDMI input.

3.  Have you inserted your SD card with NOOBS into your Pi?

An example setup is shown in figure 1.12.

Figure 1.12. Example setup of a Raspberry Pi with peripherals connected and SD card inserted. A keyboard and mouse are connected to the Pi’s two available USB ports. A microUSB power supply is plugged into the Pi; the other end is lying on the desk, ready to be plugged into the wall. An HDMI cable is connected from the Pi’s HDMI port to the back of the monitor. The Ethernet port has an Ethernet cable plugged into it from a router (not shown).

Tip

TVs and monitors often allow you to connect multiple video sources. Maybe your TV has a Wii, a DVD player, and a digital video recorder. These TVs and monitors have the option to select which input is displayed to the screen. Use your TV’s or monitor’s input selector to set the correct input.

All right, if you have all three steps checked off, it’s time to power up your Raspberry Pi. Plug your power supply into a wall outlet, and plug the microUSB connector into your Pi. Your Pi’s lights will begin to flash. Enjoy the beautiful glow from the lights—this is a sign that your Raspberry Pi is starting up. It’s also referred to as booting; this is when the computer detects the devices you have connected to it and starts up the computer’s operating system (OS). Some believe the term boot originated from kicking a horse to get it to start moving. You can imagine that you’re giving your Pi a bit of a boot to get it started.

Getting your Pi running: software

You’ve got your Pi plugged in and ready to rock. It’s time to get it running and doing something useful—and for that, you need some software.

An OS is a common set of instructions, or software, that helps manage the computer. Common OSs you’ve most likely encountered are Microsoft Windows, Apple’s OS X, and Linux. All of these OSs control the connection of your keyboard, mouse, monitor, and other peripherals. Most important, the OS serves as a foundation for you to put applications on your computer and use them.

The SD memory card that comes with your Pi kit already contains the files for installing several different OSs on your Pi. We’ll step through installing the Raspbian OS—the default for the Pi—and configuring it.

Installing the Raspbian operating system

The first time you boot a Raspberry Pi, you’ll need to install an OS on it and then configure it to work nicely for you. Let’s walk through the first task: installing an OS. You’ll configure it in the next section. Once you plug in your Pi, you’ll see the NOOBS menu for selecting an OS, as shown in figure 1.13.

Figure 1.13. The NOOBS selection menu allows you to choose the OS you want to install on your SD card and use with your Raspberry Pi. This menu appears the first time you start up your Pi.

The Raspberry Pi has a variety of OSs that can be installed on it. The Raspberry Pi Foundation recommends the Raspbian OS, and it’s what we’ll use for this book. Let’s go over how to install it on your Pi.

What if you don’t see the NOOBS software screen?

If you don’t see the NOOBS software screen after your Pi boots up for the first time, then there are a few things to check.

If you don’t see lights flashing on your Pi when you plug it in, make sure the electrical outlet you’re using has power. Many a Pi owner has accidentally plugged a Pi into a power strip and forgotten to switch on the power strip. Sounds silly, but even the best programmers make mistakes.

If your Pi’s lights blink when you plug in the power supply but the screen of your monitor doesn’t show anything, make sure the monitor is plugged into an electrical outlet, the HDMI cable is connected from the monitor to the Pi, and you’ve turned on the monitor.

Finally, if your Pi starts booting up and you see lots of messages displaying on a black screen, but you never see the NOOBS selection menu, it’s likely that your SD card has an error. See appendix A for ways to fix an SD card.

Sometimes you’ll run into issues with your Pi. If you do, use the troubleshooting steps in appendix A, and search the Raspberry Pi Foundation website[a] to find solutions.

a

The Raspberry Pi Foundation website is www.raspberrypi.org.

On the NOOBS selection menu (see figure 1.13), follow these steps:

1.  Select Raspbian (make sure there is an X in the box next to Raspbian; if not, click the box to select it).

2.  Click the Install button at the top of the menu.

3.  A message appears, warning you that the process will install the OS and that all existing data on your SD card will be overwritten.[4] Select Yes to continue with the installation.

4

When you’re warned that all data will be overwritten, this doesn’t include NOOBS, which is retained on the SD card so that you can reinstall the OS if you ever need to.

4.  Wait for the installation to complete. It will take 5 to 10 minutes, so get a drink or grab a snack while you’re waiting.

5.  When the installation is done, a box pops up, letting you know the OS was installed successfully. Click OK, and your Raspberry Pi will start loading Raspbian.

6.  When it’s finished loading Raspbian, your Raspberry Pi reboots itself. A black screen appears, followed by many, many, many messages. Don’t worry; the messages are the Pi performing its startup tasks, such as detecting the keyboard, mouse, and TV or monitor.

Kudos to you! You’ve installed your Raspberry Pi’s OS, Raspbian. Now you’ll want to configure how it works to suit you.

Configuring the operating system: making it yours

You’ve finished installing the Raspbian OS on your SD memory card and gotten it running for the first time. The next thing you’ll see is the Raspberry Pi configuration screen, shown in figure 1.14.

Figure 1.14. When your Pi boots up for the first time, you’ll see the Raspberry Pi configuration menu. This menu makes it easier to set up your Pi by allowing you to change settings such as the time zone and keyboard layout. The menu also has the option to set your Pi to always boot to the Raspbian desktop environment.

Tip

You can’t use your mouse with this menu! Use the arrow keys (up, down, left, and right) and Tab key to move around the menu instead. Press Enter to select the highlighted menu item.

Let’s walk through some of the basic configuration settings you may want to change.

Changing the keyboard settings

The Raspberry Pi is made in the U.K., so it’s preset to a U.K. keyboard. If you live in other parts of the world, the keyboard may make unexpected characters appear on the screen. For example, you might type a # symbol (Shift-3), and your Pi displays the symbol for a British pound. Weird, right?

You can use the configuration tool to change your Pi’s keyboard layout by following these steps:

1.  On the Raspberry Pi configuration menu, select option 4—Internationalisation Options—and press Enter.

2.  Select Change Keyboard Layout, and press Enter.

3.  Select your keyboard model—for example, Dell—and press Enter.

4.  You see options for the keyboard layout’s country of origin. Select the appropriate country, and press Enter.

5.  A list of keyboard layouts appears. Select the one for your location, and press Enter.

6.  On the next series of screens, you can set shortcut keys. Set them to match your personal preferences. If you aren’t sure, accept the defaults (press Enter until you’re back to the configuration menu).

You can always return to the configuration tool if needed. You’ll learn how in a later section when you’re introduced to the command-line mode for Raspbian.

Choosing how your Raspberry Pi starts up

Raspbian, like most OSs, allows you to use it in two different ways (see figure 1.15):

Figure 1.15. Example screen images of a command-line mode (top) and a GUI mode (bottom) for a Raspberry Pi running the Raspbian OS. The command-line mode is text-based: you enter instructions at the prompt. The GUI is pretty much the same as a Windows or Mac interface, with windows, icons, and menus that you interact with using a mouse pointer.

  • Command-line mode —You type in commands to the OS. This can be tough for novices, because you need to know the commands and type them in exactly. Because this mode is more difficult to use, you’ll only use it in this book when you need to run commands that require administrative or super-user permissions. For example, you’ll need the command line when you make Python programs that use the GPIO pins or you want to alter your Pi’s configuration.
  • Graphical-user-interface (GUI) mode —Everything appears in windows, icons, and menus that are point and click. Just like on Windows and Mac computers, this will be your main way to interact with your Pi and program in Python. It represents the most natural way to access applications, files, and folders.

Question: Which option do you prefer?

  • Your Raspberry Pi booting up to a screen with a blinking cursor, waiting for you to type in commands
  • Your Raspberry Pi booting up and showing you a desktop with application icons arranged on the screen, waiting for you to point to and click them with your mouse

If you chose the second option, you can set Raspbian to always boot to the desktop with the following steps:

1.  On the Raspberry Pi configuration menu, select option 3—Enable Boot to Desktop/Scratch—and press Enter.

2.  Select the second option—“Desktop Log in as user ‘pi’ at the graphical desktop”—and press Enter.

Fantastic! Next time your Raspberry Pi boots up, you’ll be taken to the Raspbian desktop.

Tip

If you decide you prefer to boot the Raspberry Pi to the command line, you can always launch the Raspbian desktop by entering startx at the command line.

Tip

Sometimes you may find yourself using the Raspbian GUI, but you want to use the command line. There is an easy way to change. You can open the command-line mode in a window by clicking the Menu Button, then selecting the Accessories category and clicking the Terminal[5] icon.

5

Terminal is short for LXTerminal or Linux terminal. Raspbian is a Linux-based OS, and terminal refers to the command-line mode where you can enter commands.

Making other changes

The Raspberry Pi configuration menu includes other options such as setting up a camera and over-clocking. These are available if you ever want to use them. Check the Raspberry Pi forums for more information on these options.

Saving your configuration and rebooting

If you’re happy with the changes made to your Raspberry Pi, follow these steps to exit the Raspberry Pi configuration tool and reboot your Pi:

1.  On the Raspberry Pi configuration menu, use the arrow keys to select Finish, and press Enter.

2.  You’re prompted with this message: “Do you want to reboot now?” Select Yes, and press Enter.

Your Raspberry Pi will display lots of lines of text as it boots up. (Yes, it does that again! Don’t worry, it will seem normal to you soon.) This is your Pi’s startup sequence when it connects peripherals and starts up the OS. Next, a white screen with a Raspberry Pi will appear, along with a set of icons—this is your Raspbian desktop (see figure 1.16). Congratulations! Your Raspberry Pi is ready to go.

Figure 1.16. A view of the Raspbian desktop after your Raspberry Pi boots up. The desktop is similar to the desktop in Microsoft Windows or Apple Mac OS X. Don’t worry if your desktop is different from this one. Depending on when you bought your Pi, you may have received an SD card with an older or newer version of Raspbian.

A bit of Pi in your face: troubleshooting

If you don’t see the view shown in figure 1.16, don’t be discouraged. It’s likely that you didn’t select the option to boot to desktop. If your screen shows the command-line mode for Raspbian (figure 1.17), you can log in and launch the Raspbian GUI.

Figure 1.17. If you didn’t set up your Pi to boot to the Raspbian desktop, the command-line mode will be displayed when your Raspberry Pi boots up. It will ask you for your login name and password.

At the command line, you’ll be prompted to enter your login and password. The default login is pi, and the password is raspberry. After entering that information, launch the Raspbian Desktop from the command line using the following steps:

1.  Type startx.

2.  Press Enter.

Once you execute the command, the Pi will start up the Raspbian GUI mode and display your Raspberry Pi’s desktop. If you happen to have a different problem, head to appendix A for troubleshooting ideas.

Getting around: learning Raspbian

Take a cruise around your Raspberry Pi, and look at some of the applications that come already installed with the Raspbian OS.

Finding and opening applications on your Raspberry Pi

There are many applications on your Raspberry Pi. You can access them by clicking the Menu button in the top-left corner of the desktop (see figure 1.18). Enjoy exploring what comes installed on your Pi.

Figure 1.18. The Raspbian application menu opens when you click the Menu button in the top-left corner of the desktop. You can open an application by moving your mouse over the categories listed on the menu and then clicking the application.

Your files and folders

Similar to Windows Explorer or Mac Finder, Raspbian has some built-in tools to make it easier to navigate the folders and files on your Raspberry Pi. In Raspbian, the application for managing files is called File Manager, and it’s accessed by clicking the folder icon located in the top-left corner of the Raspbian desktop. Figure 1.19 shows the icon and the File Manager application. Just as in Windows Explorer, you can

Figure 1.19. File Manager in Raspbian allows you to manage files as you do in Windows Explorer or Mac Finder. You access File Manager using the folder icon in the upper-left corner of the desktop. This is a view of a Pi with a lot of files stored in the /home/pi folder.

  • Navigate into folders by double-clicking them.
  • Drag files to move them to another folder.
  • Copy and paste files using the right-click menu on files and folders.
  • Rename files.
  • Open files by double-clicking them.

The Pi was built for coding. Let’s see how you can write code on your Pi.

Writing code

You’re going to learn to write code in the Python programming language. Meet a new program, IDLE. IDLE is a tool that’ll help you write programs in Python. IDLE stands for Integrated DeveLopment Environment. The Python language was named after Monty Python, and the IDLE acronym is a nod to Eric Idle, one of the founding Monty Python members.

Follow these steps:

Click the Menu button on your desktop.

Select Programming > Python 3.

After a second or two, IDLE opens the Python Shell, as shown in figure 1.20.

Figure 1.20. IDLE is a development environment that makes it easier to write Python programs. This is the IDLE Python Shell that you can use to enter Python commands or instructions one at a time.

Note

Previous Raspberry Pi models have desktop icons for Python: IDLE and IDLE 3. You’ll use Python 3 (or IDLE 3) for the exercises in this book. On older Pi models, the IDLE 3 icon opens the Python Shell for Python 3. You may have guessed that the IDLE (without the 3) icon opens IDLE for Python 2.

Note

To start the Python Shell from the Raspbian command line, type python3 and press Enter. You’ll see a >>> prompt and may interactively enter Python commands. When you’re finished using the Python Shell, type exit() and press Enter to end your Python session.

The Python Shell shown in figure 1.20 allows you to enter Python commands and press Enter to execute them. The command prompt lets you type in commands after the triple greater-than symbols (>>>).

Do the following:

1.  Enter 3 + 4.

2.  Press Enter.

The screen displays the answer: 7. Try some subtraction:

1.  Enter 17 – 9.

2.  Press Enter.

The screen displays the answer: 8. Now let’s make Python talk to you by printing a message to the screen:

1.  Enter print("I am alive!").

2.  Press Enter.

Your screen should display “I am alive!”

Outstanding work! You wrote three lines of code. When you pressed Enter after each one, the Raspberry Pi’s processor executed those commands and did what you asked. That is powerful!

Fruit Picker Extra: shopping at the Pi Store

Your Raspberry Pi can do many things. We’ve included special sections throughout the book called Fruit Picker Extras to teach you some different things your Pi can do. This Fruit Picker Extra is about shopping at the Pi Store.

The Pi Store is an online app store that provides access to games, apps, and resources for your Pi (see figure 1.21). You can browse the Pi Store from any device, such as a mobile phone or laptop. To access it from your Raspberry Pi, double-click the Pi Store icon on your desktop. If you want to download content to your Pi, you need to have your Pi connected to the internet, and you’ll also need to create an IndieCity account with an email address and password.

Figure 1.21. You can access the Pi Store from the icon on your Raspbian desktop. The store allows you to browse and download apps and content including games, tutorials, and digital magazines. You’ll find free and fee-based content, organized into five categories: Games, Apps, Tutorials, Dev Tools, and Media.

Some apps are free; others require you to pay a fee. You’ll find great resources, such as free issues of MagPi, the Raspberry Pi community magazine, a digital magazine full of tips, projects, and programming tutorials (look for these in the Pi Store’s Media category). Have fun downloading free games and tutorials onto your Pi!

Challenge

Each chapter will have challenges at the end for you to try. If you can’t figure them out, check the back of the book (see appendix C) for hints and answers.

Scavenger hunt

Time to explore your Raspberry Pi with a scavenger hunt. The goal is to learn more about the Pi by looking around, opening applications, and playing with them. Try to complete this list of scavenger-hunt items:

1.  Find a game where squirrels eat other squirrels. Can you achieve the title of Omega Squirrel? Hint: Double-click the Python Games desktop icon to look for it.

2.  Find a calculator application on your Raspberry Pi. Calculate the answer to a math problem: 87x34. Hint: The calculator is found under Menu > Accessories.

3.  Without unplugging your Raspberry Pi, can you figure out how to shut down or restart it?

4.  Turn your desktop’s background black.

5.  Bonus: Open Scratch, and try to make a cat dance.

Consider yourself an official Raspberry Pi explorer. If you want, take some more time to click some icons and see what they do. You’ve accomplished a lot!

Summary

The Raspberry Pi is like other computers in a lot of ways, but with several important differences. The similarities with other computers include these:

  • A Pi requires a keyboard, mouse, and monitor, much like other desktop computers. The ports for plugging these in are part of the Pi.
  • The Pi can be set up with a desktop OS, Raspbian. It’s similar to Microsoft Windows or Apple OS X.
  • Although its computing power is limited (similar to a smart phone), the Pi can still allow you to do many things you do on a desktop or laptop, such as browsing websites, playing games, and listening to music.

The Raspberry Pi has qualities and capabilities that make it special and unique. These key differences from other computers include the following:

  • The Pi’s cost and size are much smaller, making it a great candidate for projects.
  • The Pi was designed for programming in Python and comes preloaded with the Python development environment so you can get coding right away.
  • The Pi uses an SD memory card to store all files and software, including the OS.
  • It has GPIO pins that can send and receive electrical signals. In part 3 of this book, you’ll learn how you can use these to create projects that interact with the world around you.
..................Content has been hidden....................

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