You are previewing Raspberry Pi Cookbook for Python Programmers.
O'Reilly logo
Raspberry Pi Cookbook for Python Programmers

Book Description

Over 50 easy-to-comprehend tailor-made recipes to get the most out of the Raspberry Pi and unleash its huge potential using Python

  • Install your first operating system, share files over the network, and run programs remotely

  • Unleash the hidden potential of the Raspberry Pi’s powerful Video Core IV graphics processor with your own hardware accelerated 3D graphics

  • Discover how to create your own electronic circuits to interact with the Raspberry Pi

  • Interface with purpose-built add-ons and adapt off-the-shelf household devices

  • In Detail

    The Raspberry Pi foundation has been selling their computers since 2012 with the aim of inspiring programmers and engineers.

    Raspberry Pi Cookbook for Python Programmers is a practical guide for getting the most out of this little computer. It will guide you through the many uses of the Raspberry Pi and allow you to showcase the best it has to offer. Discover what the Raspberry Pi has to offer using detailed Python 3 examples that you can adapt and extend; see where your creativity takes you!

    "Raspberry Pi Cookbook for Python Programmers" begins by guiding you through setting up the Raspberry Pi, performing tasks using Python 3 and introduces the first steps to interface with electronics. As you work through each chapter you will build up your skills and knowledge and apply them as you progress throughout the book, delving further and further into the unique abilities and features of the Raspberry Pi.

    Later, you will learn how to automate tasks by accessing files, build applications using the popular Tkinter library and create games by controlling graphics on screen. You will harness the power of the built-in graphics processor by using Pi3D to generate your own high quality 3D graphics and environments. Connect directly to the Raspberry Pi’s hardware pins to control electronics from switching on LEDs and responding to push buttons right through to driving motors and servos. Learn how to monitor sensors to gather real-life data and use it to control other devices, and view the results over the Internet. Apply what you have learnt by creating your own Pi-Rover or Pi-Hexipod robots. Finally, we will explore using many of the purpose-built add-ons available for the Raspberry Pi, as well as interfacing with common household devices in new ways.

    The "Raspberry Pi Cookbook for Python Programmers" will allow you to discover the vast range of abilities this micro-computer has. By following the clear examples you can pick up many new skills and arm yourself with the tools to create your own exciting and interesting projects.

    Table of Contents

    1. Raspberry Pi Cookbook for Python Programmers
      1. Table of Contents
      2. Raspberry Pi Cookbook for Python Programmers
      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. Safety and using electronics
        5. Conventions
        6. Reader feedback
        7. Customer support
          1. Downloading the example code
          2. Downloading the color images of this book
          3. Errata
          4. Piracy
          5. Questions
      8. 1. Getting Started with a Raspberry Pi Computer
        1. Introduction
          1. Introducing the Raspberry Pi
          2. What is with the name?
          3. Why Python?
          4. Python 2 and Python 3
          5. Which version of Python should you use?
        2. Connecting the Raspberry Pi
          1. Getting ready
          2. How to do it…
          3. There's more…
            1. Secondary hardware connections
        3. Using NOOBS to set up your Raspberry Pi SD card
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
            1. Changing the default user password
            2. Ensuring that you shut down safely
            3. Preparing an SD card manually
            4. Expanding the system to fit in your SD card
            5. Accessing the Data/RECOVERY/BOOT partition
            6. Using the tools to backup your SD card in case of failure
        4. Networking and connecting your Raspberry Pi to the Internet via the LAN connector
          1. Getting ready
          2. How to do it…
          3. There's more…
        5. Configuring your network manually
          1. Getting ready
          2. How to do it…
          3. There's more…
        6. Networking directly to a laptop or computer
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
            1. Direct network link
          5. See also
        7. Networking and connecting your Raspberry Pi to the Internet via a USB Wi-Fi dongle
          1. Getting ready
          2. How to do it…
          3. There's more…
            1. Using USB wired network adapters
        8. Connecting to the Internet through a proxy server
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        9. Connecting remotely to the Raspberry Pi over the network using VNC
          1. Getting ready
          2. How to do it…
          3. There's more…
        10. Connecting remotely to the Raspberry Pi over the network using SSH (and X11 Forwarding)
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
            1. Running multiple programs with X11 Forwarding
            2. Running as a desktop with X11 Forwarding
            3. Running PyGame and Tkinter with X11 Forwarding
        11. Sharing the home folder of the Raspberry Pi with SMB
          1. Getting ready
          2. How to do it…
        12. Keeping the Raspberry Pi up to date
          1. Getting ready
          2. How to do it…
      9. 2. Starting with Python Strings, Files, and Menus
        1. Introduction
        2. Working with text and strings
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        3. Using files and handling errors
          1. Getting ready
          2. How to do it…
          3. How it works…
        4. Creating a boot-up menu
          1. How to do it…
          2. How it works…
          3. There's more…
        5. Creating a self-defining menu
          1. How to do it…
          2. How it works…
          3. There's more…
            1. Alternative script locations
            2. Adding scripts to PATH
      10. 3. Using Python for Automation and Productivity
        1. Introduction
        2. Using Tkinter to create graphical user interfaces
          1. Getting ready
          2. How to do it…
          3. How it works…
        3. Creating a graphical application Start menu
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        4. Displaying photo information in an application
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
        5. Organizing your photos automatically
          1. Getting ready
          2. How to do it…
          3. How it works…
      11. 4. Creating Games and Graphics
        1. Introduction
        2. Using IDLE3 to debug your programs
          1. How to do it…
          2. How it works…
        3. Drawing lines using a mouse on Tkinter Canvas
          1. Getting ready
          2. How to do it…
          3. How it works…
        4. Creating a bat and ball game
          1. Getting ready
          2. How to do it…
          3. How it works…
        5. Creating an overhead scrolling game
          1. Getting ready
          2. How to do it…
          3. How it works…
      12. 5. Creating 3D Graphics
        1. Introduction
        2. Starting with 3D coordinates and vertices
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
            1. Camera
            2. Shaders
            3. Lights
            4. Textures
        3. Creating and importing 3D models
          1. Getting ready
          2. How to do it…
          3. How it works...
          4. There's more…
            1. Creating or loading your own objects
            2. Changing the object's textures and .mtl files
            3. Taking screenshots
        4. Creating a 3D world to roam in
          1. Getting ready
          2. How to do it…
          3. How it works…
        5. Building 3D maps and mazes
          1. Getting ready
          2. How to do it…
          3. How it works...
          4. There's more...
            1. The Building module
            2. Using SolidObjects to detect collisions
      13. 6. Using Python to Drive Hardware
        1. Introduction
        2. Controlling an LED
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
            1. Controlling the GPIO current
        3. Responding to a button
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
            1. Safe voltages
            2. Pull-up and pull-down resistor circuits
            3. Protection resistors
        4. A controlled shutdown button
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
            1. Resetting and rebooting Raspberry Pi
            2. Adding extra functions
            3. Relocating to the P5 header
        5. The GPIO keypad input
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
            1. Generating other key combinations
            2. Emulating mouse events
        6. Multiplexed color LEDs
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
            1. Hardware multiplexing
            2. Displaying random patterns
            3. Mixing multiple colors
      14. 7. Sense and Display Real-world Data
        1. Introduction
        2. Using devices with the I2C bus
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Using multiple I2C devices
            2. I2C bus and level shifting
            3. Using just the PCF8591 chip or adding alternative sensors
        3. Reading analog data using an analog-to-digital converter
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Gathering analog data without hardware
        4. Logging and plotting data
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Plotting live data
            2. Scaling and calibrating data
        5. Extending the Raspberry Pi GPIO with an I/O expander
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more…
            1. I/O expander voltages and limits
            2. Using your own I/O expander module
            3. Directly controlling an LCD alphanumeric display
        6. Sensing and sending data to online services
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
      15. 8. Creating Projects with the Raspberry Pi Camera Module
        1. Introduction
        2. Getting started with the Raspberry Pi camera module
          1. Getting ready
          2. How to do it…
          3. How it works…
        3. Using the camera with Python
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
            1. Class member and static functions
            2. Using a USB webcam instead
            3. Additional drivers for the Raspberry Pi camera
          5. See also
        4. Generating a time-lapse video
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
            1. Class inheritance and function overriding
            2. Disabling the camera LED
            3. Pi NoIR – taking night shots
        5. Creating a stop frame animation
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
            1. Improving the focus
            2. Creating a hardware shutter
        6. Making a QR code reader
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
            1. Generating QR codes
          5. See also
      16. 9. Building Robots
        1. Introduction
        2. Building a Rover-Pi robot with forward driving motors
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
            1. Darlington array circuits
            2. Transistor and relay circuits
            3. Tethered or untethered robots
            4. Rover kits
        3. Using advanced motor control
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
            1. Motor speed control using PWM control
            2. Using I/O expanders
        4. Building a six-legged Pi-Bug robot
          1. Getting ready
          2. How to do it…
          3. How it works…
            1. Controlling the servos
            2. The servo class
            3. Learning to walk
            4. The Pi-Bug code for walking
        5. Avoiding objects and obstacles
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
            1. Ultrasonic reversing sensors
        6. Getting a sense of direction
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
            1. Calibrating the compass
            2. Calculating the compass bearing
            3. Saving the calibration
            4. Driving the robot using the compass
      17. 10. Interfacing with Technology
        1. Introduction
        2. Automating your home with remote sockets
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Sending RF control signals directly
        3. Using SPI to control an LED matrix
          1. Getting ready
          2. How to do it…
          3. How it works...
          4. There's more...
            1. Daisy-chain SPI configuration
        4. Communicating using a serial interface
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Configuring a USB to RS232 device for the Raspberry Pi
            2. RS232 signals and connections
            3. Using the GPIO built-in serial pins
            4. The RS232 loopback
        5. Controlling the Raspberry Pi over Bluetooth
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Configuring Bluetooth module settings
        6. Controlling USB devices
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Controlling similar missile-type devices
            2. Robot arm
            3. Taking USB control further
      18. A. Hardware and Software List
        1. Introduction
        2. General component sources
        3. Hardware list
        4. Software list
          1. PC software utilities
          2. Raspberry Pi packages
          3. There's more...
            1. APT commands
            2. Pip Python package manager commands
      19. Index