Raspberry Pi Cookbook

Book description

The world of Raspberry Pi is evolving quickly, with many new interface boards and software libraries becoming available all the time. In this cookbook, prolific hacker and author Simon Monk provides more than 200 practical recipes for running this tiny low-cost computer with Linux, programming it with Python, and hooking up sensors, motors, and other hardware—including Arduino.

Make sure to check out 10 of the over 60 video recipes for this book at: http://razzpisampler.oreilly.com/ You can purchase all recipes at:

Table of contents

  1. Preface
    1. 1. Conventions Used in This Book
    2. 2. Using Code Examples
    3. 3. Safari® Books Online
    4. 4. How to Contact Us
    5. 5. Acknowledgments
  2. 1. Setup and Management
    1. 1.0. Introduction
    2. 1.1. Selecting a Model of Raspberry Pi
    3. 1.2. Enclosing a Raspberry Pi
    4. 1.3. Selecting a Power Supply
    5. 1.4. Selecting an Operating System Distribution
    6. 1.5. Writing an SD Card with NOOBS
    7. 1.6. Writing an SD Card Manually (Mac)
    8. 1.7. Writing an SD Card Manually (Windows)
    9. 1.8. Writing an SD Card Manually (Linux)
    10. 1.9. Connecting the System
    11. 1.10. Connecting a DVI or VGA Monitor
    12. 1.11. Using a Composite Video Monitor/TV
    13. 1.12. Using All the Storage on the SD Card
    14. 1.13. Adjusting the Picture Size on your Monitor
    15. 1.14. Maximizing Performance
    16. 1.15. Changing Your Password
    17. 1.16. Setting the Pi to Boot Straight into a Windowing System
    18. 1.17. Shutting Down Your Raspberry Pi
    19. 1.18. Installing the Raspberry Pi Camera Module
  3. 2. Networking
    1. 2.0. Introduction
    2. 2.1. Connecting to a Wired Network
    3. 2.2. Finding Out Your IP Address
    4. 2.3. Setting a Static IP Address
    5. 2.4. Setting the Network Name of a Raspberry Pi
    6. 2.5. Setting Up a Wireless Connection
    7. 2.6. Connecting with a Console Lead
    8. 2.7. Controlling the Pi Remotely with SSH
    9. 2.8. Controlling the Pi Remotely with VNC
    10. 2.9. File Sharing on a Mac Network
    11. 2.10. Sharing the Pi Screen on a Mac
    12. 2.11. Using a Raspberry Pi for Network Attached Storage
    13. 2.12. Network Printing
  4. 3. Operating System
    1. 3.0. Introduction
    2. 3.1. Moving Files Around Graphically
    3. 3.2. Starting a Terminal Session
    4. 3.3. Navigating the Filesystem Using a Terminal
    5. 3.4. Copying a File or Folder
    6. 3.5. Renaming a File or Folder
    7. 3.6. Editing a File
    8. 3.7. Viewing the Contents of a File
    9. 3.8. Creating a File Without Using an Editor
    10. 3.9. Creating a Directory
    11. 3.10. Deleting a File or Directory
    12. 3.11. Performing Tasks with Superuser Privileges
    13. 3.12. Understanding File Permissions
    14. 3.13. Changing File Permissions
    15. 3.14. Changing File Ownership
    16. 3.15. Making a Screen Capture
    17. 3.16. Installing Software with apt-get
    18. 3.17. Removing Software Installed with apt-get
    19. 3.18. Fetching Files from the Command Line
    20. 3.19. Fetching Source Code with git
    21. 3.20. Running a Program or Script Automatically on Startup
    22. 3.21. Running a Program or Script Automatically at Regular Intervals
    23. 3.22. Finding Things
    24. 3.23. Using the Command-Line History
    25. 3.24. Monitoring Processor Activity
    26. 3.25. Working with File Archives
    27. 3.26. Listing Connected USB Devices
    28. 3.27. Redirecting Output from the Command Line to a File
    29. 3.28. Concatenating Files
    30. 3.29. Using Pipes
    31. 3.30. Hiding Output to the Terminal
    32. 3.31. Running Programs in the Background
    33. 3.32. Creating Command Aliases
    34. 3.33. Setting the Date and Time
    35. 3.34. Finding Out How Much Room You Have on the SD Card
  5. 4. Software
    1. 4.0. Introduction
    2. 4.1. Making a Media Center
    3. 4.2. Installing Office Software
    4. 4.3. Installing other Browsers
    5. 4.4. Using the Pi Store
    6. 4.5. Making a Webcam Server
    7. 4.6. Running a Vintage Game Console Emulator
    8. 4.7. Running Minecraft
    9. 4.8. Running Open Arena
    10. 4.9. Raspberry Pi Radio Transmitter
    11. 4.10. Running GIMP
    12. 4.11. Internet Radio
  6. 5. Python Basics
    1. 5.0. Introduction
    2. 5.1. Deciding Between Python 2 and Python 3
    3. 5.2. Editing Python Programs with IDLE
    4. 5.3. Using the Python Console
    5. 5.4. Running Python Programs from the Terminal
    6. 5.5. Variables
    7. 5.6. Displaying Output
    8. 5.7. Reading User Input
    9. 5.8. Arithmetic
    10. 5.9. Creating Strings
    11. 5.10. Concatenating (Joining) Strings
    12. 5.11. Converting Numbers to Strings
    13. 5.12. Converting Strings to Numbers
    14. 5.13. Find the Length of a String
    15. 5.14. Find the Position of One String Inside Another
    16. 5.15. Extracting Part of a String
    17. 5.16. Replacing One String of Characters with Another Inside a String
    18. 5.17. Converting a String to Upper- or Lowercase
    19. 5.18. Running Commands Conditionally
    20. 5.19. Comparing Values
    21. 5.20. Logical Operators
    22. 5.21. Repeating Instructions an Exact Number of Times
    23. 5.22. Repeating Instructions Until Some Condition Changes
    24. 5.23. Breaking Out of a Loop
    25. 5.24. Defining a Function in Python
  7. 6. Python Lists and Dictionaries
    1. 6.0. Introduction
    2. 6.1. Creating a List
    3. 6.2. Accessing Elements of a List
    4. 6.3. Find the Length of a List
    5. 6.4. Adding Elements to a List
    6. 6.5. Removing Elements from a List
    7. 6.6. Creating a List by Parsing a String
    8. 6.7. Iterating over a List
    9. 6.8. Enumerating a List
    10. 6.9. Sorting a List
    11. 6.10. Cutting Up a List
    12. 6.11. Applying a Function to a List
    13. 6.12. Creating a Dictionary
    14. 6.13. Accessing a Dictionary
    15. 6.14. Removing Things from a Dictionary
    16. 6.15. Iterating over Dictionaries
  8. 7. Advanced Python
    1. 7.0. Introduction
    2. 7.1. Formatting Numbers
    3. 7.2. Formatting Dates
    4. 7.3. Returning More Than One Value
    5. 7.4. Defining a Class
    6. 7.5. Defining a Method
    7. 7.6. Inheritance
    8. 7.7. Writing to a File
    9. 7.8. Reading from a File
    10. 7.9. Pickling
    11. 7.10. Handling Exceptions
    12. 7.11. Using Modules
    13. 7.12. Random Numbers
    14. 7.13. Making Web Requests from Python
    15. 7.14. Command-Line Arguments in Python
    16. 7.15. Sending Email from Python
    17. 7.16. Writing a Simple Web Server in Python
  9. 8. GPIO Basics
    1. 8.0. Introduction
    2. 8.1. Finding Your Way Around the GPIO Connector
    3. 8.2. Keeping Your Raspberry Pi Safe when Using the GPIO Connector
    4. 8.3. Installing RPi.GPIO
    5. 8.4. Setting Up I2C
    6. 8.5. Using I2C Tools
    7. 8.6. Setting Up SPI
    8. 8.7. Freeing the Serial Port
    9. 8.8. Installing PySerial for Access to the Serial Port from Python
    10. 8.9. Installing Minicom to Test the Serial Port
    11. 8.10. Using a Breadboard with Jumper Leads
    12. 8.11. Using a Breadboard with a Pi Cobbler
    13. 8.12. Converting 5V Signals to 3.3V with Two Resistors
    14. 8.13. Converting 5V Signals to 3.3V with a Level Converter Module
    15. 8.14. Powering a Raspberry Pi with Batteries
    16. 8.15. Powering a Raspberry Pi with a LiPo Battery
    17. 8.16. Getting Started with a PiFace Digital Interface Board
    18. 8.17. Getting Started with a Gertboard
    19. 8.18. Getting Started with a RaspiRobot Board
    20. 8.19. Using a Humble Pi Prototyping Board
    21. 8.20. Using a Pi Plate Prototyping Board
    22. 8.21. Using a Paddle Terminal Breakout Board
  10. 9. Controlling Hardware
    1. 9.0. Introduction
    2. 9.1. Connecting an LED
    3. 9.2. Controlling the Brightness of an LED
    4. 9.3. Make a Buzzing Sound
    5. 9.4. Switching a High-Power DC Device Using a Transistor
    6. 9.5. Switching a High-Power Device Using a Relay
    7. 9.6. Controlling High-Voltage AC Devices
    8. 9.7. Making a User Interface to Turn Things On and Off
    9. 9.8. Making a User Interface to Control PWM Power for LEDs and Motors
    10. 9.9. Changing the Color of an RGB LED
    11. 9.10. Using Lots of LEDs (Charlieplexing)
    12. 9.11. Using an Analog Meter as a Display
    13. 9.12. Programming with Interrupts
    14. 9.13. Controlling GPIO Outputs Using a Web Interface
  11. 10. Motors
    1. 10.0. Introduction
    2. 10.1. Controlling Servo Motors
    3. 10.2. Controlling a Large Number of Servo Motors
    4. 10.3. Controlling the Speed of a DC Motor
    5. 10.4. Controlling the Direction of a DC Motor
    6. 10.5. Using a Unipolar Stepper Motor
    7. 10.6. Using a Bipolar Stepper Motor
    8. 10.7. Using a RaspiRobot Board to Drive a Bipolar Stepper Motor
    9. 10.8. Building a Simple Robot Rover
  12. 11. Digital Inputs
    1. 11.0. Introduction
    2. 11.1. Connecting a Push Switch
    3. 11.2. Toggling with a Push Switch
    4. 11.3. Using a Two-Position Toggle or Slide Switch
    5. 11.4. Using a Center-Off Toggle or Slide Switch
    6. 11.5. Debouncing a Button Press
    7. 11.6. Using an External Pull-up Resistor
    8. 11.7. Using a Rotary (Quadrature) Encoder
    9. 11.8. Using a Keypad
    10. 11.9. Detecting Movement
    11. 11.10. Adding GPS to the Raspberry Pi
    12. 11.11. Intercepting Keypresses
    13. 11.12. Intercepting Mouse Movements
    14. 11.13. Using a Real-Time Clock Module
  13. 12. Sensors
    1. 12.0. Introduction
    2. 12.1. Using Resistive Sensors
    3. 12.2. Measuring Light
    4. 12.3. Detecting Methane
    5. 12.4. Measuring a Voltage
    6. 12.5. Reducing Voltages for Measurement
    7. 12.6. Using Resistive Sensors with an ADC
    8. 12.7. Measuring Temperature with an ADC
    9. 12.8. Measuring Acceleration
    10. 12.9. Measuring Temperature Using a Digital Sensor
    11. 12.10. Measuring Distance
    12. 12.11. Displaying Sensor Values
    13. 12.12. Logging to a USB Flash Drive
  14. 13. Displays
    1. 13.0. Introduction
    2. 13.1. Using a Four-Digit LED Display
    3. 13.2. Displaying Messages on an I2C LED matrix
    4. 13.3. Using Pi-Lite
    5. 13.4. Displaying Messages on an Alphanumeric LCD
  15. 14. Arduino and Raspberry Pi
    1. 14.0. Introduction
    2. 14.1. Programming an Arduino from Raspberry Pi
    3. 14.2. Communicating with the Arduino by Using the Serial Monitor
    4. 14.3. Setting Up PyFirmata to Control an Arduino from a Raspberry Pi
    5. 14.4. Writing Digital Outputs on an Arduino from a Raspberry Pi
    6. 14.5. Using PyFirmata with TTL Serial
    7. 14.6. Reading Arduino Digital Inputs Using PyFirmata
    8. 14.7. Reading Arduino Analog Inputs Using PyFirmata
    9. 14.8. Analog Outputs (PWM) with PyFirmata
    10. 14.9. Controlling a Servo Using PyFirmata
    11. 14.10. Custom Communication with an Arduino over TTL Serial
    12. 14.11. Custom Communication with an Arduino over I2C
    13. 14.12. Using Small Arduinos with a Raspberry Pi
    14. 14.13. Getting Started with an aLaMode Board and a Raspberry Pi
    15. 14.14. Using an Arduino Shield with an aLaMode Board and a Raspberry Pi
    16. 14.15. Using Gertboard as an Arduino Interface
  16. A. Parts and Suppliers
    1. Parts
    2. Prototyping Equipment
    3. Resistors and Capacitors
    4. Transistors and Diodes
    5. Integrated Circuits
    6. Opto-Electronics
    7. Modules
    8. Miscellaneous
  17. Index
  18. About the Author
  19. Colophon
  20. Copyright

Product information

  • Title: Raspberry Pi Cookbook
  • Author(s): Simon Monk
  • Release date: December 2013
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781449365226