Home Page Icon
Home Page
Table of Contents for
Table of Contents
Close
Table of Contents
by Tim Cox
Raspberry Pi for Python Programmers Cookbook - Second Edition
Raspberry Pi for Python Programmers Cookbook - Second Edition
Table of Contents
Raspberry Pi for Python Programmers Cookbook - Second Edition
Credits
About the Author
About the Reviewer
www.PacktPub.com
eBooks, discount offers, and more
Why Subscribe?
Preface
What this book covers
What you need for this book
Who this book is for
Safety and using electronics
Sections
Getting ready
How to do it…
How it works…
There's more…
See also
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Getting Started with a Raspberry Pi Computer
Introduction
Introducing the Raspberry Pi
What is with the name?
Why Python?
Python 2 and Python 3
Which version of Python should you use?
The Raspberry Pi family – a brief history of Pi
Which Pi to choose?
Connecting the Raspberry Pi
Getting ready
How to do it…
There's more…
Secondary hardware connections
Using NOOBS to set up your Raspberry Pi SD card
Getting ready
How to do it…
How it works…
There's more…
Changing the default user password
Ensuring that you shut down safely
Preparing an SD card manually
Expanding the system to fit in your SD card
Accessing the RECOVERY/BOOT partition
Using the tools to back up your SD card in case of failure
Networking and connecting your Raspberry Pi to the Internet via the LAN connector
Getting ready
How to do it…
There's more…
Using built-in Wi-Fi and Bluetooth on the Raspberry Pi
Getting ready
How to do it…
Connecting to your Wi-Fi network
Connecting to Bluetooth devices
Configuring your network manually
Getting ready
How to do it…
There's more…
Networking directly to a laptop or computer
Getting ready
How to do it…
How it works…
There's more…
Direct network link
See also
Networking and connecting your Raspberry Pi to the Internet via a USB Wi-Fi dongle
Getting ready
How to do it…
There's more…
Using USB wired network adapters
Connecting to the Internet through a proxy server
Getting ready
How to do it…
How it works…
There's more…
Connecting remotely to the Raspberry Pi over the network using VNC
Getting ready
How to do it…
There's more…
Connecting remotely to the Raspberry Pi over the network using SSH (and X11 Forwarding)
Getting ready
How to do it…
How it works…
There's more…
Running multiple programs with X11 Forwarding
Running as a desktop with X11 Forwarding
Running PyGame and Tkinter with X11 Forwarding
Sharing the home folder of the Raspberry Pi with SMB
Getting ready
How to do it…
Keeping the Raspberry Pi up to date
Getting ready
How to do it…
There's more…
2. Starting with Python Strings, Files, and Menus
Introduction
Working with text and strings
Getting ready
How to do it…
How it works…
There's more…
Using files and handling errors
Getting ready
How to do it…
How it works…
Creating a boot-up menu
How to do it…
How it works…
There's more…
Creating a self-defining menu
How to do it…
How it works…
There's more…
Alternative script locations
Adding scripts to PATH
3. Using Python for Automation and Productivity
Introduction
Using Tkinter to create graphical user interfaces
Getting ready
How to do it…
How it works…
Creating a graphical application – Start menu
Getting ready
How to do it…
How it works…
There's more…
Displaying photo information in an application
Getting ready
How to do it…
How it works…
There's more…
Organizing your photos automatically
Getting ready
How to do it…
How it works…
4. Creating Games and Graphics
Introduction
Using IDLE3 to debug your programs
How to do it…
How it works…
Drawing lines using a mouse on Tkinter Canvas
Getting ready
How to do it…
How it works…
Creating a bat and ball game
Getting ready
How to do it…
How it works…
Creating an overhead scrolling game
Getting ready
How to do it…
How it works…
5. Creating 3D Graphics
Introduction
Starting with 3D coordinates and vertices
Getting ready
How to do it…
How it works…
There's more…
Camera
Shaders
Lights
Textures
Creating and importing 3D models
Getting ready
How to do it…
How it works...
There's more…
Creating or loading your own objects
Changing the object's textures and .mtl files
Taking screenshots
Creating a 3D world to roam in
Getting ready
How to do it…
How it works…
Building 3D maps and mazes
Getting ready
How to do it…
How it works...
There's more...
The Building module
Using SolidObjects to detect collisions
6. Using Python to Drive Hardware
Introduction
Controlling an LED
Getting ready
How to do it…
How it works…
There's more…
Controlling the GPIO current
Responding to a button
Getting ready
How to do it…
How it works…
There's more…
Safe voltages
Pull-up and pull-down resistor circuits
Protection resistors
A controlled shutdown button
Getting ready
How to do it…
How it works…
There's more…
Resetting and rebooting Raspberry Pi
Adding extra functions
The GPIO keypad input
Getting ready
How to do it…
How it works…
There's more…
Generating other key combinations
Emulating mouse events
Multiplexed color LEDs
Getting ready
How to do it…
How it works…
There's more…
Hardware multiplexing
Displaying random patterns
Mixing multiple colors
Writing messages using Persistence of Vision
Getting ready
How to do it…
How it works…
7. Sense and Display Real-World Data
Introduction
Using devices with the I2C bus
Getting ready
How to do it...
How it works...
There's more...
Using multiple I2C devices
I2C bus and level shifting
Using just the PCF8591 chip or adding alternative sensors
Reading analog data using an analog-to-digital converter
Getting ready
How to do it...
How it works...
There's more...
Gathering analog data without hardware
Logging and plotting data
Getting ready
How to do it...
How it works...
There's more...
Plotting live data
Scaling and calibrating data
Extending the Raspberry Pi GPIO with an I/O expander
Getting ready
How to do it...
How it works...
There's more…
I/O expander voltages and limits
Using your own I/O expander module
Directly controlling an LCD alphanumeric display
Capturing data in an SQLite database
Getting ready
How to do it...
How it works...
There's more…
CREATE
INSERT
SELECT
WHERE
UPDATE
DELETE
DROP
Viewing data from your own webserver
Getting ready
How to do it...
How it works...
There's more…
Security
Using MySQL instead
Sensing and sending data to online services
Getting ready
How to do it...
How it works...
See also
8. Creating Projects with the Raspberry Pi Camera Module
Introduction
Getting started with the Raspberry Pi camera module
Getting ready
How to do it…
How it works…
Using the camera with Python
Getting ready
How to do it…
How it works…
There's more…
Class member and static functions
Using a USB webcam instead
Additional drivers for the Raspberry Pi camera
See also
Generating a time-lapse video
Getting ready
How to do it…
How it works…
There's more…
Class inheritance and function overriding
Disabling the camera LED
Pi NoIR – taking night shots
Creating a stop frame animation
Getting ready
How to do it…
How it works…
There's more…
Improving the focus
Creating a hardware shutter
Making a QR code reader
Getting ready
How to do it…
How it works…
There's more…
Generating QR codes
See also
Discover and experiment with OpenCV
Getting ready
How to do it…
How it works…
Color detection with OpenCV
Getting ready
How to do it…
How it works…
There's more…
Performing motion tracking with OpenCV
Getting ready
How to do it…
How it works…
There's more…
9. Building Robots
Introduction
Building a Rover-Pi robot with forward driving motors
Getting ready
How to do it…
How it works…
There's more…
Darlington array circuits
Transistor and relay circuits
Tethered or untethered robots
Rover kits
Using advanced motor control
Getting ready
How to do it…
How it works…
There's more…
Motor speed control using PWM control
Using I/O expanders
Building a six-legged Pi-Bug robot
Getting ready
How to do it…
How it works…
Controlling the servos
The servo class
Learning to walk
The Pi-Bug code for walking
Controlling servos directly with Servoblaster
Getting ready
How to do it…
How it works…
Using an Infra-Red Remote Control with your Raspberry Pi
Getting Ready
How to do it…
There's more…
Avoiding objects and obstacles
Getting ready
How to do it…
How it works…
There's more…
Ultrasonic reversing sensors
Getting a sense of direction
Getting ready
How to do it…
How it works…
There's more…
Calibrating the compass
Calculating the compass bearing
Saving the calibration
Driving the robot using the compass
10. Interfacing with Technology
Introduction
Automating your home with remote sockets
Getting ready
How to do it...
How it works...
There's more...
Sending RF control signals directly
Extending the range of the RF Transmitter
Determining the structure of the remote control codes
Using SPI to control an LED matrix
Getting ready
How to do it…
How it works...
There's more...
Daisy-chain SPI configuration
Communicating using a serial interface
Getting ready
How to do it...
How it works...
There's more...
Configuring a USB to RS232 device for the Raspberry Pi
RS232 signals and connections
Using the GPIO built-in serial pins
The RS232 loopback
Controlling the Raspberry Pi over Bluetooth
Getting ready
How to do it...
How it works...
There's more...
Configuring Bluetooth module settings
Controlling USB devices
Getting ready
How to do it...
How it works...
There's more...
Controlling similar missile-type devices
Robot arm
Taking USB control further
A. Hardware and Software List
Index
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Prev
Previous Chapter
Cover
Next
Next Chapter
Raspberry Pi for Python Programmers Cookbook - Second Edition
Table of Contents
Raspberry Pi for Python Programmers Cookbook - Second Edition
Credits
About the Author
About the Reviewer
www.PacktPub.com
eBooks, discount offers, and more
Why Subscribe?
Preface
What this book covers
What you need for this book
Who this book is for
Safety and using electronics
Sections
Getting ready
How to do it…
How it works…
There's more…
See also
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Getting Started with a Raspberry Pi Computer
Introduction
Introducing the Raspberry Pi
What is with the name?
Why Python?
Python 2 and Python 3
Which version of Python should you use?
The Raspberry Pi family – a brief history of Pi
Which Pi to choose?
Connecting the Raspberry Pi
Getting ready
How to do it…
There's more…
Secondary hardware connections
Using NOOBS to set up your Raspberry Pi SD card
Getting ready
How to do it…
How it works…
There's more…
Changing the default user password
Ensuring that you shut down safely
Preparing an SD card manually
Expanding the system to fit in your SD card
Accessing the RECOVERY/BOOT partition
Using the tools to back up your SD card in case of failure
Networking and connecting your Raspberry Pi to the Internet via the LAN connector
Getting ready
How to do it…
There's more…
Using built-in Wi-Fi and Bluetooth on the Raspberry Pi
Getting ready
How to do it…
Connecting to your Wi-Fi network
Connecting to Bluetooth devices
Configuring your network manually
Getting ready
How to do it…
There's more…
Networking directly to a laptop or computer
Getting ready
How to do it…
How it works…
There's more…
Direct network link
See also
Networking and connecting your Raspberry Pi to the Internet via a USB Wi-Fi dongle
Getting ready
How to do it…
There's more…
Using USB wired network adapters
Connecting to the Internet through a proxy server
Getting ready
How to do it…
How it works…
There's more…
Connecting remotely to the Raspberry Pi over the network using VNC
Getting ready
How to do it…
There's more…
Connecting remotely to the Raspberry Pi over the network using SSH (and X11 Forwarding)
Getting ready
How to do it…
How it works…
There's more…
Running multiple programs with X11 Forwarding
Running as a desktop with X11 Forwarding
Running PyGame and Tkinter with X11 Forwarding
Sharing the home folder of the Raspberry Pi with SMB
Getting ready
How to do it…
Keeping the Raspberry Pi up to date
Getting ready
How to do it…
There's more…
2. Starting with Python Strings, Files, and Menus
Introduction
Working with text and strings
Getting ready
How to do it…
How it works…
There's more…
Using files and handling errors
Getting ready
How to do it…
How it works…
Creating a boot-up menu
How to do it…
How it works…
There's more…
Creating a self-defining menu
How to do it…
How it works…
There's more…
Alternative script locations
Adding scripts to PATH
3. Using Python for Automation and Productivity
Introduction
Using Tkinter to create graphical user interfaces
Getting ready
How to do it…
How it works…
Creating a graphical application – Start menu
Getting ready
How to do it…
How it works…
There's more…
Displaying photo information in an application
Getting ready
How to do it…
How it works…
There's more…
Organizing your photos automatically
Getting ready
How to do it…
How it works…
4. Creating Games and Graphics
Introduction
Using IDLE3 to debug your programs
How to do it…
How it works…
Drawing lines using a mouse on Tkinter Canvas
Getting ready
How to do it…
How it works…
Creating a bat and ball game
Getting ready
How to do it…
How it works…
Creating an overhead scrolling game
Getting ready
How to do it…
How it works…
5. Creating 3D Graphics
Introduction
Starting with 3D coordinates and vertices
Getting ready
How to do it…
How it works…
There's more…
Camera
Shaders
Lights
Textures
Creating and importing 3D models
Getting ready
How to do it…
How it works...
There's more…
Creating or loading your own objects
Changing the object's textures and .mtl files
Taking screenshots
Creating a 3D world to roam in
Getting ready
How to do it…
How it works…
Building 3D maps and mazes
Getting ready
How to do it…
How it works...
There's more...
The Building module
Using SolidObjects to detect collisions
6. Using Python to Drive Hardware
Introduction
Controlling an LED
Getting ready
How to do it…
How it works…
There's more…
Controlling the GPIO current
Responding to a button
Getting ready
How to do it…
How it works…
There's more…
Safe voltages
Pull-up and pull-down resistor circuits
Protection resistors
A controlled shutdown button
Getting ready
How to do it…
How it works…
There's more…
Resetting and rebooting Raspberry Pi
Adding extra functions
The GPIO keypad input
Getting ready
How to do it…
How it works…
There's more…
Generating other key combinations
Emulating mouse events
Multiplexed color LEDs
Getting ready
How to do it…
How it works…
There's more…
Hardware multiplexing
Displaying random patterns
Mixing multiple colors
Writing messages using Persistence of Vision
Getting ready
How to do it…
How it works…
7. Sense and Display Real-World Data
Introduction
Using devices with the I2C bus
Getting ready
How to do it...
How it works...
There's more...
Using multiple I2C devices
I2C bus and level shifting
Using just the PCF8591 chip or adding alternative sensors
Reading analog data using an analog-to-digital converter
Getting ready
How to do it...
How it works...
There's more...
Gathering analog data without hardware
Logging and plotting data
Getting ready
How to do it...
How it works...
There's more...
Plotting live data
Scaling and calibrating data
Extending the Raspberry Pi GPIO with an I/O expander
Getting ready
How to do it...
How it works...
There's more…
I/O expander voltages and limits
Using your own I/O expander module
Directly controlling an LCD alphanumeric display
Capturing data in an SQLite database
Getting ready
How to do it...
How it works...
There's more…
CREATE
INSERT
SELECT
WHERE
UPDATE
DELETE
DROP
Viewing data from your own webserver
Getting ready
How to do it...
How it works...
There's more…
Security
Using MySQL instead
Sensing and sending data to online services
Getting ready
How to do it...
How it works...
See also
8. Creating Projects with the Raspberry Pi Camera Module
Introduction
Getting started with the Raspberry Pi camera module
Getting ready
How to do it…
How it works…
Using the camera with Python
Getting ready
How to do it…
How it works…
There's more…
Class member and static functions
Using a USB webcam instead
Additional drivers for the Raspberry Pi camera
See also
Generating a time-lapse video
Getting ready
How to do it…
How it works…
There's more…
Class inheritance and function overriding
Disabling the camera LED
Pi NoIR – taking night shots
Creating a stop frame animation
Getting ready
How to do it…
How it works…
There's more…
Improving the focus
Creating a hardware shutter
Making a QR code reader
Getting ready
How to do it…
How it works…
There's more…
Generating QR codes
See also
Discover and experiment with OpenCV
Getting ready
How to do it…
How it works…
Color detection with OpenCV
Getting ready
How to do it…
How it works…
There's more…
Performing motion tracking with OpenCV
Getting ready
How to do it…
How it works…
There's more…
9. Building Robots
Introduction
Building a Rover-Pi robot with forward driving motors
Getting ready
How to do it…
How it works…
There's more…
Darlington array circuits
Transistor and relay circuits
Tethered or untethered robots
Rover kits
Using advanced motor control
Getting ready
How to do it…
How it works…
There's more…
Motor speed control using PWM control
Using I/O expanders
Building a six-legged Pi-Bug robot
Getting ready
How to do it…
How it works…
Controlling the servos
The servo class
Learning to walk
The Pi-Bug code for walking
Controlling servos directly with Servoblaster
Getting ready
How to do it…
How it works…
Using an Infra-Red Remote Control with your Raspberry Pi
Getting Ready
How to do it…
There's more…
Avoiding objects and obstacles
Getting ready
How to do it…
How it works…
There's more…
Ultrasonic reversing sensors
Getting a sense of direction
Getting ready
How to do it…
How it works…
There's more…
Calibrating the compass
Calculating the compass bearing
Saving the calibration
Driving the robot using the compass
10. Interfacing with Technology
Introduction
Automating your home with remote sockets
Getting ready
How to do it...
How it works...
There's more...
Sending RF control signals directly
Extending the range of the RF Transmitter
Determining the structure of the remote control codes
Using SPI to control an LED matrix
Getting ready
How to do it…
How it works...
There's more...
Daisy-chain SPI configuration
Communicating using a serial interface
Getting ready
How to do it...
How it works...
There's more...
Configuring a USB to RS232 device for the Raspberry Pi
RS232 signals and connections
Using the GPIO built-in serial pins
The RS232 loopback
Controlling the Raspberry Pi over Bluetooth
Getting ready
How to do it...
How it works...
There's more...
Configuring Bluetooth module settings
Controlling USB devices
Getting ready
How to do it...
How it works...
There's more...
Controlling similar missile-type devices
Robot arm
Taking USB control further
A. Hardware and Software List
Index
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset