You are previewing Learning Python with Raspberry Pi.
O'Reilly logo
Learning Python with Raspberry Pi

Book Description

The must-have companion guide to the Raspberry Pi User Guide!

Raspberry Pi chose Python as its teaching language of choice to encourage a new generation of programmers to learn how to program. This approachable book serves as an ideal resource for anyone wanting to use Raspberry Pi to learn to program and helps you get started with the Python programming language. Aimed at first-time developers with no prior programming language assumed, this beginner book gets you up and running.

  • Covers variables, loops, and functions

  • Addresses 3D graphics programming

  • Walks you through programming Minecraft

  • Zeroes in on Python for scripting

  • Learning Python with Raspberry Pi proves itself to be a fantastic introduction to coding.

    Table of Contents

      1. Introduction
        1. What Is Programming?
        2. Why the Raspberry Pi?
        3. How Does this Book Work?
      2. Chapter 1: Getting Up and Running
        1. Setting Up Your Raspberry Pi
        2. Solving Problems
        3. A Quick Tour of Raspbian
          1. Using LXDE (Lightweight X11 Desktop Environment)
          2. Using the Terminal
          3. Changing Configurations with Raspi-Config
          4. Installing Software
        4. Python 3
          1. The Python Interpreter
          2. Running Python Programs
        5. Summary
      3. Chapter 2: A Really Quick Introduction to Python
        1. Drawing Picture with Turtles
          1. Using Loops
          2. Conditionals: if, elif, and else
          3. Using Functions and Methods to Structure Code
        2. A Python Game of Cat and Mouse
          1. Understanding Variables
          2. Defining Functions
          3. Looping Through the Game
        3. Summary
      4. Chapter 3: Python Basics
        1. Variables, Values, and Types
          1. Values Have Types
          2. Storing Numbers
          3. Keeping Text in Strings
          4. Boolean: True or False
          5. Converting Between Data Types
          6. Test Your Knowledge
        2. Storing Values in Structures
          1. Non-Sequential Values in Dictionaries and Sets
          2. Test Your Knowledge
        3. Controlling the Way the Program Flows
          1. Moving Through Data with for Loops
          2. Going Deeper with Nested Loops
          3. Branching Execution with if Statements
          4. Catching Exceptions
        4. Making Code Reusable with Functions
          1. Optional Parameters
        5. Bringing Everything Together
        6. Building Objects with Classes
        7. Getting Extra Features from Modules
        8. Summary
        9. Solutions to Exercises
          1. Exercise 1
          2. Exercise 2
      5. Chapter 4: Graphical Programming
        1. Graphical User Interface (GUI) Programming
        2. Adding Controls
          1. Test Your Knowledge
        3. Creating a Web Browser
        4. Adding Window Menus
          1. Test Your Knowledge
        5. Summary
        6. Solutions to Exercises
      6. Chapter 5: Creating Games
        1. Building a Game
        2. Initialising PyGame
        3. Creating a World
          1. Detecting Collisions
          2. Moving Left and Right
          3. Reaching the Goal
          4. Making a Challenge
        4. Making It Your Own
        5. Adding Sound
        6. Adding Scenery
          1. Adding the Finishing Touches
        7. Taking the Game to the Next Level
        8. Realistic Game Physics
        9. Summary
      7. Chapter 6: Creating Graphics with OpenGL
        1. Getting Modules
        2. Creating a Spinning Cube
          1. Vectors and Matrices
          2. Bringing It All Together
          3. Let There Be Light
        3. Making the Screen Dance
          1. Building the 3D Model
          2. Calculating the Sound Level
        4. Taking Things Further
        5. Adding Some Texture
        6. Summary
      8. Chapter 7: Networked Python
        1. Understanding Hosts, Ports, and Sockets
          1. Locating Computers with IP Addresses
          2. Building a Chat Server
          3. Tweeting to the World
          4. Weather Forecasts with JSON
        2. Testing Your Knowledge
          1. Exercise 1
        3. Getting On the Web
          1. Making Your Website Dynamic
          2. Using Templates
          3. Sending Data Back with Forms
          4. Exercise 2
        4. Keeping Things Secure
        5. Summary
        6. Solutions to Exercises
          1. Exercise 1
      9. Chapter 8: Minecraft
        1. Exploring Minecraft
          1. Controlling Your Minecraft World
          2. Creating Minecraft Worlds in Python
          3. Taking Things Further
        2. Making the Game Snake
          1. Moving the Snake
          2. Growing the Snake
          3. Adding the Apples
        3. Taking Things Further
        4. Summary
      10. Chapter 9: Multimedia
        1. Using PyAudio to Get Sound into Your Computer
          1. Recording the Sound
          2. Speaking to Your Pi
          3. Asking the Program Questions
          4. Putting It All Together
          5. Taking Things Further
        2. Making Movies
          1. Using USB Webcams
          2. Adding Computer Vision Features with OpenCV
          3. Taking Things Further
          4. Using the Raspberry Pi Camera Module
          5. Creating Live Streams
          6. Taking Things Further
        3. Summary
      11. Chapter 10: Scripting
        1. Getting Started with the Linux Command Line
          1. Using the Subprocess Module
          2. Command-Line Flags
          3. Regular Expressions
        2. Testing Your Knowledge
        3. Scripting with Networking
        4. Bringing It All Together
        5. Working with Files in Python
        6. Summary
      12. Chapter 11: Interfacing with Hardware
        1. Setting Up Your Hardware Options
          1. Female to Male Jumper Wires
          2. Pi Cobbler
          3. Solderless Breadboard
          4. Stripboards and Prototyping Boards
          5. PCB Manufacturing
        2. Getting the Best Tools
          1. Wire Cutters/Strippers
          2. Multimeters
          3. Soldering Irons
        3. Hardware Needed for this Chapter
          1. The First Circuit
          2. Power Limits
          3. Getting Input
        4. Expanding the GPIO Options with I2C, SPI, and Serial
          1. The SPI Communications Protocol
          2. The I2C Communications Protocol
          3. The Serial Communications Protocol
        5. Taking the Example Further
          1. Arduino
          2. PiFace
          3. Gertboard
          4. Wireless Inventor's Kit
        6. Trying Some Popular Projects
          1. Robots
          2. Home Automation
          3. Burglar Alarms
          4. Digital Art
        7. Summary
      13. Chapter 12: Testing and Debugging
        1. Investigating Bugs by Printing Out the Values
        2. Finding Bugs by Testing
          1. Checking Bits of Code with Unit Tests
          2. Getting More Assertive
          3. Using Test Suites for Regression Testing
          4. Testing the Whole Package
          5. Making Sure Your Software's Usable
        3. How Much Should You Test?
        4. Summary