18,99 €
Get your slice of Raspberry Pi With the invention of the unique credit card-sized single-board computer comes a new wave of hardware geeks, hackers, and hobbyists who are excited about the possibilities with the Raspberry Pi--and this is the perfect guide to get you started. With this down-to-earth book, you'll quickly discover why the Raspberry Pi is in high demand! There's a reason the Raspberry Pi sold a million units in its first year, and you're about to find out why! In Raspberry Pi For Dummies, 3rd Edition veteran tech authors Sean McManus and Mike Cook make it easier than ever to get you up and running on your Raspberry Pi, from setting it up, downloading the operating system, and using the desktop environment to editing photos, playing music and videos, and programming with Scratch--and everything in between. * Covers connecting the Pi to other devices such as a keyboard, mouse, monitor, and more * Teaches you basic Linux System Admin * Explores creating simple hardware projects * Shows you how to create web pages Raspberry Pi For Dummies, 3rd Edition makes computing as easy as pie!
Sie lesen das E-Book in den Legimi-Apps auf:
Seitenzahl: 682
Raspberry Pi® For Dummies®, 3rd Edition
Published by: John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030-5774, www.wiley.com
Copyright © 2017 by John Wiley & Sons, Inc., Hoboken, New Jersey
Published simultaneously in Canada
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without the prior written permission of the Publisher. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions.
Trademarks: Wiley, For Dummies, the Dummies Man logo, Dummies.com, Making Everything Easier, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and may not be used without written permission. Raspberry Pi is a registered trademark of Raspberry Pi Foundation All other trademarks are the property of their respective owners. John Wiley & Sons, Inc. is not associated with any product or vendor mentioned in this book.
LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES OR PROMOTIONAL MATERIALS. THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR EVERY SITUATION. THIS WORK IS SOLD WITH THE UNDERSTANDING THAT THE PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR OTHER PROFESSIONAL SERVICES. IF PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF A COMPETENT PROFESSIONAL PERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOR THE AUTHOR SHALL BE LIABLE FOR DAMAGES ARISING HEREFROM. THE FACT THAT AN ORGANIZATION OR WEBSITE IS REFERRED TO IN THIS WORK AS A CITATION AND/OR A POTENTIAL SOURCE OF FURTHER INFORMATION DOES NOT MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE INFORMATION THE ORGANIZATION OR WEBSITE MAY PROVIDE OR RECOMMENDATIONS IT MAY MAKE. FURTHER, READERS SHOULD BE AWARE THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR DISAPPEARED BETWEEN WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ.
For general information on our other products and services, please contact our Customer Care Department within the U.S. at 877-762-2974, outside the U.S. at 317-572-3993, or fax 317-572-4002. For technical support, please visit https://hub.wiley.com/community/support/dummies.
Wiley publishes in a variety of print and electronic formats and by print-on-demand. Some material included with standard print versions of this book may not be included in e-books or in print-on-demand. If this book refers to media such as a CD or DVD that is not included in the version you purchased, you may download this material at http://booksupport.wiley.com. For more information about Wiley products, visit www.wiley.com.
Library of Congress Control Number: 2017950656
ISBN: 978-1-119-41200-7; 978-1-119-41202-1 (ebk); 978-1-119-41201-4 (ebk)
Table of Contents
Cover
Introduction
About This Book
Why You Need This Book
Foolish Assumptions
Icons Used in This Book
Beyond the Book
Where to Go from Here
Part 1: Setting Up Your Raspberry Pi
Chapter 1: Introducing the Raspberry Pi
Getting Familiar with the Raspberry Pi
Figuring Out What You Can Do with a Raspberry Pi
Getting Your Hands on a Raspberry Pi
Determining What Else You Need
Chapter 2: Downloading the Operating System
Introducing Linux
Creating a NOOBS Card
Using Your NOOBS Card
Flashing an SD or MicroSD card
Chapter 3: Connecting Your Raspberry Pi
Inserting the SD Card
Connecting the Raspberry Pi Camera Module
Preparing Your Pi Zero or Zero W
Connecting a Monitor or TV
Connecting a USB Hub
Connecting a Keyboard and Mouse
Connecting Audio
Connecting to Your Router
Connecting the Power and Turning on the Raspberry Pi
Logging In
Configuring Your Raspberry Pi in Raspbian
Configuring Your Wi-Fi
Configuring Bluetooth Devices
Testing the Camera Module
Setting Up the Data Partition
Taking Your Next Steps with the Raspberry Pi
Part 2: Getting Started with Linux
Chapter 4: Using the Desktop Environment
Navigating the Desktop Environment
Using the Task Manager
Using File Manager
Browsing the Web
Sending and Receiving Email with Claws Mail
Using the Image Viewer
Using the Text Editor
Customizing the Desktop
Finding and Installing New Applications
Backing Up Your Data
Logging Out from PIXEL and Shutting Down
Chapter 5: Using the Linux Shell
Understanding the Prompt
Exploring Your Linux System
Understanding the Long Listing Format and Permissions
Slowing Down the Listing and Reading Files with the Less Command
Speeding Up Entering Commands
Using Redirection to Create Files
Creating Directories
Deleting Files
Using Wildcards to Select Multiple Files
Removing Directories
Copying and Renaming Files
Installing and Managing Software on Your Raspberry Pi
Managing User Accounts on Your Raspberry Pi
Learning More about Linux Commands
Customizing the Shell with Your Own Linux Commands
Shutting Down and Rebooting Your Raspberry Pi
Part 3: Using the Raspberry Pi for Both Work and Play
Chapter 6: Being Productive with the Raspberry Pi
Installing LibreOffice on Your Raspberry Pi
Working with LibreOffice on the Raspberry Pi
Chapter 7: Editing Photos on the Raspberry Pi with GIMP
Working with GIMP
Finding Out More about GIMP
Chapter 8: Playing Audio and Video on the Raspberry Pi
Setting Up Your Media Center
Navigating the Media Center
Adding Media
Playing Music
Playing Videos
Viewing Photos
Changing the Settings
Using a Remote Control
Turning Off Your Media Center
Playing Music in the Desktop Environment
Part 4: Programming the Raspberry Pi
Chapter 9: Introducing Programming with Scratch
Understanding What Programming Is
Working with Scratch
What's new in Scratch 2
Chapter 10: Programming an Arcade Game Using Scratch
Starting a New Scratch Project and Deleting Sprites
Changing the Background
Adding Sprites to Your Game
Drawing Sprites in Scratch
Naming Your Sprites
Controlling When Scripts Run
Using Random Numbers
Detecting When a Sprite Hits Another Sprite
Introducing Variables
Making Sprites Move Automatically
Fixing the Final Bug
Adding Scripts to the Stage
Duplicating Sprites
Playing Your Game
Adapting the Game’s Speed
Taking It Further with Scratch
Chapter 11: Writing Programs in Python
Working with Python
Creating the Times Tables Program
Creating the Chatbot Program
Chapter 12: Creating a Game with Python and Pygame Zero
Collecting Your Sounds and Images
Setting Up Your Folders
Creating and Running Your First Program
Exploring Pygame Zero Further
Chapter 13: Programming Minecraft with Python
Playing Minecraft
Preparing for Python
Using the Minecraft Module
Adapting the Program
Chapter 14: Making Music with Sonic Pi
Understanding the Sonic Pi Screen Layout
Playing Your First Notes
Using Note and Chord Names
Writing Shorter Programs
Composing Random Tunes Using Shuffle
Changing the Random Number Seed
Using List Names in Your Programs
Playing Random Notes
Experimenting with Live Loops
Using Samples
Adding Special Effects
Synchronizing with Your Drumbeat
Bringing It All Together
Next Steps with Sonic Pi
Part 5: Exploring Electronics with the Raspberry Pi
Chapter 15: Understanding Circuits
Discovering What a Circuit Is
Getting Familiar with the GPIO
Looking at Ready-Made Add-On Boards
Chapter 16: Taking Control of Your Pi’s Circuitry
Accessing Raspberry Pi’s GPIO Pins
Your First Circuit
Starting Out with a Dice Display
Pedestrian Crossing
Chapter 17: Lots of Multicolored LEDs
Making Colors
The Way Forward
Rainbow Invaders
Keepy Uppy
LEDs Galore
Chapter 18: Old McDonald's Farm and Other RFID Adventures
How RFID Work
Dressing Up a Paper Doll
Old McDonald's Farm
Part 6: The Part of Tens
Chapter 19: Ten Great Software Packages for the Raspberry Pi
Penguins Puzzle
FocusWriter
Mathematica
XInvaders 3D
Fraqtive
Tux Paint
Grisbi
Beneath a Steel Sky
Sense HAT Emulator
Brain Party
Chapter 20: Ten Inspiring Projects for the Raspberry Pi
One-Button Audiobook Player
Weather Station
Heart Rate Monitor
Electric Skateboard
T-Shirt Cannon
Panflute Hero
Magic Mirror
Pi in the Sky
Raspberry Turk
Sound Fighter
Appendix A: Troubleshooting and Configuring the Raspberry Pi
Troubleshooting the Raspberry Pi
Adjusting the Settings on Your Raspberry Pi
Fixing Audio Problems
Mounting External Storage Devices
Fixing Software Installation Issues
Troubleshooting Your Network Connection
Connecting Using SSH
About the Authors
Advertisement Page
Connect with Dummies
End User License Agreement
Cover
Table of Contents
Begin Reading
i
ii
v
vi
vii
viii
ix
x
xi
xii
xiii
1
2
3
4
5
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
23
24
25
26
27
28
29
30
31
32
33
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
149
150
151
152
153
154
155
156
157
158
159
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
445
446
447
448
449
450
451
452
453
454
455
456
457
458
483
484
486
487
488
489
490
The Raspberry Pi is at the forefront of the maker movement, where people make their own inventions using a mixture of traditional craft skills and modern coding and electronics knowledge. It's also given more and more people access to a computer that provides a gateway into programming, electronics, and the world of Linux — the technically powerful (and free) rival to Windows and Mac OS. As a supercheap computer, the Raspberry Pi is also being pressed into service in media centers and as a family computer for games, music, photo editing, and word processing.
Although the Raspberry Pi presents new opportunities to everyone, it can also be a daunting prospect. It comes as a bare circuit board, so to do anything with it, you need to add an operating system on an SD or microSD card and connect it up to a screen, mouse, and keyboard. To get started, you need to learn a few basics of Linux, or at least get acquainted with PIXEL, the graphical desktop. You might be a geek who relishes learning new technologies, or you might be someone who wants a new family computer to use with the children. In either case, Raspberry Pi For Dummies, 3rd Edition, helps you get started with your Raspberry Pi and teaches you about some of the many fun and inspiring things you can do with it.
Raspberry Pi For Dummies, 3rd Edition, provides a concise and clear introduction to the terminology, technology, and techniques that you need to get the most from your Pi. With this book as your guide, you’ll learn how to
Connect your Raspberry Pi.
Change its settings so that it works optimally for you.
Discover and install great free software you can use on your Raspberry Pi.
Use the desktop environment to run programs, manage files, surf the web, and view photos.
Use the Linux command line to manage your Raspberry Pi and its files.
Use the Raspberry Pi as a productivity tool.
Edit photos.
Play music and video.
Create animations and arcade games with the child-friendly Scratch programming language.
Write your own games and other programs using the Python programming language.
Compose music by programming with Sonic Pi.
Get started with electronics, from an introduction to soldering to the design and creation of electronic projects controlled by the Raspberry Pi.
Incidentally, within this book, you may note that some web addresses break across two lines of text. If you’re reading this book in print and want to visit one of these web pages, simply key in the web address exactly as it’s noted in the text, pretending as though the line break doesn’t exist. If you’re reading this as an ebook, you’ve got it easy — just click or tap the web address to be taken directly to the web page.
After you shake the Raspberry Pi out of the little electrostatic bag it comes in, what next?
This book answers that question. It enables you to get your Raspberry Pi up and running and also introduces you to some of the great things you can do with it, through satisfying practical projects. With this book as your companion, you can write games and other programs and create your own electronic gadgets, all with no prior programming knowledge.
The Raspberry Pi is most likely a bit different compared to other computers you’ve used, so this book also helps you to do some of the things on your Pi that you expect of every computer, such as play music and edit documents.
You can learn a lot of this through trial and error, of course, but that can be a frustrating way to spend your time. Using this book as a reference, you can more quickly start using your Raspberry Pi, whatever you plan to do with it.
Raspberry Pi For Dummies, 3rd Edition, is written for beginners, by which we mean people who have never used a similar computer. However, we do have to make a few assumptions in writing this book, because we wouldn't have enough space for all its cool projects if we had to start by explaining what a mouse is! Here are our assumptions:
You are familiar with other computers, such as Windows or Apple computers.
In particular, we assume that you’re familiar with using windows, icons, and the keyboard and mouse, and that you know the basics of using your computer for things like browsing the Internet, writing letters, or copying files.
The Raspberry Pi is not your only computer.
At times, you’ll need to have access to another computer — for example, to create your SD or microSD card for the Pi. (See
Chapter 2
.) When it comes to networking, we assume you already have a router set up with an Internet connection and a spare port that you can plug the Raspberry Pi into.
The Raspberry Pi is your first Linux-based computer.
If you’re a Linux ninja, this book still gives you a solid reference on the Raspberry Pi and the version of Linux it uses, but no prior Linux knowledge is required.
You share our excitement.
The Raspberry Pi can open up a world of possibilities to you!
Other than these assumptions, we hope this book is approachable for everyone. The Raspberry Pi is being adopted in classrooms and youth groups, and this book is a useful resource for teachers and students. The Raspberry Pi is also finding its way into many homes, where people of all ages (from children to adults) are using it for education and entertainment.
If you’ve read other For Dummies books, you know that they use icons in the margin to call attention to particularly important or useful ideas in the text. In this book, we use four such icons:
The Tip icon highlights expert shortcuts or simple ideas that can make life easier for you.
Arguably, the whole book talks about technical stuff, but this icon highlights something that’s particularly technical. We’ve tried to avoid unnecessary jargon and complexity, but some background information can give you a better understanding of what you’re doing, and sometimes we do need to get quite techy, given the sophistication of the projects you’re doing. Paragraphs highlighted with this icon might be worth rereading, to make sure you understand, or you might decide that you don’t need to know that much detail. It’s up to you!
Although we’d like to think that reading this book is an unforgettable experience, we’ve highlighted some points that you might want to particularly commit to memory. They’re either important takeaways, or they’re fundamental to the project you’re working on.
As you would do on the road, slow down when you see a Warning icon. It highlights an area where things could go wrong.
In addition to what you’re reading right now, this book comes with a free access-anywhere Cheat Sheet with tips on installing software and using Scratch. To get this Cheat Sheet, simply go to www.dummies.com and type Raspberry Pi Dummies Cheat Sheet in the Search box.
Also be sure to check out this book’s companion website (www.dummies.com/extras/raspberrypi3e), where you can download the code listings that appear throughout this book, as well as two bonus appendices (one on The GPIO on the Raspberry Pi and one on the RISC OS) as well as a bonus chapter on Mathematica, a mathematical program.
Both of us maintain our own personal websites too, which contain some additional information on the Raspberry Pi. Mike’s is at www.thebox.myzen.co.uk/Raspberry/Punnet.html, and Sean’s is at www.sean.co.uk.
It’s up to you how you read this book. It’s been organized to take you on a journey from acquiring and setting up your Raspberry Pi to learning the software that comes with it, and from writing your own programs to finally creating your own electronics projects. Some chapters build on knowledge gained in earlier chapters, especially the sections on Scratch and Python — and all of Part 5.
We understand, though, that some projects or topics might interest you more than others, and you might need help in some areas right now. When a chapter assumes knowledge from elsewhere, we include cross-references to help you quickly find what you might have missed. We also include some signposts to future chapters, so you can skip ahead to a later chapter if it provides the quickest answer for you.
If you haven’t set up your Pi yet, start with Part 1. If you have your Pi up and running, Part 2 shows you how to use the software on it. Part 3 covers productivity, creativity, and entertainment software. To flex your programming muscles, perhaps for the first time, read Part 4. You can learn Scratch, Python, or Sonic Pi here, and feel free to start with any one of those languages. The Python chapters provide a good foundation for Part 5, where you can start building your own electronics projects.
Part 1
IN THIS PART …
Get to know the Raspberry Pi and what other equipment you will need to be able to use it.
Download the Linux operating system and prepare an SD or MicroSD card for use on your Raspberry Pi.
Connect your Raspberry Pi to the power, USB hub, keyboard, mouse, and screen.
Install and test the Raspberry Pi Camera Module.
Change the settings on your Raspberry Pi.
Chapter 1
IN THIS CHAPTER
Getting up close and personal with the Raspberry Pi
Taking stock of your Raspberry Pi
Determining its limitations
Purchasing your very own Raspberry Pi
Figuring out what else you need
The Raspberry Pi is perhaps the most inspiring computer available today. Although most of the computing devices being used (including phones, tablets, and game consoles) are designed to stop people from tinkering with them, the Raspberry Pi is exactly the opposite. From the moment you see its shiny green circuit board, it invites you to prod it, play with it, and create with it. It comes with the tools you need to start creating your own software (or programming), and you can connect your own electronic inventions to it. It’s cheap enough that if you break it, it won’t break the bank, so you can experiment with confidence.
Lots of people are fired up about its potential, and they’re discovering exciting new ways to use it. Dave Akerman (www.daveakerman.com) and friends attached one to a weather balloon and sent it nearly 40 kilometers high to take pictures of the Earth from near space using a webcam. (You can read about Dave’s ballooning project in Chapter 20.)
Professor Simon Cox and his team at the University of Southampton connected 64 Raspberry Pi boards to build an experimental supercomputer, held together by Lego bricks. In the supercomputer (see Figure 1-1), the Raspberry Pis work together to solve a single problem. The project has been able to cut the cost of a supercomputer from millions of dollars to thousands or even hundreds of dollars, making supercomputing much more accessible to schools and students. Others have also experimented with combining the processing power of multiple Pis. There's even an off-the-shelf kit you can use to combine four Raspberry Pi Zeros with a full-size Raspberry Pi (the Cluster HAT from Pimoroni) so that you can experiment with running programs across multiple Pis at the same time.
Courtesy of Simon Cox and Glenn Harris, University of Southampton.
FIGURE 1-1: Two of the Raspberry Pi boards used in the University of Southampton’s supercomputer, with the rest of the supercomputer in the background.
The Pi is also being used to make weather stations, fitness gadgets, gaming devices, audiobook players, electric skateboards, and much more, as you discover in Chapter 20.
Although those projects are grabbing headlines, another story is less visible but more important: the thousands of people of all ages who are taking their first steps in computer science, thanks to the Raspberry Pi.
Both of the authors of this book used computers in the 1980s, when the notion of a home computer first became a reality. Back then, computers were less friendly than they are today. When you switched them on, you were faced with a flashing cursor and had to type something in to get it to do anything. As a result, though, a whole generation grew up knowing at least a little bit about how to give the computer commands, and how to create programs for it. As computers started to use mice and windows, people didn't need those skills any more, and they lost touch with them.
Eben Upton, designer of the Raspberry Pi, noticed the slide in skill levels when he was working at Cambridge University’s computer laboratory in 2006. Students applying to study computer science started to have less experience with programming than students of the past did. Upton and his university colleagues hatched the idea of creating a computer that would come supplied with all the tools needed to program it — and would sell for a target price of $25 (about £20). It had to be able to do other interesting things, too, so that people were drawn to use it, and it had to be robust enough to survive being pushed in and out of school bags hundreds of times.
That idea started a six-year journey that led to the Raspberry Pi you probably have on your desk you as you read this book. It was released in February 2012, and sold half a million units by the end of the quarter. By July 2017, there were more than 14 million Raspberry Pis in homes, schools and workplaces, 10 million of them made in the UK. It is, by a large margin, the best-selling British computer of all time.
When your Raspberry Pi arrives, you’ll see that it’s a circuit board, with components and sockets stuck on it, as shown in Figure 1-2. In an age when most computing devices are sleek and shiny boxes, the spiky Pi, with tiny codes printed in white all over it, seems alien. That’s a big part of its appeal, though: Many of the cases you can buy for the Raspberry Pi are transparent because people love the look of it.
FIGURE 1-2: The Raspberry Pi 3 Model B (top left), Model A+ (top right), and Pi Zero W (bottom).
Over the years, the Raspberry Pi has evolved, increasing its memory, improving its performance, and adding features. So which one should you get? Here’s an overview designed to help you decide:
Raspberry Pi 3 Model B: The third generation of the Raspberry Pi, it represents the best all-round Raspberry Pi at the time of writing. According to the Raspberry Pi Foundation, it is 50 to 60 percent faster than the previous model, and ten times faster than the original Raspberry Pi. It includes 1GB of memory, four USB ports, built-in Wi-Fi and Bluetooth, and an Ethernet port for a wired Internet connection. It has 40 General Purpose Input/Output (GPIO) pins, which you can use to connect to your own electronics projects. Like previous Pi models, it's about the size of a credit card. As with any current Raspberry Pi, it uses a MicroSD card for storage. If you're not sure which model to get and your budget allows, get this one. It represents the fastest performance, and offers the best experience on the desktop. Its price is around $35 (about £30).
It’s called the Model B, incidentally, as a tribute to the BBC Microcomputer that was popular in the U.K. in the 1980s. It’s sobering to think that the BBC Micro cost about ten times the price of a Raspberry Pi, which, thanks to 35 years of progress in computer science, has more than 7,800 times more memory.
Raspberry Pi 1 Model A+:
A cut-down model, it is ideal for projects that need lower power consumption — typically battery-based projects. It is suitable for robots and projects in remote locations, where a wired electricity supply isn’t viable and batteries must be used instead. It does not have an Ethernet socket, and only has one USB port, although you can connect it to a USB hub to use more devices simultaneously. It does have the full complement of 40 GPIO pins, though, so you should find that your projects and add-ons work with it. Like the Model B, it includes an audio output (headphones-style) socket. This model has 512MB of memory and a price of $20 (or £20). The Model A+ is slightly shorter on the long side than the Raspberry Pi 3, measuring 6.5 centimeters by 5.5 centimeters.
Raspberry Pi Zero:
The Raspberry Pi Foundation astounded everyone when it gave this computer away with the print edition of its magazine
The MagPi.
The Raspberry Pi Zero measures 6.5 centimeters by 3 centimeters, is extremely lightweight, and has 512MB of memory and one Micro USB port. If you want to use the GPIO, you'll need to solder or affix your own pins, available separately. (You can read about adding GPIO pins to the Pi Zero in
Chapter 16
.) You'll also need a converter for the Mini HDMI socket, and for the Micro USB socket, so you should expect to spend a bit more than the price of the Pi (and have a bit more complexity in your setup). Billed as the $5 computer, the Raspberry Pi Zero has at times been difficult to get hold of, which is perhaps not surprising given the phenomenal demand for it.
Raspberry Pi Zero W:
Released in February 2017, the Raspberry Pi Zero W added Wi-Fi and Bluetooth, and compatibility with the Raspberry Pi Camera Module. The Pi Zero W costs around $10 (or about £10). If you're happy to solder your own GPIO pins, or you don't need them, the Raspberry Pi Zero or Zero W represents a great entry point to the Raspberry Pi family. After the Raspberry Pi Model 3, the Pi Zero W is our recommended best buy.
Of course, the older Raspberry Pis are still out there. Recent models usually remain in production while there is demand, and you can buy secondhand versions online from websites such as eBay. Generally speaking, the newer the model, the faster its performance. Memory upgrades have made a difference, as well as the use of more powerful processors, as the Pi has evolved. There are plenty of uses for the Pi that don't need especially fast performance, though, so you might find that an older Pi is perfect for your project. The older models are described in this list:
Raspberry Pi 1 Model B with 256MB memory:
Although it’s called Model B, this was the first Raspberry Pi to be released, in February 2012. The Raspberry Pi Model B features an Ethernet connection for the Internet and two USB ports. It uses an SD card for storage.
Raspberry Pi 1 Model B with 512MB memory:
Released in October 2012, the Raspberry Pi Model B had twice the memory capacity. This improved the speed of some software, especially applications that used images heavily.
Raspberry Pi 1 Model A:
The Model A, released in February 2013, is a stripped-down version of the Model B. It has just one USB port and doesn’t have an Ethernet port for connecting to the Internet. It has 256MB of memory.
Raspberry Pi 1 Model B+:
The Model B+, released in July 2014, has been described by the Raspberry Pi Foundation as “the final evolution of the original Raspberry Pi.” It runs all the same software as the previous versions of the Raspberry Pi, but it has four USB ports, more GPIO pins for connecting electronics projects to the Pi, and lower power consumption and better audio than the Model B. In common with the Model B, it has 512MB of memory. Although all previous versions use SD cards for data storage, the Model B+ introduced the smaller MicroSD cards, which are now standard on the Raspberry Pi.
Raspberry Pi 2 Model B:
Launched in February 2015, this model doubled the memory on the Model B+ to 1GB. It increased performance, compared to the Model B+, while retaining its physical features. Over the years the Pi's performance has been improved through new software releases as well as updates to the hardware. The Pi 2 represents an immediately noticeable speed-up, compared to the Model B+.
If you're using anything earlier than the Model B+, you'll need full-size SD cards (not MicroSD) for storage, and you'll only have 26 GPIO pins to play with. Current add-ons are unlikely to be compatible with the early boards, so check their requirements before you buy.
In this book, we offer guidance on older models where possible but will assume you're using at least a Model B+ for the projects. For best performance, we recommend using a current model, if possible.
You’ll also see the Raspberry Pi Compute Module in the online stores alongside the Raspberry Pi, but this is something quite different. It’s aimed at engineers creating industrial applications (known as embedded systems) or products based on Raspberry Pi technology. We only mention it here in case you wonder what it is: It’s not covered further in this book, and it’s almost certainly not what you want to buy for your first Raspberry Pi.
The Raspberry Pi was made possible in part by the advances in mobile computer chips that have happened in recent years. At its heart is a Broadcom chip (BCM2835, BCM2836, or BCM2837) that contains an ARM central processing unit (CPU) and a Videocore IV graphics processing unit (GPU). The CPU and GPU share the memory between them. The GPU is powerful enough to be able to handle Blu-ray quality video playback.
Instead of running Windows or Mac OS, the Raspberry Pi uses an operating system called Linux. It’s a leading example of open source, a completely different philosophy to the commercial software industry. Rather than being created within the heavily guarded walls of a company, with its design treated as a trade secret, Linux is built by companies and expert volunteers working together. Anyone is free to inspect and modify the source code (a bit like the recipe) that makes it work. You don’t have to pay to use Linux, and you’re allowed to share it with other people, too.
You probably won’t be able to run the software you have on your other computers on your Raspberry Pi. It won’t run Windows or Mac software, and not all Linux software works on the Raspberry Pi. But a lot of Linux software that is compatible with the Raspberry Pi is available and is free of charge.
The Raspberry Pi is a fully featured computer, and you can do almost anything with it that you can do with a desktop computer.
It has a graphical windows desktop to start and manage programs (see Chapter 4) as well as a shell for accepting text commands. (See Chapter 5.) You can use it for browsing the Internet (see Chapter 4), or for word processing and spreadsheets (see Chapter 6), or for editing photos. (See Chapter 7.) You can use it for playing back music or video (see Chapter 8) or for playing games. (See Chapter 19.) You can use the built-in software to write your own music, too. (See Chapter 14.) It’s the perfect tool for homework, but it’s also a useful computer for writing letters, managing your accounts, and paying bills online.
The Raspberry Pi is at its best, however, when it’s being used to learn how computers work, and how you can create your own programs or electronics projects using them. It comes with Scratch (see Chapter 9), which enables people of all ages to create their own animations and games while learning some of the core concepts of computer programming along the way.
It also comes with Python (see Chapter 11), a professional programming language used by YouTube, Google, and Industrial Light & Magic (the special effects gurus for the Star Wars films), among many others.
It has GPIO pins on it that you can use to connect up your own circuits to the Raspberry Pi, so you can use your Raspberry Pi to control other devices and to receive and interpret signals from them. In Part 5, we show you how to build some electronic projects controlled by the Raspberry Pi.
One of the great things about the Raspberry Pi is that it's established a community of businesses that have created products for it, or have shared in its success by selling it. You can now buy the Raspberry Pi from a wide range of electronics companies for hobbyists. Global retailers include Pimoroni (www.pimoroni.com), The Pi Hut (https://thepihut.com), and Adafruit (www.adafruit.com). It's also available from the Raspberry Pi's distributors, RS Components (www.rs-components.com) and Element14 (www.element14.com).
You might also be able to buy it from your local computer or electronics store, although you'll probably find it's only available as part of a kit there. Shops often bundle the Raspberry Pi with other items you need to use it. It can be convenient to get everything at once, but it might not represent the cheapest way to get started.
The creators of Raspberry Pi have stripped costs to the bone to enable you to own a fully featured computer for less than $35, so you’ll need to scavenge or buy a few other bits and pieces in order to use your Pi. We say scavenge because the things you need are exactly the kind of things many people have lying around their house or garage already, or can easily pick up from friends or neighbors. In particular, if you’re using a Raspberry Pi as your second computer, you probably have most of the peripherals you need. That said, you might find they’re not fully compatible with the Raspberry Pi and you need to buy replacements to use with the Pi.
Here’s a checklist of what else you might need:
Monitor:
The Raspberry Pi has a high-definition video feed and uses an HDMI (high-definition multimedia interface) connection for it. If your monitor has an HDMI socket, you can connect the Raspberry Pi directly to it. If your monitor does not support HDMI, it probably has a DVI socket, and you can get a simple and cheap converter that enables you to connect an HDMI cable to it. Older VGA (video graphics array) monitors require a device to convert the HDMI signal into a VGA one. If you’re thinking of buying a converter, check online first to see whether it works with the Raspberry Pi. A lot of cheap cables are just cables, when what you need is a device that converts the signal from HDMI format to VGA, not one that just fits into the sockets on the screen and your Raspberry Pi. These converters can be quite expensive, so Gert van Loo has designed a device that uses the Raspberry Pi’s GPIO pins to connect to a VGA monitor. He’s published the design specs so that anyone can build one, and sell it if she wants to, too. Take a look at eBay if you need one, and you might well find what you need. For more information, check out
www.raspberrypi.org/blog/gert-vga-adapter
. (If your monitor is connected using a blue plug and the connector has three rows of five pins in it, it’s probably a VGA monitor.)
TV:
You can connect your Raspberry Pi to a high-definition TV using the HDMI socket and should experience a crisp picture. If you have an old television in the garage, you can also press it into service for your Raspberry Pi. The Pi can send a composite video signal, so it can use a TV as its display. When we tried this, it worked but the text lacked definition, which made it difficult to read. If a TV is your only option, see
Appendix A
for advice on tweaking the settings to get the clearest possible picture. It’s better to use a computer monitor if you can, though. You’ll need to get a cable with the right connector to fit your Pi: The Model A and Model B have a dedicated RCA video socket, but later models use the headphone socket for RCA video output, too.
USB hub:
The Raspberry Pi has one, two, or four USB sockets (depending on the model you get). Consider using a powered USB hub, for two reasons. Firstly (and especially if you have a Model A, A+, B, or Zero), you’re going to want to connect other devices to your Pi at the same time as your keyboard and mouse, which need two sockets. And secondly, a USB hub provides external power to your devices and minimizes the likelihood of experiencing problems using your Raspberry Pi, especially if connecting relatively power-intensive devices such as hard drives. Make sure your USB hub has its own power source, independent of the Raspberry Pi.
USB keyboard and mouse: The Raspberry Pi only supports USB keyboards and mice, so if you’re still using ones with PS/2 connectors (round rather than flat), you need to replace them.
When the Raspberry Pi behaves unpredictably, it can be because the keyboard is drawing too much power, so avoid keyboards with too many flashing lights and features.
MicroSD card or SD card:
The Raspberry Pi doesn’t have a hard drive built into it, so it uses a MicroSD card (current models) or SD card (older models, excluding the Model B+) as its main storage. You probably have some SD cards that you use for your digital camera, although you might need to get a higher-capacity one. We recommend an 8GB card as a minimum, but you can use a 4GB card if you use a media center operating system (OS) like LibreELEC. (See
Chapter 8
for a guide to LibreELEC.) Even that isn’t much space compared to the hard drive on a modern computer, but you can use other storage devices such as external hard drives with your Raspberry Pi, too. SD and MicroSD cards have different class numbers that indicate how fast you can copy information to and from them. The Raspberry Pi Foundation recommends its branded Class 6 card as a good value and high-performing solution, although online retailers often sell a Class 10 card for this purpose. You will be fine with a Class 6 or higher. The easiest way to get started with the Raspberry Pi is to buy a card with the NOOBS software already on it. (See
Chapter 2
for more on NOOBS.) Online retailers, including those mentioned earlier for buying the Pi itself, usually sell an 8GB or 16GB MicroSD card that has the NOOBS software preloaded on it. It comes with an SD card adapter, shown in
Figure 1-3
, so the card fits the older models (with the adapter) and newer models (without it).
SD or MicroSD card writer:
Many PCs today have a slot for SD or MicroSD cards, so you can easily copy photos from your camera to your computer. If yours doesn’t, you might want to consider getting an SD or MicroSD card writer to connect to your computer. You can use it to copy software to an SD card for use with your Raspberry Pi, but you won’t be able to use it to copy files from your Raspberry Pi to a Windows computer. Alternatively, as we’ve said, you can buy a MicroSD card with an SD adapter that has the Raspberry Pi software already on it. You can also use the card writer to create a backup copy of your Raspberry Pi's files and software. (You can read about making back-ups in
Chapter 4
.)
USB key:
A USB key (also known as
flash drive
or
memory stick
) can be fairly cheap and high-capacity now (a 64GB USB key is readily affordable), which makes it an ideal complement to your Raspberry Pi. You can transfer files between your PC and your Raspberry Pi using a USB key, too.
USB Wi-Fi adapter:
The Model A and A+ don't have an Ethernet socket, so if you want to connect to the Internet, you’ll need a USB Wi-Fi adapter. You might already have one of these from a laptop. Some are incompatible with the Raspberry Pi, but companies that sell the Pi usually sell a compatible Wi-Fi adapter, too. There is an official Raspberry Pi Wi-Fi adapter, available from the usual Pi retailers.
External hard drive:
If you want lots of storage, perhaps so that you can use your music or video collection with the Raspberry Pi, you can connect an external hard drive to it over USB. You’ll need to connect your hard drive through a powered USB hub, or use a hard drive that has its own external power source.
Raspberry Pi Camera Module:
The Raspberry Pi has stimulated entrepreneurs to create all kinds of add-ons for it, but the Camera Module is a product that originated at the Raspberry Pi Foundation. This 8-megapixel, fixed-focus camera can be used to shoot HD video and take still photos. There is also a version without an infrared filter (the PiNoIR Camera), which can be used for wildlife photography at night or weird special effects by day.
Speakers:
The Raspberry Pi has a standard audio out socket, compatible with headphones and PC speakers that use a 3.5mm audio jack. You can plug headphones directly into it, or use the audio jack to connect to speakers, a stereo, or a TV. If you’re using a TV or stereo for sound, you can get a cable that connects the 3.5mm audio jack and the audio input(s) on your television or stereo. You won’t always need speakers: If you’re using an HDMI connection, the audio is sent to the screen with the video signal, so you won’t need separate speakers — but note that this doesn’t work if you use a DVI monitor.
Power supply:
The Raspberry Pi uses a Micro USB connector for its power supply, and is theoretically compatible with a lot of mobile phone and tablet chargers. In practice, many of these can’t deliver enough current (up to 700 milliamperes for a Model A+ and up to 2500 milliamperes for a Raspberry Pi 3 Model B), which can make the Raspberry Pi perform unreliably. It’s worth checking to see whether you have a 5V charger that might do the job (it should say on it how much current it provides), but for best results, we recommend buying a compatible charger from the same company that you buy your Raspberry Pi from. There is an official Raspberry Pi power supply available, which works in the U.K., Europe, the U.S./Japan, and Australia/China. For mobile applications, it's possible to power the Raspberry Pi using a battery pack designed for mobile phone charging. Don’t try to power the Pi by connecting its Micro USB port to the USB port on your PC with a cable, because your computer probably can’t provide enough power for your Pi. You can also power the Pi through the GPIO pins, but you could damage the Raspberry Pi if there is a spike in current or the wrong voltage is applied. If you want to provide power through the GPIO pins, a safer approach is to use a HAT device (
H
ardware
A
ttached on
T
op) designed to sit on the GPIO pins and provide the consistent power you need while protecting the Pi underneath. The Raspberry Pi Foundation advises that you should only use batteries to power your Raspberry Pi if you know what you’re doing, because there’s a risk of damaging your Raspberry Pi. For more details on the power requirements of various Raspberry Pi models, consult the FAQ at
www.raspberrypi.org/help/faqs/
.
Case:
It’s safe to operate your Raspberry Pi as is, but many people prefer to protect it from spills and precariously stacked desk clutter by getting a case for it. You can buy plastic cases on eBay (
www.ebay.com
), many of which are transparent, so you can still admire the circuitry and see the Pi’s LED lights. These cases typically come supplied as simple kits for you to assemble. The Pibow Coupe (
https://shop.pimoroni.com/collections/pibow
) is one of the most attractively designed cases, assembled from layers of colored plastic. (See
Figure 1-4
.) It’s designed by Paul Beech, who designed the Raspberry Pi logo. There are also official red-and-white cases for the Raspberry Pi 3 (compatible with the B+ and later models) and the Raspberry Pi Zero. The case for the Pi Zero includes three different tops, so you can either seal it, leave a camera hole, or have access to the GPIO pins. You don’t have to buy a case, though. You can go without or make your own using cardboard or Lego bricks. Whatever case you go with, make sure you can still access the GPIO pins so that you can experiment with connecting your Pi to electronic circuits and try the projects in
Part 5
of this book.
Cables:
You’ll need cables to connect it all up, too. In particular, you need an HDMI cable (if you’re using an HDMI or DVI monitor), an HDMI-to-DVI adapter (if you’re using a DVI monitor), an RCA cable (if you’re connecting to an older television), an audio cable (if you’re connecting the audio jack to your stereo), and an Ethernet cable (for networking on models with an Ethernet port). Note that current Raspberry Pi models send the RCA video signal through a 3.5mm jack (headphone socket), and earlier ones had a dedicated RCA socket. You will need a different cable, depending on which version of the Pi's design you have. If you have a Raspberry Pi Zero, you will also need a converter for the Mini HDMI socket, and for the Micro USB socket. You can get these cables from an electrical-components retailer and might be able to buy them at the same time as you buy your Raspberry Pi. Any other cables you need (for example, to connect to PC speakers or a USB hub) should come with those devices.
FIGURE 1-3: A NOOBS card. The MicroSD card fits into the SD card adapter. The MicroSD card works on the current Pi models, and inside the adapter it also fits the older Model A and Model B.
FIGURE 1-4: The Pibow Coupe case for the Raspberry Pi 3, Pi 2, and Model B+.
The Raspberry Pi has been designed to be used with whatever accessories you have lying around, to minimize the cost of getting started, but in practice not all devices are compatible. In particular, incompatible USB hubs, keyboards, and mice can cause problems that are hard to diagnose. USB hubs that feed power back into your Raspberry Pi through the Pi’s USB port (known as backpowering) could potentially cause damage to the Raspberry Pi if they feed in too much power.
A list of compatible and incompatible devices is maintained at http://elinux.org/RPi_VerifiedPeripherals, and you can check online reviews to see whether others have experienced difficulties using a particular device with the Raspberry Pi.
If you’re buying new devices, you can minimize the risk by buying recommended devices from Raspberry Pi retailers.
In any case, you should set a little bit of money aside to spend on accessories. The Raspberry Pi is a cheap device, but buying a keyboard, mouse, USB hub, and cables can easily double or triple your costs, and you might have to resort to that if what you have on hand turns out not to be compatible.
Chapter 2
IN THIS CHAPTER
Introducing Linux
Downloading NOOBS
Preparing the MicroSD or SD card
Copying NOOBS to the MicroSD or SD card
Flashing your MicroSD or SD card
Before you can do anything with your Raspberry Pi, you need to provide it with an operating system (OS). The operating system software enables you to use the computer’s basic functions and looks after activities such as managing files and running applications, like word processors or web browsers. Those applications use the operating system as an intermediary to talk to the hardware, and they won’t work without it. This concept isn’t unique to the Raspberry Pi. On your laptop, the operating system might be Microsoft Windows or Mac OS. On iPads or iPhones it’s iOS, and on other devices it might be Android.
In this chapter, we introduce you to Linux, the operating system most frequently used on the Raspberry Pi, and we show you how to create an SD or MicroSD card with an operating system on it. You’ll need to use another computer to set up the SD or MicroSD card. It doesn’t matter whether you use a Windows, Mac OS, or Linux machine, but you need to have the ability to write to SD or MicroSD cards using it and a connection to the Internet.
The operating system used on the Raspberry Pi is GNU/Linux, or often just Linux. The Raspberry Pi might be the first Linux computer you’ve used, but the operating system has a long and honorable history.
Richard Stallman created the GNU Project in 1984 with the goal of building an operating system that users were free to copy, study, and modify. Such software is known as free software, and although this software is often given away, the ideology is about free as in “free speech” rather than free as in “free beer.” Thousands of people have joined the GNU Project, creating software packages that include tools, applications, and even games. Stallman aimed to make his operating system compatible with Unix, an operating system that was created by AT&T’s Bell Labs and that started to gain popularity in the 1970s. That would make it easy for existing Unix users to switch to using the GNU Project.
In 1991, Linus Torvalds released the central component of Linux, the kernel, which acts as a conduit between the applications software and the hardware resources, including the memory and processor. He still works on the Linux kernel, sponsored by the Linux Foundation, which is the nonprofit consortium that promotes Linux and supports its development. The Linux Foundation reports that over 11,800 people from almost 1,200 different companies have contributed to the kernel since 2005.
GNU/Linux brings together the Linux kernel with the GNU components it needs to be a complete operating system, reflecting the work of thousands of people on both the GNU and Linux projects. That so many people could cooperate to build something as complex as an operating system, and then give it away for anyone to use, is a modern miracle.
Because GNU/Linux can be modified and distributed by anyone, lots of different versions of it exist. They’re called distributions, or distros, but not all of them are suitable for the Raspberry Pi. The recommended distribution of Linux for the Raspberry Pi is Raspbian. (See Chapter 3.) Software created for one version of Linux usually works on another version, but Linux isn’t designed to run Windows or Mac OS software.
Strictly speaking, Linux is just the kernel in the operating system, but as is commonly done, we refer to GNU/Linux as Linux in the rest of this book.
The easiest way to get started with the Raspberry Pi is to use the NOOBS software. NOOBS is short for new-out-of-box software, although it’s also a pun on the term noob, sometimes used to describe beginners in any field of computing. Don’t underestimate the power of this software, though, especially if you’re a more experienced user: NOOBS is easy to copy to the SD or MicroSD card, but provides you with a simple menu for installing a number of different operating systems, including different versions of Linux and the Kodi media center software. The options are described in more depth in Chapter 3.
As we say in Chapter 1, you can buy a card with NOOBS already on it, and that might be the quickest way to get started. If you’ve got one of these, you can skip ahead to Chapter 3