E-Book description:
In 2006, when Eben Upton and the other founders of the Raspberry Pi Foundation looked at the state of Computer Science (CS) programs in universities, they were dismayed. Computer science programs were being reduced to “CS 101: How To Operate Microsoft Word” and “CS 203: Optimize Your Facebook Page.” Nobody, they realized, was learning how to program any more, least of all before they entered college. So they hatched a plan—create a small, cheap computer that kids could learn to program on, like the Amigas, Spectrums, and Commodore 64s of yesteryear. They put an ARM processor on a board, gave it (eventually) 512 MB of RAM and a VideoCore GPU, and allowed users to interface with it using a USB keyboard, mouse, and an HDMI output port. To make it easy to program, they designed it so that its main programming language would be Python—a powerful, easy-to-learn scripting language. And thus the Raspberry Pi was born. I wrote my first program in BASIC on a Commodore VIC 20, lo these many years ago. At 5 KB of RAM, it had less computing power than many of today’s microcontrollers, but I was still able to write a simple maze game on it, saving my progress as I went on a cassette-tape drive. In the years since, I’ve traversed my way through the different computing platforms, from Windows 3.1, to Macintosh OS 8, to a little bit of Linux. It had been a long time since I was truly excited by a computer; the Pi was a breath of fresh air in a somewhat stale computing environment. Not only was it small and cheap, but it was easy to get it to interact with the physical world—a real boon for anybody interested in designing physical systems. So when I heard about its release, I signed up like about a trillion other hobbyists/ hackers/engineers and waited impatiently for mine to be delivered. Then I started building stuff with it and never looked back. If you bought a Pi but aren’t sure how to get started with it, this book is for you. If you bought a Pi but aren’t sure what to do with it, this book is for you. If you’re considering buying a Pi but haven’t yet because you keep thinking, “Why should I? It’s not like I can do anything cool with it, right?”, then this book is definitely for you. This book isn’t meant to be a textbook on Python, nor is it an exhaustive exploration of the Raspberry Pi and everything it can do. But it is meant to be a fun, getting-started guide to this neat little computer. I hope that after you work your way through the book, you’ll get a sense of all the things that are possible with the Pi when you combine it with a little ingenuity and creativity on your part. If you want to work through the projects here in order, feel free. If you’d rather skip around, doing those that interest you, you’re welcome to do that as well. Along the way, I hope you’ll develop a familiarity with both Python
and the Pi that will enable you to continue on, building projects as you go, and perhaps inspiring others along the way. Above all, I hope you enjoy the book and its projects. It was truly a blast to write. Happy computing!
[quote font=”helvetica” font_size=”18″] Here is another example of how to write a sudoku game gui in python[/quote]
E-Book Author:
Wolfram Donat
E-Book Table of Contents:
About the Author……xv
About the Technical Reviewer……xvii
Acknowledgments……xix
Introduction……xxi
Chapter 1: Introducing the Raspberry Pi……1
The History of Raspberry Pi……2
Exploring the Pi Board……4
The SD Card……5
The Power Port……5
The HDMI Port……5
The Ethernet and USB Ports……6
The Audio and RCA Video Jacks……6
The GPIO Pins……6
The System on a Chip……6
Comparing Raspberry Pi to Similar Devices ……7
Hardware Requirements of the Pi……7
Connecting to Power……7
Adding a Monitor……7
Adding a USB Hub……7
Using a Wireless USB Dongle……8
The Pi Operating System…………9
Formatting the Card……10
Using NOOBS……10
Connecting the Peripherals……10
Configuring the Pi……11
Shutting Down the Pi……13
Summary……13
Chapter 2: Linux by the Seat of Your Pants……5
Getting Started with Linux on the Pi……16
Linux Files and the File System……17
Root User vs sudo……17
Commands……18
Exercise: Navigating in the Linux File System……21
Shells in Linux ……22
Package Managers……23
Text Editors……24
Vim vs emacs vs nano……25
Summary……29
Chapter 3: Introducing Python……30
Scripting vs a Programming Language…………31
The Python Philosophy……33
Getting Started with Python……34
Running Python Using IDLE……34
Running Python Using the Terminal……37
Running Python Using Scripts……38
Exploring Python’s Data Types……39
Programming with Python……44
IF tests……45
Loops……46
Functions……48
Objects and Object-Oriented Programming……49
Summary……50
Chapter 4: Electronics at 100 MPH………1
Basic Electricity Concepts……52
Required Tools for Robotics……54
Screwdrivers…………54
Pliers and Wire Strippers……54
Wire Cutters…………55
Files……56
Magnifying Light……56
Hot Glue Gun……….57
Assorted Glues……57
Multimeter…………57
Power Supplies……58
Breadboard…………59
Power Strip……61
Soldering Iron……61
General Safety Rules……62
Working with Heat……62
Working With Sharp Objects……63
Wear Safety Glasses……63
Fire Extinguishers at the Ready……63
Keep a First-Aid Kit Handy……63
Work in a Ventilated Area ……64
Organizing Your Workplace……64
Bonus: Soldering Techniques……65
Summary……66
Chapter 5: The Web Bot……67
Bot Etiquette……68
The Connections of the Web……69
Web Communication Protocols……69
Web Page Formats……69
A Request Example……70
Our Web Bot Concept……70
Parsing Web Pages……71
Coding with Python Modules……72
Using the Mechanize Module……72
Parsing with Beautiful Soup……73
Downloading with the urllib Library……73
Deciding What to Download……73
Choosing a Starting Point……74
Storing Your Files……74
Writing the Python Bot……74
Reading a String and Extracting All the Links……75
Looking For and Downloading Files ……75
Testing the Bot…………76
Creating Directories and Instantiating a List……77
The Final Code……79
Summary……80
Chapter 6: The Weather Station………..1
A Shopping List of Parts……82
Using the I2C Protocol……82
Using an Anemometer……84
Building the Anemometer……84
Connecting the Anemometer to the Pi ……87
Correlating Revolutions per Second with Wind Speed……88
Connecting the Digital Compass……90
Connecting the Temperature/Humidity Sensor……92
Connecting the Barometer……93
Connecting the Bits ……95
The Final Code……97
Summary……100
Chapter 7: The Media Server……101
A Shopping List of Parts ……101
Using an NTFS Drive……101
Installing Samba……104
Configuring Samba……104
Setting Linux Permissions……106
Fixing the Apostrophe Bug……107
Restarting the Samba Service……107
Connecting with Linux/OS X……108
Where’s Python?……110
Summary……110
Chapter 8: The Home Security System………..1
Dogs as Security……111
Raspberry Pi as Security……112
Using a Sensor Network……112
Understanding a Pulldown Resistor……112
A Shopping List of Parts……113
Connecting to Your Network Wirelessly……113
Accessing the GPIO Pins……116
Setting Up the Motion Sensor……118
Setting Up the Reed Switch……120
Setting Up the Pressure Switch ……121
Connecting the Magnetic Sensor……122
Setting Up Pi’s Camera……123
Sending a Text Message from the Pi……123
Implementing the Callback……124
Connecting All of the Bits……124
The Final Code……125
Summary……126
Chapter 9: The Cat Toy ……127
A Shopping List of Parts……127
The Concept Behind the Toy……128
Creating and Using Random Numbers……129
Using the GPIO Library…………130
Controlling the Servo ……132
Constructing the Servo Mechanism……134
Constructing the Laser Mechanism ……135
Connecting the Laser to the Servo……136
Connecting the Motion Sensor……137
Connecting All the Bits……140
The Final Code ……142
Summary ……143
Chapter 10: The Radio-Controlled Airplane…………45
A Shopping List of Parts……145
Connecting the GPS Receiver to the Pi……146
Setting Up a Log File……148
Formatting a KML File……149
Using Threading and Objects………………..151
Setting Up Automatic Startup……152
Connecting the Bits……153
The Final Code……157
The Plane Program……158
KML Conversion Program ……159
Summary ……159
Chapter 11: The Weather Balloon………161
A Shopping List of Parts ……161
Setting Up the GPS Receiver……162
Storing the GPS Data……164
Installing PiFM……164
Installing festival……165
Installing FFMPEG……165
Preparing the Pi……166
Using Threading and Objects…….167
Connecting the Bits……167
Reviewing the Photo Results……170
The Final Code……171
Summary……172
Chapter 12: The Submersible…………173
A Shopping List of Parts……174
Accessing the Raspberry Pi’s GPIO pins……174
Installing the Raspberry Pi Camera Board……176
Controlling the Sub ……178
Attaching the Wiichuck Adapter……179
Activating the Pi’s I2C ……180
Testing the Nunchuk……181
Reading from the Nunchuk……182
Controlling the Sub Motors and Camera with the Nunchuk……185
Starting the Program Remotely ……187
The Final Control Program……189
The Final Code……189
Constructing the Sub……191
Building the Frame ……192
Creating the Pi’s Enclosure……192
Waterproofing the Motor Enclosures……193
Connecting the Nunchuck……196
Assembling the Final Product……196
Summary……200
Chapter 13: The Gertboard ……201
Examining the Board……201
The GPIO Pins…………202
Atmega Chip…………203
A-to-D and D-to-A Converters ……204
I/O Section…………205
The Motor Controller……206
Open Collector Driver……207
Jumpers……..208
Some Example Projects…….209
Configuring the Preliminary Jumper Setup ……209
Making Some LEDs Blink……210
Experimenting with Motor Controllers……212
Using the Open Collector Drivers……213
Using the Digital/Analogue Converters……213
Summary……214
Chapter 14: The Raspberry Pi and the Arduino…………215
Exploring the Arduino……215
Installing the Arduino IDE on the Pi……218
Running a Servo……223
The Arduino and the Gertboard ……224
Summary ……225
Index……227