You are previewing Getting Started with Raspberry Pi.

Getting Started with Raspberry Pi

Cover of Getting Started with Raspberry Pi by Matt Richardson... Published by Maker Media, Inc
  1. A Note Regarding Supplemental Files
  2. Preface
    1. What Can You Do With It?
    2. Raspberry Pi for Makers
    3. Linux and Raspberry Pi
    4. What Others Have Done With It
    5. Conventions Used in This Book
    6. Using Code Examples
    7. Safari® Books Online
    8. How to Contact Us
    9. Acknowledgements
  3. 1. Getting Up and Running
    1. A Tour of the Boards
    2. The Proper Peripherals
    3. The Case
    4. Choose Your Distribution
    5. Flash the SD Card
    6. Booting Up
    7. Configuring Your Pi
    8. Shutting Down
    9. Troubleshooting
    10. Going Further
  4. 2. Getting Around Linux on the Raspberry Pi
    1. Using the Command Line
      1. Files and the Filesystem
    2. More Linux Commands
      1. Processes
      2. Sudo and Permissions
      3. The Network
    3. /etc
    4. Setting the Date and Time
    5. Installing New Software
    6. Going Further
  5. 3. Python On The Pi
    1. Hello Python
    2. A Bit More Python
    3. Objects and Modules
    4. Even More Modules
    5. Troubleshooting Errors
    6. Going Further
  6. 4. Animation and Multimedia in Python
    1. Hello Pygame
    2. Pygame Surfaces
    3. Drawing on Surfaces
    4. Handling Events and Inputs
    5. Sprites
    6. Playing Sound
    7. Playing Video
    8. Further Reading
  7. 5. Scratch on the Pi
    1. Hello Scratch
    2. The Stage
    3. Two More Things to Know About Sprites
    4. A Bigger Example: Astral Trespassers
    5. Scratch and the Real World
    6. Sharing Your Programs
    7. Going Further
  8. 6. Arduino and the Pi
    1. Installing Arduino in Raspbian
      1. Finding the Serial Port
    2. Talking in Serial
    3. Going Further
  9. 7. Basic Input and Output
    1. Using Inputs and Outputs
      1. Digital Output: Lighting Up an LED
      2. Digital Input: Reading a Button
    2. Project: Cron Lamp Timer
      1. Scripting Commands
      2. Connecting a Lamp
      3. Scheduling Commands with cron
    3. Going Further
  10. 8. Programming Inputs and Outputs with Python
    1. Installing and Testing GPIO in Python
    2. Blinking an LED
    3. Reading a Button
    4. Project: Simple Soundboard
    5. Going Further
  11. 9. Working with Webcams
    1. Testing Webcams
    2. Installing and Testing SimpleCV
    3. Displaying an Image
    4. Modifying an Image
    5. Accessing the Webcam
    6. Face Detection
    7. Project: Raspberry Pi Photobooth
    8. Going Further
  12. 10. Python and The Internet
    1. Download Data from a Web Server
      1. Fetching the Weather Forecast
    2. Serving Pi (Be a Web Server)
      1. Flask Basics
    3. Connecting the Web to the Real World
    4. Project: WebLamp
    5. Going Further
  13. A. Writing an SD Card Image
    1. Writing an SD card from OS X
    2. Writing an SD card from Windows
    3. Writing an SD card from Linux
  14. B. Astral Trespassers Complete
  15. C. Analog Input
    1. Converting Analog to Digital
  16. About the Authors
  17. Colophon
  18. Copyright
O'Reilly logo

Chapter 8. Programming Inputs and Outputs with Python

At the end of Chapter 7, you did a little bit of programming with the Raspberry Pi’s GPIO pins using a shell script. In this chapter, you’re going to learn how to use Python to do the same thing… and a little more. Much like with the shell script, Python will let you access the pins by writing code to read and control the pins automatically.

The advantage that Python has over shell scripting is that the code is easier to write and is more readable. There’s also a whole slew of Python modules that make it easy for you to do some complex stuff with basic code. See Table 3-2 for a list of a few modules that might be useful in your projects. Best of all, there’s a Python module called raspberry-gpio-python ...

The best content for your career. Discover unlimited learning on demand for around $1/day.