Introduction | p. 1 |
What Is Programming? | p. 1 |
Why the Raspberry Pi? | p. 2 |
How Does this Book Work? | p. 2 |
Getting Up and Running | p. 5 |
Setting Up Your Raspberry Pi | p. 5 |
Solving Problems | p. 6 |
A Quick Tour of Raspbian | p. 7 |
Using LXDE (Lightweight X11 Desktop Environment) | p. 7 |
Using the Terminal | p. 8 |
Changing Configurations with Raspi-Config | p. 10 |
Installing Software | p. 10 |
Python 3 | p. 11 |
The Python Interpreter | p. 11 |
Running Python Programs | p. 11 |
Summary | p. 12 |
A Really Quick Introduction to Python | p. 13 |
Drawing Picture with Turtles | p. 13 |
Using Loops | p. 16 |
Conditionals: if, elif, and else | p. 18 |
Using Functions and Methods to Structure Code | p. 20 |
A Python Game of Cat and Mouse | p. 21 |
Understanding Variables | p. 24 |
Defining Functions | p. 24 |
Looping Through the Game | p. 25 |
Summary | p. 26 |
Python Busies | p. 27 |
Variables, Values, and Types | p. 27 |
Values Have Types | p. 28 |
Storing Numbers | p. 29 |
Keeping Text in Strings | p. 30 |
Boolean: True or False | p. 31 |
Converting Between Data Types | p. 32 |
Test Your Knowledge | p. 32 |
| p. 33 |
Storing Values in Structures | p. 33 |
Non-Sequential Values in Dictionaries and Sets | p. 37 |
Test Your Knowledge | p. 38 |
Controlling the Way the Program Flows | p. 38 |
Moving Through Data with for Loops | p. 39 |
Going Deeper with Nested Loops | p. 40 |
Branching Execution with if Statements | p. 41 |
Catching Exceptions | p. 42 |
| p. 43 |
Making Code Reusable with Functions | p. 43 |
Optional Parameters | p. 46 |
Bringing Everything Together | p. 46 |
| p. 48 |
Building Objects with Classes | p. 49 |
Getting Extra Features from Modules | p. 54 |
Summary | p. 55 |
Solutions to Exercises | p. 56 |
Exercise 1 | p. 56 |
Exercise 2 | p. 56 |
Exercise 3 | p. 56 |
Graphical Programming | p. 57 |
Graphical User Interface (GUI) Programming | p. 58 |
Adding Controls | p. 60 |
Test Your Knowledge | p. 62 |
| p. 62 |
Creating a Web Browser | p. 62 |
Adding Window Menus | p. 71 |
Test Your Knowledge | p. 73 |
| p. 73 |
Summary | p. 74 |
Solutions to Exercises | p. 74 |
| p. 74 |
| p. 76 |
Creating Gaines | p. 77 |
Building a Game | p. 79 |
Initialising PyGame | p. 82 |
Creating a World | p. 86 |
Detecting Collisions | p. 88 |
Moving Left and Right | p. 90 |
Reaching the Goal | p. 92 |
Making a Challenge | p. 93 |
Making It Your Own | p. 97 |
Adding Sound | p. 98 |
Adding Scenery | p. 99 |
Adding the Finishing Touches | p. 101 |
Taking the Game to the Next Level | p. 102 |
Realistic Game Physics | p. 103 |
Summary | p. 108 |
Creating Graphics with OpenGL | p. 109 |
Getting Modules | p. 110 |
Creating a Spinning Cube | p. 110 |
Vectors and Matrices | p. 112 |
Bringing It All Together | p. 116 |
Let There Be Light | p. 120 |
Calculating the Distance of the Point from the Light Source | p. 120 |
Calculating Reflecting Angles | p. 121 |
Making the Screen Dance | p. 126 |
Building the 3D Model | p. 128 |
Calculating the Sound Level | p. 129 |
Taking Things Further | p. 135 |
Adding Some Texture | p. 136 |
Summary | p. 136 |
Networked Python | p. 139 |
Understanding Hosts, Ports, and Sockets | p. 139 |
Locating Computers with IP Addresses | p. 140 |
Building a Chat Server | p. 141 |
Tweeting to the World | p. 144 |
Weather Forecasts with JSON | p. 147 |
Testing Your Knowledge | p. 149 |
Exercise 1 | p. 149 |
Getting On the Web | p. 149 |
Making Your Website Dynamic | p. 151 |
Using Templates | p. 153 |
Sending Data Back with Forms | p. 153 |
Exercise 2 | p. 155 |
Keeping Things Secure | p. 155 |
Summary | p. 159 |
Solutions to Exercises | p. 160 |
Exercise 1 | p. 160 |
Exercise 2 | p. 161 |
Minecraft | p. 163 |
Exploring Minecraft | p. 164 |
Controlling Your Minecraft World | p. 164 |
Creating Minecraft Worlds in Python | p. 165 |
Building Worlds | p. 166 |
Drawing Pictures | p. 166 |
Taking Things Further | p. 169 |
Making the Game Snake | p. 169 |
Moving the Snake | p. 173 |
Growing the Snake | p. 173 |
Adding the Apples | p. 174 |
Taking Things Further | p. 175 |
Summary | p. 175 |
Multimedia | p. 177 |
Using PyAudio to Get Sound into Your Computer | p. 177 |
Recording the Sound | p. 179 |
Speaking to Your Pi | p. 180 |
Asking the Program Questions | p. 181 |
Putting It All Together | p. 182 |
Taking Things Further | p. 184 |
Making Movies | p. 184 |
Using USB Webcams | p. 185 |
Adding Computer Vision Features with OpenCV | p. 187 |
Taking Things Further | p. 190 |
Using the Raspberry Pi Camera Module | p. 190 |
Creating Live Streams | p. 193 |
Taking Things Further | p. 196 |
Summary | p. 196 |
Scripting | p. 197 |
Getting Started with the Linux Command Line | p. 197 |
Using the Subprocess Module | p. 200 |
Command-Line Flags | p. 202 |
Regular Expressions | p. 203 |
Testing Your Knowledge | p. 206 |
Scripting with Networking | p. 207 |
Bringing It All Together | p. 209 |
Working with Files in Python | p. 216 |
Summary | p. 217 |
Interfacing with Hardware | p. 219 |
Setting Up Your Hardware Options | p. 219 |
Female to Male Jumper Wires | p. 219 |
Pi Cobbler | p. 220 |
Solderless Breadboard | p. 221 |
Stripboards and Prototyping Boards | p. 221 |
PCB Manufacturing | p. 222 |
Getting the Best Tools | p. 222 |
Wire Cutters/Strippers | p. 222 |
Multimeters | p. 222 |
Soldering Irons | p. 222 |
Hardware Needed for this Chapter | p. 223 |
The First Circuit | p. 224 |
Protecting Your Pi | p. 228 |
Power Limits | p. 229 |
Getting Input | p. 229 |
Expanding the GPIO Options with I2C, SP1, and Serial | p. 231 |
The SPI Communications Protocol | p. 231 |
The I2C Communications Protocol | p. 235 |
The Serial Communications Protocol | p. 236 |
Taking the Example Further | p. 236 |
Arduino | p. 236 |
PiFace | p. 237 |
Gertboard | p. 237 |
Wireless Inventor's Kit | p. 238 |
Trying Some Popular Projects | p. 238 |
Robots | p. 238 |
Home Automation | p. 239 |
Burglar Alarms | p. 239 |
Digital Art | p. 239 |
Summary | p. 239 |
Testing and Debugging | p. 241 |
Investigating Bugs by Printing Out the Values | p. 241 |
Finding Bugs by Testing | p. 245 |
Checking Bits of Code with Unit Tests | p. 245 |
Getting More Assertive | p. 250 |
Using Test Suites for Regression Testing | p. 252 |
Testing the Whole Package | p. 253 |
Making Sure Your Software's Usable | p. 254 |
How Much Should You Test? | p. 254 |
Summary | p. 255 |
Index | p. 257 |
Table of Contents provided by Ingram. All Rights Reserved. |