Book description
With millions of new users and several new models, the Raspberry Pi ecosystem continues to expand—along with many new questions about the Pi’s capabilities. The third edition of this popular cookbook provides more than 200 hands-on recipes that show you how to run this tiny low-cost computer with Linux; program it with Python; hook it up to sensors, motors, and Arduino boards; and even use it with the internet of things (IoT).
Prolific hacker and author Simon Monk also teaches basic principles to help you use new technologies with the Raspberry Pi. This cookbook is ideal for programmers and hobbyists familiar with the Pi through resources such as Getting Started with Raspberry Pi (O’Reilly). Code examples from the book are available on GitHub.
- 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
- 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
Publisher resources
Table of contents
- Preface to the Third 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. Writing a microSD Card with NOOBS
- 1.7. Installing an Operating System Without NOOBS
- 1.8. Using PiBakery to Configure and Write an SD Card
- 1.9. Using PiBakery to Configure a Headless Raspberry Pi
- 1.10. Booting from a Real Hard Disk or USB Flash Drive
- 1.11. Connecting a DVI or VGA Monitor
- 1.12. Using a Composite Video Monitor/TV
- 1.13. Adjusting the Picture Size on Your Monitor
- 1.14. Maximizing Performance
- 1.15. Changing Your Password
- 1.16. Shutting Down Your Raspberry Pi
- 1.17. Installing the Raspberry Pi Camera Module
- 1.18. 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. Controlling the Pi Remotely Using RDP
- 2.10. File Sharing on a Mac Network
- 2.11. Using a Raspberry Pi for Network Attached Storage
- 2.12. Network Printing
-
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-get
- 3.18. Removing Software Installed with apt-get
- 3.19. Installing Python Packages with Pip
- 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 or Script Automatically on Startup
- 3.24. Running a Program or Script Automatically as a Service
- 3.25. Running a Program or Script Automatically at Regular Intervals
- 3.26. Finding Things
- 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. Find Out What Operating System Version You Are Running
- 3.40. Updating Raspbian
- 4. Software
-
5. Python Basics
- 5.0. Introduction
- 5.1. Deciding Between Python 2 and Python 3
- 5.2. Editing Python Programs with Mu
- 5.3. Using the Python Console
- 5.4. Running Python Programs from the Terminal
- 5.5. Assigning Names to Values (Variables)
- 5.6. Displaying Output
- 5.7. Reading User Input
- 5.8. Arithmetic
- 5.9. Creating Strings
- 5.10. Concatenating (Joining) Strings
- 5.11. Converting Numbers into Strings
- 5.12. Converting Strings into Numbers
- 5.13. Finding the Length of a String
- 5.14. Finding the Position of One String Within Another
- 5.15. Extracting Part of a String
- 5.16. Replacing One String of Characters with Another Within a String
- 5.17. Converting a String to Uppercase or Lowercase
- 5.18. Running Commands Conditionally
- 5.19. Comparing Values
- 5.20. Logical Operators
- 5.21. Repeating Instructions an Exact Number of Times
- 5.22. Repeating Instructions Until Some Condition Changes
- 5.23. Breaking Out of a Loop
- 5.24. 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. Sorting a List
- 6.10. Cutting Up a List
- 6.11. Applying a Function to a List
- 6.12. Creating a Dictionary
- 6.13. Accessing a Dictionary
- 6.14. Removing Entries from a Dictionary
- 6.15. 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. Pickling
- 7.10. Handling Exceptions
- 7.11. Using Modules
- 7.12. Random Numbers
- 7.13. Making Web Requests from Python
- 7.14. 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. Using Python with Minecraft: Pi Edition
- 7.21. Parsing JSON
- 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. Hardware Basics
- 9.0. Introduction
- 9.1. Finding Your Way Around the GPIO Connector
- 9.2. Keeping Your Raspberry Pi Safe When Using the GPIO Connector
- 9.3. Setting Up I2C
- 9.4. Using I2C Tools
- 9.5. Setting Up SPI
- 9.6. Installing PySerial for Access to the Serial Port from Python
- 9.7. Installing Minicom to Test the Serial Port
- 9.8. Using a Breadboard with Jumper Leads
- 9.9. Using a Breadboard with a Pi Cobbler
- 9.10. Using a Raspberry Squid
- 9.11. Using a Raspberry Squid Button
- 9.12. Converting 5V Signals to 3.3V with Two Resistors
- 9.13. Converting 5V Signals to 3.3V with a Level Converter Module
- 9.14. Powering a Raspberry Pi with Batteries
- 9.15. Powering a Raspberry Pi with a LiPo Battery
- 9.16. Getting Started with the Sense HAT
- 9.17. Getting Started with the Explorer HAT Pro
- 9.18. Getting Started with a RasPiRobot Board
- 9.19. Using a Pi Plate Prototyping Board
- 9.20. Making a HAT
- 9.21. The Pi Zero and Pi Zero W
-
10. Controlling Hardware
- 10.0. Introduction
- 10.1. Connecting an LED
- 10.2. Leaving the GPIO Pins in a Safe State
- 10.3. Controlling the Brightness of an LED
- 10.4. Switching a High-Power DC Device Using a Transistor
- 10.5. Switching a High-Power Device Using a Relay
- 10.6. Controlling High-Voltage AC Devices
- 10.7. Controlling Hardware with Android and Bluetooth
- 10.8. Making a User Interface to Turn Things On and Off
- 10.9. Making a User Interface to Control PWM Power for LEDs and Motors
- 10.10. Changing the Color of an RGB LED
- 10.11. Using an Analog Meter as a Display
-
11. Motors
- 11.0. Introduction
- 11.1. Controlling Servo Motors
- 11.2. Controlling Servo Motors Precisely
- 11.3. Controlling Multiple Servo Motors Precisely
- 11.4. Controlling the Speed of a DC Motor
- 11.5. Controlling the Direction of a DC Motor
- 11.6. Using a Unipolar Stepper Motor
- 11.7. Using a Bipolar Stepper Motor
- 11.8. Using a Stepper Motor HAT to Drive a Bipolar Stepper Motor
- 11.9. Using a RasPiRobot Board to Drive a Bipolar Stepper Motor
- 11.10. Building a Simple Robot Rover
-
12. Digital Inputs
- 12.0. Introduction
- 12.1. Connecting a Push Switch
- 12.2. Toggling with a Push Switch
- 12.3. Using a Two-Position Toggle or Slide Switch
- 12.4. Using a Center-Off Toggle or Slide Switch
- 12.5. Debouncing a Button Press
- 12.6. Using an External Pull-Up Resistor
- 12.7. Using a Rotary (Quadrature) Encoder
- 12.8. Using a Keypad
- 12.9. Detecting Movement
- 12.10. Adding GPS to the Raspberry Pi
- 12.11. Intercepting Keypresses
- 12.12. Intercepting Mouse Movements
- 12.13. Using a Real-Time Clock Module
- 12.14. Giving the Raspberry Pi a Reset Button
-
13. Sensors
- 13.0. Introduction
- 13.1. Using Resistive Sensors
- 13.2. Measuring Light
- 13.3. Measuring Temperature with a Thermistor
- 13.4. Detecting Methane
- 13.5. Measuring CO2 Concentration
- 13.6. Measuring a Voltage
- 13.7. Reducing Voltages for Measurement
- 13.8. Using Resistive Sensors with an ADC
- 13.9. Measuring Temperature with an ADC
- 13.10. Measuring the Raspberry Pi CPU Temperature
- 13.11. Measuring Temperature, Humidity, and Pressure with a Sense HAT
- 13.12. Measuring Temperature Using a Digital Sensor
- 13.13. Measuring Acceleration with an MMA8452Q Module
- 13.14. Finding Magnetic North with the Sense HAT
- 13.15. Using the Inertial Management Unit of the Sense HAT
- 13.16. Sensing a Magnet with a Reed Switch
- 13.17. Sensing a Magnet with the Sense HAT
- 13.18. Measuring Distance Using Ultrasound
- 13.19. Measuring Distance Using a Time-of-Flight Sensor
- 13.20. Capacitive Touch Sensing
- 13.21. Reading Smart Cards with an RFID Reader/Writer
- 13.22. Displaying Sensor Values
- 13.23. Logging to a USB Flash Drive
-
14. Displays
- 14.0. Introduction
- 14.1. Using a Four-Digit LED Display
- 14.2. Displaying Messages on an I2C LED Matrix
- 14.3. Using the Sense HAT LED Matrix Display
- 14.4. Displaying Messages on an Alphanumeric LCD HAT
- 14.5. Using an OLED Graphical Display
- 14.6. Using Addressable RGB LED Strips
- 14.7. Using the Pimoroni Unicorn HAT
- 14.8. Using an ePaper Display
- 15. Sound
-
16. The Internet of Things
- 16.0. Introduction
- 16.1. Controlling GPIO Outputs Using a Web Interface
- 16.2. Displaying Sensor Readings on a Web Page
- 16.3. Getting Started with Node-RED
- 16.4. Sending Email and Other Notifications with IFTTT
- 16.5. Sending Tweets Using ThingSpeak
- 16.6. CheerLights
- 16.7. Sending Sensor Data to ThingSpeak
- 16.8. Responding to Tweets Using Dweet and IFTTT
-
17. Home Automation
- 17.0. Introduction
- 17.1. Making a Raspberry Pi into a Message Broker with Mosquitto
- 17.2. Using Node-RED with an MQTT Server
- 17.3. Flashing a Sonoff WiFi Smart Switch for MQTT Use
- 17.4. Configuring a Sonoff WiFi Smart Switch
- 17.5. Using Sonoff Web Switches with MQTT
- 17.6. Using Flashed Sonoff Switches with Node-RED
- 17.7. The Node-RED Dashboard
- 17.8. Scheduled Events with Node-RED
- 17.9. Publishing MQTT Messages from a Wemos D1
- 17.10. Using a Wemos D1 with Node-RED
-
18. Arduino and Raspberry Pi
- 18.0. Introduction
- 18.1. Programming an Arduino from Raspberry Pi
- 18.2. Communicating with an Arduino by Using the Serial Monitor
- 18.3. Setting Up PyFirmata to Control an Arduino from a Raspberry Pi
- 18.4. Writing Digital Outputs on an Arduino from a Raspberry Pi
- 18.5. Using PyFirmata with TTL Serial
- 18.6. Reading Arduino Digital Inputs Using PyFirmata
- 18.7. Reading Arduino Analog Inputs Using PyFirmata
- 18.8. Analog Outputs (PWM) with PyFirmata
- 18.9. Controlling a Servo Using PyFirmata
- 18.10. Using Small Arduino Boards with a Raspberry Pi
- 18.11. Using Small WiFi-Enabled Arduino-Compatibles (ESP8266)
- Parts and Suppliers
- Raspberry Pi Pinouts
- Index
Product information
- Title: Raspberry Pi Cookbook, 3rd Edition
- Author(s):
- Release date: October 2019
- Publisher(s): O'Reilly Media, Inc.
- ISBN: 9781492043171
You might also like
book
Raspberry Pi Cookbook, 4th Edition
If you've started to work with Raspberry Pi, you know that Raspberry Pi's capabilities are continually …
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
Mastering Embedded Linux Programming - Second Edition
Master the techniques needed to build great, efficient embedded devices on Linux About This Book Discover …