1. Introducing the Raspberry Pi
So youve got yourself a Raspberry Pi mini computer. Now what? Perhaps youre familiar with the Pi and its architecture, but youre wondering what to do with it. Perhaps you have some experience with computers but arent familiar with Linux or Raspbian, the Pis default operating system. Perhaps youre already a Linux geek, but you dont know how to program in Python and thought it would be a good time to learn. Perhaps you have absolutely no experience with computers beyond clicking the Start button, checking your email, and surfing the web, but you heard about this Raspberry Pie thingamabob and decided to see what all the ruckus was about.
Whatever the case may be, welcome! Youre about to join a clubnot a particularly exclusive one, Im afraid, since all it takes to join is about $35 US plus shippingbut a club nonetheless. As a member, youll be able to discuss package managers , ARM11 processors , and dot config files intelligently with anyone who will listen. Youll know about drivers and APIs. Youll become familiar with servos, LEDs, and cameras-on-a-chip. And, perhaps most importantly, youll be able to connect to your new mini computer, program it in one of many different programming languages (though this book deals exclusively with Python), build projects, and interface those projects with the Pi, enabling it to interact with the physical world and do some very cool things.
With this book, I hereby induct you into this club. Your experience doesnt matter because Ill take you step by step through the process of setting up your Pi so that you can work with it with a minimum of headaches. Ill try to give you a solid background in Linux so that you understand whats going on behind the scenes, and Ill devote a long chapter on introducing you to Python, the scripting language that all the fashionable geeks are scripting in. Google uses it, NASA uses it, and the Book of Faces uses it. Lets face it, Perl is so yesterday. I will also devote a chapter introducing you to the nuts and bolts of building electronics projectssomething many technical and programming books either gloss over or neglect completely. There are safety factors to consider (I very nearly had a small explosion when I shorted out a battery pack, for instance) as well as just good building practice. For example, youll learn how to make a good solder joint and how to avoid slicing your index finger off with an X-ACTO knife, as well as the difference between a 40 and a 40K resistor.
Of course, if youre already familiar with all those things, feel free to skip ahead to the good stuff: the projects. All of them can be constructed in a weekend or so (or a month or two, depending on your motivation level and length of your honey-do list), and all are programmed in Python. Ill give you a shopping list of parts at the beginning of each project, with places to get the parts, and then well dive right in. They dont necessarily build on each other, nor are they in any particular order of complexity; if you want to build the Cat Entertainer and skip the Home Media Server, its perfectly all right.
What kind of projects can you do with a Pi? Youd be surprised: the Pis small size belies its impressive computing power. It has been used for everything from web servers to car computers ( carputers ) to cluster computing, when hooked up in large groups. I hope that after you finish this book youll have not only some more ideas, but the skills necessary to put those ideas into practice.
Whatever your reason for picking up this book, your main objective should be to have fun and learn something! Ill do what I can to lead the way.
The History of Raspberry Pi
It may seem to the casual observer that the Raspberry Pi is very new; many blog posts still treat it that way, and theres a surprisingly huge number of people who have no idea what it is. A good number of online articles still begin with something along the lines of, The Raspberry Pi is a small, credit-card-sized computer that hobbyists have begun using for.... This is in stark contrast to, say, the Arduino; most people up on current events have at least heard of the Arduino, even if they have no idea what it is or what its used for, because it has been around since 2005 and has gained a loyaland vocalfollowing among hobbyists, geeks, and do-it-yourselfers worldwide.
THE ARDUINO
For those who dont know, the Arduino is a microcontroller platform, mounted on a board that plugs easily into most computers. It allows the user to program the onboard Atmega chip to do various things using a C-like programming language, in programs called sketches . A typical Arduino sketch might look like this:
#include
void setup()
{
myservo.attach(9)
}
void loop()
{
myservo.write(95);
delay(100);
myservo.write(150);
delay(100);
}
This repeatedly moves a connected servomotor (a small motor that can be precisely controlled via software) back and forth, with one-second delays.
Although not as powerful as the Pi, the Arduino has done a lot to make electronics projects in general (and microcontrollers specifically) more accessible to the general public. I talk about how the Arduino and the Raspberry Pi complement each other well in .
The Raspberry Pi, while not brand new, has been around for a few years. Its creatorsEben Upton, Rob Mullins, Jack Lang, and Alan Mycroftfirst floated the idea of a cheap PC in 2006. Based at the University of Cambridge in the United Kingdom, they were concerned that the demise of cheap personal computers like the Commodore 64, the Amiga, and the Spectrum were adversely affecting young peoples ability to program. With desktop and laptop computers costing hundredsif not thousandsof dollars, kids and teenagers were forbidden from practicing programming on the familys main machine.
At the same time, the creators realized that many university computer science curricula had been reduced to Microsoft Word 101 and How to create a web page. The four creators wanted to raise the programming knowledge bar of incoming students, and thus perhaps computer science and engineering courses would become a bit more robust.
Obviously, a cheaper computer was necessary. They played around with microcontrollers and various chips, breadboards, and PCBs, but it wasnt until 2008 that the idea became more feasible. Chips were becoming smaller, cheaper, and more powerful thanks to the explosion in mobile devices. These chips enabled them to plan a device that would be capable of supporting multimedia, not just command-line programming, which they felt was important. (See Figure .) Young people were more likely to be interested in a media-capable device, and thus more likely to try programming on one.