The Official Raspberry Pi Beginner's Guide: How to use your new computer
4/5
()
About this ebook
Raspberry Pi is a small, clever, British-built computer that's packed with potential. Made using a desktop-class, energy-efficient processor, Raspberry Pi is designed to help you learn coding, discover how computers work, and build your own amazing things. This book was written to show you just how easy it is to get started.
Learn how to:
- Set up your Raspberry Pi, install its operating system, and start using this fully functional computer.
- Start coding projects, with step-by-step guides using the Scratch 3, Python, and MicroPython programming languages.
- Experiment with connecting electronic components, and have fun creating amazing projects.
This revised edition is updated for the latest Raspberry Pi computers: Raspberry Pi 5 and Raspberry Pi Zero 2 W as well as the latest Raspberry Pi OS. It also includes a new chapter on the Raspberry Pi Pico!
Whichever model you have, a standard Raspberry Pi board; the compact Raspberry Pi Zero 2 W; or the Raspberry Pi 400 with integrated keyboard, this affordable computer can be used to learn coding, build robots, and create all kinds of weird and wonderful projects. If you want to make games, build robots, or hack a variety of amazing projects, then this book is here to help you get started.
Gareth Halfacree
Gareth Halfacree is a freelance technology journalist, writer, and former system administrator in the education sector. With a passion for open-source software and hardware, he was an early adopter of the Raspberry Pi platform and has written several publications on its capabilities and flexibility. He can be found on Mastodon as @ghalfacree@mastodon.social or via his website at freelance.halfacree.co.uk.
Read more from Gareth Halfacree
The Official BBC micro:bit User Guide Rating: 4 out of 5 stars4/5Get started with MicroPython on Raspberry Pi Pico: The Official Raspberry Pi Pico Guide Rating: 0 out of 5 stars0 ratingsRaspberry Pi User Guide Rating: 4 out of 5 stars4/5
Related to The Official Raspberry Pi Beginner's Guide
Related ebooks
Raspberry Pi Server Essentials Rating: 0 out of 5 stars0 ratingsCutting-Edge Computing with Raspberry Pi Rating: 5 out of 5 stars5/5Raspberry Pi for Secret Agents Rating: 4 out of 5 stars4/5Programming the Raspberry Pi, Third Edition: Getting Started with Python Rating: 5 out of 5 stars5/5Raspberry Pi Computer Architecture Essentials Rating: 0 out of 5 stars0 ratingsIntel Galileo Blueprints Rating: 0 out of 5 stars0 ratingsRaspberry Pi :The Ultimate Step by Step Raspberry Pi User Guide (The Updated Version ) Rating: 4 out of 5 stars4/5Learning Raspbian Rating: 5 out of 5 stars5/5Learning Raspberry Pi Rating: 0 out of 5 stars0 ratingsGetting Started with Raspberry Pi Zero Rating: 5 out of 5 stars5/5Raspberry Pi Android Projects Rating: 0 out of 5 stars0 ratingsProgramming 5-Book Collection Rating: 1 out of 5 stars1/5Raspberry Pi Home Automation with Arduino - Second Edition Rating: 0 out of 5 stars0 ratingsThe Official Raspberry Pi Handbook 2023: Astounding projects with Raspberry Pi computers Rating: 0 out of 5 stars0 ratingsAdvanced Home Automation Using Raspberry Pi: Building Custom Hardware, Voice Assistants, and Wireless Nodes Rating: 0 out of 5 stars0 ratingsBuilding Smart Homes with Raspberry Pi Zero Rating: 0 out of 5 stars0 ratingsRaspberry Pi 3 Rating: 0 out of 5 stars0 ratingsRaspberry Pi: 40 Outstanding Raspberry Pi Tips and Tricks for Absolute Beginners Rating: 0 out of 5 stars0 ratingsIntel Galileo Essentials Rating: 0 out of 5 stars0 ratingsRaspberry Pi LED Blueprints Rating: 0 out of 5 stars0 ratingsThe Official Raspberry Pi Projects Book Volume 2: 200 Pages of Coding and Creating Rating: 0 out of 5 stars0 ratingsRaspberry Pi Robotic Projects - Third Edition Rating: 0 out of 5 stars0 ratingsRaspberry Pi Projects For Dummies Rating: 5 out of 5 stars5/5Raspberry Pi: The complete guide to Raspberry Pi for beginners, including projects, tips, tricks, and programming Rating: 0 out of 5 stars0 ratingsRaspberry Pi Essentials Rating: 0 out of 5 stars0 ratingsRaspberry Pi: Beginner's Guide - Learn Raspberry Pi in Easy Steps Rating: 2 out of 5 stars2/5Yocto for Raspberry Pi Rating: 0 out of 5 stars0 ratingsBuilding a NAS Server with Raspberry Pi and Openmediavault Rating: 0 out of 5 stars0 ratingsLearn Electronics with Raspberry Pi: Physical Computing with Circuits, Sensors, Outputs, and Projects Rating: 0 out of 5 stars0 ratings
Hardware For You
CompTIA A+ Complete Review Guide: Exam Core 1 220-1001 and Exam Core 2 220-1002 Rating: 5 out of 5 stars5/5CompTIA A+ Complete Review Guide: Core 1 Exam 220-1101 and Core 2 Exam 220-1102 Rating: 5 out of 5 stars5/5Chip War: The Fight for the World's Most Critical Technology Rating: 4 out of 5 stars4/5Creative Selection: Inside Apple's Design Process During the Golden Age of Steve Jobs Rating: 5 out of 5 stars5/5Programming Arduino: Getting Started with Sketches Rating: 4 out of 5 stars4/5Linux All-In-One For Dummies Rating: 2 out of 5 stars2/5Electrical Engineering | Step by Step Rating: 0 out of 5 stars0 ratingsRaspberry Pi Electronics Projects for the Evil Genius Rating: 3 out of 5 stars3/5iPhone X Hacks, Tips and Tricks: Discover 101 Awesome Tips and Tricks for iPhone XS, XS Max and iPhone X Rating: 3 out of 5 stars3/5Dancing with Qubits: How quantum computing works and how it can change the world Rating: 5 out of 5 stars5/5macOS Sonoma For Dummies Rating: 0 out of 5 stars0 ratingsiPhone For Dummies Rating: 0 out of 5 stars0 ratingsGoing iPad (Third Edition): Making the iPad Your Only Computer Rating: 5 out of 5 stars5/5Build Your Own PC Do-It-Yourself For Dummies Rating: 4 out of 5 stars4/5iPhone 12, iPhone Pro, and iPhone Pro Max For Senirs: A Ridiculously Simple Guide to the Next Generation of iPhone and iOS 14 Rating: 0 out of 5 stars0 ratingsDebugging: The 9 Indispensable Rules for Finding Even the Most Elusive Software and Hardware Problems Rating: 4 out of 5 stars4/5Arduino for Secret Agents Rating: 4 out of 5 stars4/5Troubleshooting and Maintaining Your PC All-in-One For Dummies Rating: 5 out of 5 stars5/5MacBook For Dummies Rating: 4 out of 5 stars4/5ESP8266 Internet of Things Cookbook Rating: 5 out of 5 stars5/5Linux All-in-One For Dummies Rating: 3 out of 5 stars3/5Amazon Web Services (AWS) Interview Questions and Answers Rating: 5 out of 5 stars5/5Chromebook For Dummies Rating: 5 out of 5 stars5/5Exploring Arduino: Tools and Techniques for Engineering Wizardry Rating: 4 out of 5 stars4/5Upgrading and Fixing Computers Do-it-Yourself For Dummies Rating: 4 out of 5 stars4/5Apple Watch For Dummies Rating: 0 out of 5 stars0 ratings
Reviews for The Official Raspberry Pi Beginner's Guide
6 ratings0 reviews
Book preview
The Official Raspberry Pi Beginner's Guide - Gareth Halfacree
The Official Raspberry Pi Beginner’s Guide, 5th Edition
The Official Raspberry Pi Beginner’s Guide
by Gareth Halfacree
ISBN: 978-1-912047-26-0
Copyright © 2024 Gareth Halfacree
Printed in the United Kingdom
Published by Raspberry Pi, Ltd., 194 Science Park, Cambridge, CB4 0AB
Editors: Brian Jepson, Liz Upton
Interior Designer: Sara Parodi
Production: Nellie McKesson
Photographer: Brian O’Halloran
Illustrator: Sam Alder
Graphics Editor: Natalie Turner
Publishing Director: Brian Jepson
Head of Design: Jack Willis
CEO: Eben Upton
July 2024: Fifth Edition, Second Printing
October 2023: Fifth Edition
November 2020: Fourth Edition
November 2019: Third Edition
June 2019: Second Edition
December 2018: First Edition
The publisher, and contributors accept no responsibility in respect of any omissions or errors relating to goods, products or services referred to or advertised in this book. Except where otherwise noted, the content of this book is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0).
Welcome to the Official Raspberry Pi Beginner’s Guide
We think you’re going to love your Raspberry Pi. Whichever model you have — a standard Raspberry Pi board, the compact Raspberry Pi Zero 2 W, or the Raspberry Pi 400 with integrated keyboard — this affordable computer can be used to learn coding, build robots, and create all kinds of weird and wonderful projects.
Raspberry Pi is capable of doing all the things you’d expect from a computer — everything from browsing the internet and playing games, to watching movies and listening to music. But your Raspberry Pi is much more than a modern computer.
With a Raspberry Pi you can get right into the heart of a computer. You get to set up your own operating system, and can connect wires and circuits directly to its GPIO pins. It was designed to teach young people how to program in languages like Scratch and Python, and all the major programming languages are included with the official operating system. With Raspberry Pi Pico, you can create unobtrusive, low-power projects that interact with the physical world.
The world needs programmers more than ever, and Raspberry Pi has ignited a love of computer science and technology in a new generation.
People of all ages use Raspberry Pi to create exciting projects: everything from retro games consoles to internet-connected weather stations.
So if you want to make games, build robots, or hack a variety of amazing projects, then this book is here to help you get started.
You can find example code and other information about this book, including errata, in its GitHub repository at rptl.io/bg-resources. If you’ve found what you believe is a mistake or error in the book, please let us know by using our errata submission form at rptl.io/bg-errata.
About the author
Gareth Halfacree is a freelance technology journalist, writer, and former system administrator in the education sector. With a passion for open-source software and hardware, he was an early adopter of the Raspberry Pi platform and has written several publications on its capabilities and flexibility. He can be found on Mastodon as @ghalfacree@mastodon.social or via his website at freelance.halfacree.co.uk.
Colophon
Raspberry Pi is an affordable way to do something useful, or to do something fun.
Democratising technology — providing access to tools — has been our motivation since the Raspberry Pi project began. By driving down the cost of general-purpose computing to below $5, we’ve opened up the ability for anybody to use computers in projects that used to require prohibitive amounts of capital. Today, with barriers to entry being removed, we see Raspberry Pi computers being used everywhere from interactive museum exhibits and schools to national postal sorting offices and government call centres. Kitchen table businesses all over the world have been able to scale and find success in a way that just wasn’t possible in a world where integrating technology meant spending large sums on laptops and PCs.
Raspberry Pi removes the high entry cost to computing for people across all demographics: while children can benefit from a computing education that previously wasn’t open to them, many adults have also historically been priced out of using computers for enterprise, entertainment, and creativity. Raspberry Pi eliminates those barriers.
Raspberry Pi Press
store.rpipress.cc
Raspberry Pi Press is your essential bookshelf for computing, gaming, and hands-on making. We are the publishing imprint of Raspberry Pi Ltd, part of the Raspberry Pi Foundation. From building a PC to building a cabinet, discover your passion, learn new skills, and make awesome stuff with our extensive range of books and magazines.
The MagPi
magpi.raspberrypi.com
The MagPi is the official Raspberry Pi magazine. Written for the Raspberry Pi community, it is packed with Pi-themed projects, computing and electronics tutorials, how-to guides, and the latest community news and events.
HackSpace
hackspace.raspberrypi.com
HackSpace magazine is filled with projects for fixers and tinkerers of all abilities. We’ll teach you new techniques and give you refreshers on familiar ones, from 3D printing, laser cutting, and woodworking to electronics and the Internet of Things. HackSpace will inspire you to dream bigger and build better.
Chapter 1
Get to know your Raspberry Pi
Introducing your new credit-card-sized computer. Take a guided tour of the Raspberry Pi, find out how it works, and discover some of the amazing things you can do with it.
Raspberry Pi is a remarkable device: a fully functional computer in a tiny, low-cost package. Whether you’re looking for a device you can use to browse the web or play games, are interested in learning how to write your own programs, or are looking to create your own circuits and physical devices, Raspberry Pi — and its amazing community — will support you every step of the way.
Raspberry Pi is known as a single-board computer, which means exactly what it sounds like: it’s a computer, just like a desktop, laptop, or smartphone, but built on a single printed circuit board. Like most single-board computers, Raspberry Pi is small — it has roughly the same footprint as a credit card — but that doesn’t mean it’s not powerful: a Raspberry Pi can do anything a bigger and more power-hungry computer can do, from browsing the web and playing games to driving other devices.
The Raspberry Pi family was born from a desire to encourage more hands-on computer education around the world. Its creators, who joined together to form the non-profit Raspberry Pi Foundation, had little idea that it would prove so popular: the few thousand built to test the waters in 2012 sold out immediately, and more than fifty million have been shipped all over the world in the years since. These boards have found their way into homes, classrooms, offices, data centres, factories, and even self-piloting boats and satellites.
Various models of Raspberry Pi have been released since the original Model B, each bringing either improved specifications or features specific to a particular use-case. The Raspberry Pi Zero family, for example, is a tiny version of the full-size Raspberry Pi which drops a few features — in particular the multiple USB ports and wired network port — in favour of a significantly smaller layout and reduced power requirements.
All Raspberry Pi models have one thing in common, though: they’re compatible, meaning that most software written for one model will run on any other model. It’s even possible to take the very latest version of Raspberry Pi’s operating system and run it on an original pre-launch Model B prototype. It will run more slowly, it’s true, but it will still run.
Throughout this book you’ll learn about Raspberry Pi 4 Model B, Raspberry Pi 5, Raspberry Pi 400, and Raspberry Pi Zero 2 W: the latest and most powerful versions of Raspberry Pi. Everything you learn can be easily applied to other models in the Raspberry Pi family, so don’t worry if you’re using a different model or revision.
RASPBERRY PI 400
If you have a Raspberry Pi 400, the circuit board is built into the keyboard case. Read on to learn about all the components that make Raspberry Pi tick, or skip to Raspberry Pi 400
for a tour of your desktop device.
RASPBERRY PI ZERO 2 W
If you have a Raspberry Pi Zero 2 W, some of the ports and components look different when compared to the Raspberry Pi 5. Read on to learn about what each component does, or skip to Raspberry Pi Zero 2 W
to learn more about your device.
A guided tour of Raspberry Pi
Unlike a traditional computer, which hides its inner workings in a case, a standard Raspberry Pi has all its components, ports, and features out on display — although you can buy a case to provide extra protection, if you’d prefer. This makes it a great tool for learning about what the various parts of a computer do, and also makes it easy to learn what goes where when it comes time to plug in the various other pieces of hardware — known as peripherals — you’ll need to get started.
Figure 1-1 shows a Raspberry Pi 5 from above. When you’re using a Raspberry Pi with this book, try to keep it oriented the same way as in the pictures; otherwise it can get confusing when it comes to using things like the GPIO header (detailed in Chapter 6, Physical computing with Scratch and Python).
Figure 1-1: Raspberry Pi 5
GPIO header
Wireless
RAM
RP1 I/O controller chip
Connector for fan
USB 2.0
USB 3.0
Ethernet port
Power-over-Ethernet (PoE) pins
CSI/DSI camera/display port 0
CSI/DSI camera/display port 1
Micro HDMI 1
Connector for UART serial port
System-on-chip
Micro HDMI 0
Real-time clock battery header
USB Type-C power in
Power button
Connector for PCI Express (PCIe)
While it may look like there’s an overwhelming amount packed into such a tiny board, a Raspberry Pi is very simple to understand — starting with its components, the inner workings that make the device tick.
Raspberry Pi’s components
Like any computer, Raspberry Pi is made up of many components, each of which has a role to play in making it work. The first, and arguably most important, of these can be found just to the left of the centre point of the board (Figure 1-2), covered in a metal cap: this is the system-on-chip (SoC).
The name ‘system-on-chip’ is a great indicator of what you would find if you prised the metal cover off: a silicon chip, known as an integrated circuit, that contains the bulk of Raspberry Pi’s system. This integrated circuit includes a central processing unit (CPU), commonly thought of as the ‘brain’ of a computer, and a graphics processing unit (GPU), which handles the visual rendering and display output side of things.
A brain is no good without memory, however, and just above the SoC you’ll find exactly that: a small, black, plastic-covered rectangular chip (Figure 1-3). This is Raspberry Pi’s random-access memory (RAM). When you’re working on Raspberry Pi, it’s the RAM that holds what you’re doing. Saving your work moves this data to the more permanent storage of the microSD card. Together, these components form Raspberry Pi’s volatile and non-volatile memory: the volatile RAM loses its contents whenever Raspberry Pi loses power, while the non-volatile memory in the microSD card keeps its contents.
Figure 1-2: Raspberry Pi’s system-on-chip (SoC)
Figure 1-3: Raspberry Pi’s random access memory (RAM)
At the top left of the board you’ll find another metal lid (Figure 1-4) covering the radio, the component that Raspberry Pi the ability to communicate with devices wirelessly. In fact, the radio itself fills the role of two other common components: a WiFi radio that connects to computer networks; and a Bluetooth radio that connects to peripherals like mice and sends or receives data from nearby smart devices like sensors or smartphones.
Another black, plastic-covered chip marked with the Raspberry Pi logo can be found on the right side of the board, near the USB ports (Figure 1-5). This is RP1, a custom I/O controller chip which communicates with the four USB ports, the Ethernet port, and most low-speed interfaces to other hardware.
Figure 1-4: Raspberry Pi’s radio module
Figure 1-5: Raspberry Pi’s RP1 controller chip
Another black chip, smaller than the rest, can be found a little bit above the USB C power connector at the bottom left of the board (Figure 1-6). This is known as a power management integrated circuit (PMIC); it takes the power that comes in from the USB C port and turns it into the power your Raspberry Pi needs to run.
The final black chip, below RP1 and positioned at a jaunty angle, helps the RP1 in handling Raspberry Pi’s Ethernet port. It provides what is known as an Ethernet PHY, providing the physical interface which sits between the Ethernet port itself and the Ethernet controller in the RP1 chip.
Figure 1-6: Raspberry Pi’s power management integrated circuit (PMIC)
Don’t worry if this seems like a lot to take in: you don’t need to know what each component is or where to find it on the board in order to use Raspberry Pi.
Raspberry Pi’s ports
Raspberry Pi has a range of ports, starting with four Universal Serial Bus (USB) ports (Figure 1-7) at the middle and top of its right-hand edge. These ports let you connect any USB-compatible peripheral — like keyboards, mice, digital cameras, and flash drives — to your Raspberry Pi. Speaking technically, there are two types of USB ports on Raspberry Pi, each relating to a different Universal Serial Bus standard: the ones with black plastic inside are USB 2.0 ports and the ones with blue plastic are newer and faster USB 3.0 ports.
Next to the USB ports is an Ethernet port, also known as a network port (Figure 1-8). You can use this port to connect your Raspberry Pi to a wired computer network with a cable that uses what is known as an RJ45 connector. If you look closely at the Ethernet port, you’ll see two light-emitting diodes (LEDs) at the bottom. These are status lights which, when lit or blinking, let you know the connection is working.
Figure 1-7: Raspberry Pi’s USB ports
Figure 1-8: Raspberry Pi’s Ethernet port
Just to the left of the Ethernet port, on the bottom edge of Raspberry Pi, is a Power-over-Ethernet (PoE) connector (Figure 1-9). This connector, when paired with the Raspberry Pi 5 PoE+ HAT — Hardware Attached on Top, a special add-on board designed for Raspberry Pi — and a suitable PoE-capable network switch, lets you power Raspberry Pi from its Ethernet port without having to connect anything to the USB Type-C connector. The same connector is also available on Raspberry Pi 4, though in a different location; Raspberry Pi 4 and Raspberry Pi 5 use different HATs for PoE support.
Directly to the left of the PoE connector are a pair of strange-looking connectors with plastic flaps you can pull up; these are the camera and display connectors, also known as the Camera Serial Interface (CSI) and Display Serial Interface(DSI) ports (Figure 1-10).
Figure 1-9: Raspberry Pi’s Power-over-Ethernet connector
Figure 1-10: Raspberry Pi’s camera and display connectors
You can use these connectors to connect a DSI-compatible display like the Raspberry Pi Touchscreen Display or the specially designed Raspberry Pi Camera Module family (see Figure 1-11). You’ll learn more about camera modules in Chapter 8, Raspberry Pi Camera Modules. Either port can act as a camera input or display output so you can have two CSI cameras, two DSI displays, or one CSI camera and one DSI display running on a single Raspberry Pi 5.
To the left of the camera and display connectors, still on the bottom edge of the board, are the micro High Definition Multimedia Interface (micro HDMI) ports, which are smaller versions of the connectors you can find on a games console, set-top box, or TV (Figure 1-12). The ‘multimedia’ part of its name means that it carries both audio and video signals, while ‘high-definition’ means you can expect excellent quality from both signals. You’ll use these micro HDMI ports to connect Raspberry Pi to one or two display devices, such as a computer monitor, TV, or projector.
Figure 1-11: Raspberry Pi’s camera module
Figure 1-12: Raspberry Pi’s micro HDMI ports
Between the two micro HDMI ports is a small connector labelled ‘UART,’ which provides access to a Universal Asynchronous Receiver-Transmitter (UART) serial port. You won’t use that port in this book, but you may need it in the future for communicating with, or troubleshooting, more complex projects.
To the left of the micro HDMI ports is another small connector labelled ‘BAT’, where you can connect a small battery to keep Raspberry Pi’s real-time clock (RTC) ticking, even when it’s disconnected from its power supply. You don’t need to connect a battery to use Raspberry Pi, though, since it will automatically update its clock when turned on, so long as it has access to the internet.
At the bottom left of the board is a USB C power port (Figure 1-13), used to provide Raspberry Pi with power through a compatible USB C power supply. The USB C port is a common sight on smartphones, tablets, and other portable devices. While you could use a standard mobile charger to power your Raspberry Pi, for best results you should use the official Raspberry Pi USB-C Power Supply: it’s better at coping with the sudden changes in power requirements that can occur when your Raspberry Pi is working particularly hard.
At the left edge of the board is a small button facing outwards. This is Raspberry Pi 5’s power button, used to safely shut down your Raspberry Pi when you’re finished with it. This button is not available on Raspberry Pi 4 or older boards.
Above the