Book description
If you've started to work with Raspberry Pi, you know that Raspberry Pi's capabilities are continually expanding. The fourth edition of this popular cookbook provides more than 200 hands-on recipes (complete with code) that show you how to run this tiny low-cost computer with Linux, program it with Python, hook it up to sensors and motors, and use it with the internet of things (IoT). This new edition includes new chapters on the Raspberry Pi Pico and machine learning with the Raspberry Pi.
These easy-to-use recipes will show you, step-by-step, how to:
- Set up your Raspberry Pi and connect to a network
- Work with its Linux-based operating system
- Program your Raspberry Pi with Python
- Give your Pi "eyes" with computer vision
- Recognize objects from video and sounds using machine learning
- Control hardware through the GPIO connector
- Use your Raspberry Pi to run different types of motors
- Work with switches, keypads, and other digital inputs
- Use sensors to measure temperature, light, and distance
- Connect to IoT devices in various ways and automate your home
- Use the Raspberry Pi Pico microcontroller board with your Raspberry Pi
Publisher resources
Table of contents
- Preface to the Fourth Edition
-
1. Setup and Management
- 1.0. Introduction
- 1.1. Selecting a Model of Raspberry Pi
- 1.2. Connecting the System
- 1.3. Enclosing a Raspberry Pi
- 1.4. Selecting a Power Supply
- 1.5. Selecting an Operating System
- 1.6. Installing an Operating System Using Raspberry Pi Imager
- 1.7. Booting Up Your Raspberry Pi for the First Time
- 1.8. Setting Up a Headless Raspberry Pi
- 1.9. Booting from a Real Hard Disk or USB Flash Drive
- 1.10. Connecting a DVI or VGA Monitor
- 1.11. Using a Composite Video Monitor/TV
- 1.12. Adjusting the Picture Size on Your Monitor
- 1.13. Maximizing Performance
- 1.14. Changing Your Password
- 1.15. Shutting Down Your Raspberry Pi
- 1.16. Installing the Raspberry Pi Camera Module
- 1.17. Using Bluetooth
-
2. Networking
- 2.0. Introduction
- 2.1. Connecting to a Wired Network
- 2.2. Finding Your IP Address
- 2.3. Setting a Static IP Address
- 2.4. Setting the Network Name of a Raspberry Pi
- 2.5. Setting Up a Wireless Connection
- 2.6. Connecting with a Console Lead
- 2.7. Controlling the Pi Remotely with SSH
- 2.8. Controlling the Pi Remotely with VNC
- 2.9. Using a Raspberry Pi for Network-Attached Storage
- 2.10. Setting Up a Network Printer
-
3. Operating System
- 3.0. Introduction
- 3.1. Browsing Files Graphically
- 3.2. Copying Files onto a USB Flash Drive
- 3.3. Starting a Terminal Session
- 3.4. Navigating the Filesystem Using a Terminal
- 3.5. Copying a File or Folder
- 3.6. Renaming a File or Folder
- 3.7. Editing a File
- 3.8. Viewing the Contents of a File
- 3.9. Creating a File Without Using an Editor
- 3.10. Creating a Directory
- 3.11. Deleting a File or Directory
- 3.12. Performing Tasks with Superuser Privileges
- 3.13. Understanding File Permissions
- 3.14. Changing File Permissions
- 3.15. Changing File Ownership
- 3.16. Making a Screen Capture
- 3.17. Installing Software with apt
- 3.18. Removing Software Installed with apt
- 3.19. Installing Python Packages with pip3
- 3.20. Fetching Files from the Command Line
- 3.21. Fetching Source Code with Git
- 3.22. Fetching This Bookâs Accompanying Code
- 3.23. Running a Program Automatically on Startup
- 3.24. Running a Program Automatically as a Service
- 3.25. Running a Program Automatically at Regular Intervals
- 3.26. Finding a File
- 3.27. Using the Command-Line History
- 3.28. Monitoring Processor Activity
- 3.29. Working with File Archives
- 3.30. Listing Connected USB Devices
- 3.31. Redirecting Output from the Command Line to a File
- 3.32. Concatenating Files
- 3.33. Using Pipes
- 3.34. Hiding Output to the Terminal
- 3.35. Running Programs in the Background
- 3.36. Creating Command Aliases
- 3.37. Setting the Date and Time
- 3.38. Finding Out How Much Room You Have on the SD Card
- 3.39. Finding Out What Operating System Version You Are Running
- 3.40. Updating Raspberry Pi OS
-
4. Using Ready-Made Software
- 4.0. Introduction
- 4.1. Making a Media Center
- 4.2. Installing Recommended Software
- 4.3. Using Office Software
- 4.4. Running a Vintage Game Console Emulator
- 4.5. Turning Your Raspberry Pi into a Radio Transmitter
- 4.6. Editing Bitmap Images
- 4.7. Editing Vector Images
- 4.8. Using Bookshelf
- 4.9. Playing Internet Radio
- 4.10. Using Visual Studio Code
- 4.11. Controlling a Laser Cutter
-
5. Python Basics
- 5.0. Introduction
- 5.1. Deciding Between Python 2 and Python 3
- 5.2. Choosing a Python Editor
- 5.3. Editing Python Programs with Thonny
- 5.4. Editing Python Programs with Mu
- 5.5. Using the Python Console
- 5.6. Running Python Programs from the Terminal
- 5.7. Assigning Names to Values (Variables)
- 5.8. Displaying Output
- 5.9. Reading User Input
- 5.10. Using Arithmetic Operators
- 5.11. Creating Strings
- 5.12. Concatenating (Joining) Strings
- 5.13. Converting Numbers into Strings
- 5.14. Converting Strings into Numbers
- 5.15. Finding the Length of a String
- 5.16. Finding the Position of One String Within Another
- 5.17. Extracting Part of a String
- 5.18. Replacing One String of Characters with Another Within a String
- 5.19. Converting a String to Uppercase or Lowercase
- 5.20. Running Commands Conditionally (if)
- 5.21. Comparing Values
- 5.22. Using Logical Operators
- 5.23. Repeating Instructions an Exact Number of Times
- 5.24. Repeating Instructions Until Some Condition Changes
- 5.25. Breaking Out of a Loop
- 5.26. Defining a Function in Python
-
6. Python Lists and Dictionaries
- 6.0. Introduction
- 6.1. Creating a List
- 6.2. Accessing Elements of a List
- 6.3. Finding the Length of a List
- 6.4. Adding Elements to a List
- 6.5. Removing Elements from a List
- 6.6. Creating a List by Parsing a String
- 6.7. Iterating Over a List
- 6.8. Enumerating a List
- 6.9. Testing if Something Is in a List
- 6.10. Sorting a List
- 6.11. Cutting Up a List
- 6.12. Using Comprehensions
- 6.13. Creating a Dictionary
- 6.14. Accessing a Dictionary
- 6.15. Removing Entries from a Dictionary
- 6.16. Iterating Over Dictionaries
-
7. Advanced Python
- 7.0. Introduction
- 7.1. Formatting Numbers
- 7.2. Formatting Dates and Times
- 7.3. Returning More Than One Value
- 7.4. Defining a Class
- 7.5. Defining a Method
- 7.6. Inheritance
- 7.7. Writing to a File
- 7.8. Reading from a File
- 7.9. Using Pickling to Save and Load Data in a File
- 7.10. Handling Exceptions
- 7.11. Using Modules
- 7.12. Generating Random Numbers
- 7.13. Making Web Requests from Python
- 7.14. Specifying Command-Line Arguments in Python
- 7.15. Running Linux Commands from Python
- 7.16. Sending Email from Python
- 7.17. Writing a Simple Web Server in Python
- 7.18. Doing Nothing in Python
- 7.19. Doing More Than One Thing at a Time
- 7.20. Parsing JSON Data
- 7.21. Saving Dictionaries as JSON Files
- 7.22. Creating User Interfaces
- 7.23. Using Regular Expressions to Search for Patterns in Text
- 7.24. Using Regular Expressions to Validate Data Entry
- 7.25. Using Regular Expressions for Web Scraping
- 8. Computer Vision
-
9. Machine Learning
- 9.0. Introduction
- 9.1. Identifying Objects in Video with TensorFlow Lite
- 9.2. Reacting to Objects in Video with TensorFlow Lite
- 9.3. Identifying Sounds with TensorFlow Lite
- 9.4. Reacting to a Whistle with TensorFlow Lite
- 9.5. Installing Edge Impulse
- 9.6. Recognizing a Spoken Command (in the Cloud)
- 9.7. Recognizing a Spoken Command (Locally)
- 9.8. Responding to a Spoken Command in Python
-
10. Hardware Basics
- 10.0. Introduction
- 10.1. Finding Your Way Around the GPIO Connector
- 10.2. Using the GPIO Connector on a Raspberry Pi 400
- 10.3. Keeping Your Raspberry Pi Safe When Using the GPIO Connector
- 10.4. Setting Up I2C
- 10.5. Using I2C Tools
- 10.6. Setting Up SPI
- 10.7. Installing pySerial for Access to the Serial Port from Python
- 10.8. Installing Minicom to Test the Serial Port
- 10.9. Using a Breadboard with Jumper Leads
- 10.10. Using a Raspberry Squid
- 10.11. Using a Raspberry Squid Button
- 10.12. Converting 5V Signals to 3.3V with Two Resistors
- 10.13. Converting 5V Signals to 3.3V with a Level Converter Module
- 10.14. Powering a Raspberry Pi with a LiPo Battery
- 10.15. Getting Started with the Sense HAT
- 10.16. Getting Started with the Explorer HAT Pro
- 10.17. Making a HAT
- 10.18. Using the Raspberry Pi Zero 2 and Pi Zero 2 W
-
11. Controlling Hardware
- 11.0. Introduction
- 11.1. Connecting an LED
- 11.2. Leaving the GPIO Pins in a Safe State
- 11.3. Controlling the Brightness of an LED
- 11.4. Switching a High-Power DC Device Using a Transistor
- 11.5. Switching a High-Power Device Using a Relay
- 11.6. Switching Using a Solid-State Relay
- 11.7. Controlling High-Voltage AC Devices
- 11.8. Controlling Hardware with Android and Bluetooth
- 11.9. Making a User Interface to Turn Things On and Off
- 11.10. Making a User Interface to Control PWM Power for LEDs and Motors
- 11.11. Making a User Interface to Change the Color of an RGB LED
- 11.12. Using an Analog Meter as a Display
-
12. Motors
- 12.0. Introduction
- 12.1. Controlling Servomotors
- 12.2. Controlling Servomotors Precisely
- 12.3. Controlling Multiple Servomotors Precisely
- 12.4. Controlling the Speed of a DC Motor
- 12.5. Controlling the Direction of a DC Motor
- 12.6. Using a Unipolar Stepper Motor
- 12.7. Using a Bipolar Stepper Motor
- 12.8. Using a Stepper Motor HAT to Drive a Bipolar Stepper Motor
-
13. Digital Inputs
- 13.0. Introduction
- 13.1. Connecting a Push Switch
- 13.2. Toggling with a Push Switch
- 13.3. Using a Two-Position Toggle or Slide Switch
- 13.4. Using a Center-Off Toggle or Slide Switch
- 13.5. Debouncing a Button Press
- 13.6. Using an External Pull-Up Resistor
- 13.7. Using a Rotary (Quadrature) Encoder
- 13.8. Using a Keypad
- 13.9. Detecting Movement
- 13.10. Adding GPS to the Raspberry Pi
- 13.11. Intercepting Keypresses
- 13.12. Intercepting Mouse Movements
- 13.13. Giving the Raspberry Pi a Reset Button
-
14. Sensors
- 14.0. Introduction
- 14.1. Using Resistive Sensors
- 14.2. Measuring Light
- 14.3. Measuring Temperature with a Thermistor
- 14.4. Detecting Methane
- 14.5. Measuring Air Quality (CO2)
- 14.6. Measuring Soil Moisture
- 14.7. Measuring a Voltage
- 14.8. Reducing Voltages for Measurement
- 14.9. Using Resistive Sensors with an ADC
- 14.10. Measuring Temperature with an ADC
- 14.11. Measuring the Raspberry Pi CPU Temperature
- 14.12. Measuring Temperature, Humidity, and Pressure with a Sense HAT
- 14.13. Measuring Temperature Using a Digital Sensor
- 14.14. Measuring Acceleration with an MMA8452Q Module
- 14.15. Finding Magnetic North with the Sense HAT
- 14.16. Using the Inertial Measurement Unit of the Sense HAT
- 14.17. Sensing a Magnet with a Reed Switch
- 14.18. Sensing a Magnet with the Sense HAT
- 14.19. Measuring Distance Using Ultrasound
- 14.20. Measuring Distance Using a Time-of-Flight Sensor
- 14.21. Adding Touch Sensing to Your Raspberry Pi
- 14.22. Reading Smart Cards with an RFID Reader/Writer
- 14.23. Displaying Sensor Values
- 14.24. Logging to a USB Flash Drive
- 15. Displays
- 16. Sound
-
17. The Internet of Things
- 17.0. Introduction
- 17.1. Controlling GPIO Outputs Using a Web Interface
- 17.2. Displaying Sensor Readings on a Web Page
- 17.3. Getting Started with Node-RED
- 17.4. Sending Email and Other Notifications with IFTTT
- 17.5. Sending Tweets Using ThingSpeak
- 17.6. Changing LED Color Using CheerLights
- 17.7. Sending Sensor Data to ThingSpeak
- 17.8. Responding to Tweets Using Dweet and IFTTT
-
18. Home Automation
- 18.0. Introduction
- 18.1. Making a Raspberry Pi into a Message Broker with Mosquitto
- 18.2. Using Node-RED with an MQTT Server
- 18.3. Flashing a Sonoff WiFi Smart Switch for MQTT Use
- 18.4. Configuring a Sonoff WiFi Smart Switch
- 18.5. Using Sonoff Web Switches with MQTT
- 18.6. Using Flashed Sonoff Switches with Node-RED
- 18.7. Turning Things On and Off Using the Node-RED Dashboard
- 18.8. Scheduling Events with Node-RED
- 18.9. Publishing MQTT Messages from a Wemos D1
- 18.10. Using a Wemos D1 with Node-RED
-
19. Raspberry Pi Pico and Pico W
- 19.0. Introduction
- 19.1. Connecting a Pico or Pico W to a Computer
- 19.2. Using the Python Shell on a Pico
- 19.3. Using a Pico with a Breadboard
- 19.4. Using Digital Outputs on a Pico
- 19.5. Using Digital Inputs on a Pico
- 19.6. Using Analog (PWM) Outputs on a Pico
- 19.7. Using Analog Inputs on a Pico
- 19.8. Controlling a Servomotor from a Pico
- 19.9. Using the Pico and Pico Wâs Filesystem
- 19.10. Making Use of the Second Core
- 19.11. Running a WiFi Web Server on the Pico W
- 19.12. Using Pico-Compatible Boards
- 19.13. Using the Pico on Batteries
- Parts and Suppliers
- Raspberry Pi Pinouts
- Index
- About the Author
Product information
- Title: Raspberry Pi Cookbook, 4th Edition
- Author(s):
- Release date: December 2022
- Publisher(s): O'Reilly Media, Inc.
- ISBN: 9781098130923
You might also like
book
Raspberry Pi Cookbook, 3rd Edition
With millions of new users and several new models, the Raspberry Pi ecosystem continues to expand—along …
book
Arduino Cookbook, 3rd Edition
Want to create devices that interact with the physical world? This cookbook is perfect for anyone …
book
Getting Started With Arduino, 4th Edition
Arduino is the open source electronics prototyping platform that has taken the Maker Movement by storm. …
book
Linux Cookbook, 2nd Edition
This handy cookbook teaches new-to-intermediate Linux users the essential skills necessary to manage a Linux system, …