O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Getting Started with Python and Raspberry Pi

Book Description

Learn to design and implement reliable Python applications on the Raspberry Pi using a range of external libraries, the Raspberry Pis GPIO port, and the camera module

About This Book

  • Learn the fundamentals of Python scripting and application programming
  • Design user-friendly command-line and graphical user interfaces
  • A step-by-step guide to learning Python programming with the Pi

Who This Book Is For

This book is designed for those who are unfamiliar with the art of Python development and want to get to know their way round the language and the many additional libraries that allow you to get a full application up and running in no time.

What You Will Learn

  • Fundamentals of Python applications
  • Designing applications for multi-threading
  • Interacting with electronics and physical devices
  • Debugging applications when they go wrong
  • Packaging and installing Python modules
  • User interface design using Qt
  • Building easy to use command-line interfaces
  • Connecting applications to the Internet

In Detail

The Raspberry Pi is one of the smallest and most affordable single board computers that has taken over the world of hobby electronics and programming, and the Python programming language makes this the perfect platform to start coding with.

The book will start with a brief introduction to Raspberry Pi and Python. We will direct you to the official documentation that helps you set up your Raspberry Pi with the necessary equipment such as the monitor, keyboard, mouse, power supply, and so on. It will then dive right into the basics of Python programming. Later, it will focus on other Python tasks, for instance, interfacing with hardware, GUI programming, and more. Once you get well versed with the basic programming, the book will then teach you to develop Python/Raspberry Pi applications.

By the end of this book, you will be able to develop Raspberry Pi applications with Python and will have good understanding of Python programming for Raspberry Pi.

Style and approach

An easy-to-follow introduction to Python scripting and application development through clear conceptual explanations backed up by real-world examples on the Raspberry Pi.

Downloading the example code for this book You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Table of Contents

  1. Getting Started with Python and Raspberry Pi
    1. Table of Contents
    2. Getting Started with Python and Raspberry Pi
    3. Credits
    4. About the Author
    5. About the Reviewers
    6. www.PacktPub.com
      1. Support files, eBooks, discount offers, and more
        1. Why subscribe?
        2. Free access for Packt account holders
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    8. 1. Your First Steps with Python on the Pi
      1. Installing and setting up Raspbian
        1. Writing to the SD card
          1. Windows
          2. Linux and Mac
        2. Booting the Pi for the first time
      2. The Python development tools
        1. Python 2 versus Python 3
      3. Running some simple Python scripts
      4. Summary
    9. 2. Understanding Control Flow and Data Types
      1. Data in Python
        1. Numerical types
        2. Operations on numerical types
        3. String manipulation
          1. String functions
          2. String formatting
          3. String templates
      2. Control flow operators
      3. Using functions
      4. Summary
    10. 3. Working with Data Structures and I/O
      1. Data structures
        1. Lists
          1. Creating lists
          2. List operations
        2. Dictionaries
          1. Creating dictionaries
          2. Dictionary operations
        3. Sets
          1. Set operations
          2. Frozen sets
        4. Tuples
      2. Input/output
        1. The os.path module
        2. Reading and writing files
      3. Summary
    11. 4. Understanding Object-oriented Programming and Threading
      1. Object-oriented programming
      2. Classes in Python
        1. Operation.py
        2. Calculator.py
        3. Using the module
        4. Inheritance
      3. Threading
        1. Locks
      4. Summary
    12. 5. Packaging Code with setuptools
      1. Using packages in your Python code
        1. Importing modules
        2. Installing modules manually
        3. Installing modules using pip
        4. Installing modules using apt
      2. Packaging your own Python modules
        1. Packaging a library
        2. Adding an entry point
      3. Summary
    13. 6. Accessing the GPIO Pins
      1. Digital electronics
      2. The GPIO library
        1. Single LED output
        2. PWM output
        3. Multiple outputs
        4. Basic switch
        5. Switch using interrupt
      3. Universal Asynchronous Receiver/Transmitter (UART)
        1. Setting up the serial port
        2. Using pySerial
      4. Additional libraries
      5. Summary
    14. 7. Using the Camera Module
      1. Setting up the camera module
      2. Installing and testing the Python library
      3. Writing applications for the camera
        1. A time lapse recorder
        2. A point-and-shoot camera
        3. An image effect randomizer
      4. Summary
    15. 8. Extracting Data from the Internet
      1. Using urllib2 to download data
      2. Parsing JSON APIs
      3. Parsing XML APIs
        1. The DOM method
        2. The SAX method
      4. Parsing a web page using BeautifulSoup
      5. Summary
    16. 9. Creating Command-line Interfaces
      1. Unit conversion application
      2. Command-line interface
      3. Summary
    17. 10. Debugging Applications with PDB and Log Files
      1. The Python debugger
      2. Writing log files
      3. Unit testing
      4. Summary
    18. 11. Designing Your GUI with Qt
      1. Setting up the codebase
      2. Building the UI with Qt Designer
      3. Writing the UI code
      4. Launching the UI
      5. Packaging the code
      6. Summary
    19. Index