Adventures in Raspberry Pi. Carrie Anne Philbin
as set out by the instructions. Sometimes you need to type a very long line of code, longer than will fit on a single line in this book. If you see a ↩ symbol at the end of a line of code, it means that line and the following line are part of a single code line, so you should type them as one line, not on separate lines. For example the following code should be typed on one line, not two:
print("Welcome to Adventures in Raspberry Pi by ↩
Carrie Anne Philbin")
Most chapters include a Quick Reference Table at the end to sum up the main commands or concepts from the chapter. You can refer to these guides when you need a refresher on the commands.
Whenever you complete a chapter, you unlock an achievement and collect a new badge. You can collect badges to represent these achievements from the Adventures in Raspberry Pi companion website (www.wiley.com/go/adventuresinrp2E).
In the Appendix you will find ways to take your Raspberry Pi knowledge further, with references to websites, organisations, videos and other resources. Many of those resources include forums where you can ask questions or get in touch with other Raspberry Pi users.
You can also contact me by sending me a message through my website, www.geekgurldiaries.co.uk.
Time to start your adventures!
Adventure 1
You Have a Raspberry Pi- Now What?
IN THE PAGES of this book you’ll discover how to do great things with your Raspberry Pi. You’ll create art and music, programs, games, even create your own jukebox! But first, you need to get your system working.
If you are new to Raspberry Pi, the initial tasks of getting it set up and running might seem a little daunting but it is not that complicated to do. By setting up the Raspberry Pi yourself you will learn more about how it and other computers work. You will encounter technical jargon and procedures that you may not have come across before. In this chapter, I show you how to set up your Raspberry Pi so it is ready for you to use for the first time. I explain what hardware and software you need, and tell you how to put it all together into a working system. You’ll also learn how to create a backup copy of your system in case you need to replace it at some stage in the future.
Hardware refers to the physical elements of the computer that you can see and touch. This includes everything inside the computer case, known as components.
Software is the term given to the programs that run on the computer system. Programs are what make the hardware work, for example by making a calculation or organising your files. There are two main types of software: systems software, which runs and manages your computer; and application software, which performs a specific task or function.
Of course, the first thing you need is a Raspberry Pi. If you have used games consoles or computing devices before, you’ll notice something different about Raspberry Pi – it doesn’t come with a power supply, a charger or any connecting cables. It doesn’t have a storage device to keep your programs on either, or even a case!
So, to get started, you will first need to get the following hardware together (see Figure 1-1):
● A Raspberry Pi
● A micro USB power adapter
● A USB keyboard and mouse
● A desktop computer or laptop with an SD card reader/writer – this is to enable you to prepare an SD card with the software you need to run your Raspberry Pi
● An 8 GB SD card for use with the Model B or an 8GB micro SD card for the B+
● An HDMI cable – you will be using this with an HDMI TV or monitor
● A monitor or TV
When I refer to SD cards in this chapter and throughout this book, I am also referring to micro SD cards, which the Raspberry Pi model B+ uses.
HDMI stands for High-Definition Multimedia Interface. HDMI devices are used to transfer video and audio data from a source device – such as your Raspberry Pi – to a compatible HDMI device like a digital TV or monitor.
USB stands for Universal Serial Bus. You have probably used a USB port on a computer to plug in a webcam or a portable memory device like a memory stick.
An SD card, or Secure Digital memory card, stores data or information. SD cards are most often used in digital cameras to store images that can then be transferred to a computer using an SD card reader. A micro SD card is much smaller in physical size, and the Model B+ uses them instead of a standard SD card.
FIGURE 1-1 The essential hardware you’ll need before you can use your Raspberry Pi Model B or Model B+.
The following additional accessories are not vital but you might want to consider acquiring some of them to improve your Raspberry Pi experience.
● A case– To protect your Raspberry Pi from damage and make it easier for you to carry, think about buying a case like the PiBow shown in Figure 1-2, designed and manufactured by Pimoroni (http://shop.pimoroni.com/collections/customise-your-raspberry-pi). The great thing about this case is that it’s colourful and fun, and the ports are also labelled to remind you where each cable should be inserted.
FIGURE 1-2 The PiBow case can help protect your Raspberry Pi.
Reproduced by permission of Pimoroni
If you don’t want to spend cash on a case, why not create your own by using the Raspberry Pi Punnet? This template can be printed onto card stock, and then cut out and folded into a box. You can really let yourself get creative here and customise your case using pens, paints, stickers or coloured card stock to create a masterpiece. You can download the template from this site: http://squareitround.co.uk/Resources/Punnet_net_Mk1.pdf.
Want a sturdier case? Build one with Lego blocks! You can find instructions to build the Lego Raspberry Pi case shown in Figure 1-3 on the official Lego website at http://www.thedailybrick.co.uk/instructions/.
FIGURE 1-3 Build a Lego case for your Raspberry Pi.
Reproduced by permission of The Daily Brick
● A few spare SD cards– It’s worth having a few extra cards just in case the one you’re using becomes corrupted or stops working for any reason. They are also useful for backing up your files and projects – I explain how to do this at the end of the chapter.
● An SD card reader/writer– You’ll need an SD card reader/writer to enable you to put the Raspberry Pi operating system software onto an SD card. You download the operating system software onto your computer, plug the card reader into a USB port on your computer and use it to copy the OS onto an SD card that you can then load onto your Raspberry Pi. Many desktop computers and laptops are already fitted with an SD card reader and writer but if your computer or laptop doesn’t have one, you will have to