Preface to the Second Edition

Launched in 2011, the Raspberry Pi has found a role both as a very low-cost Linux-based computer and as a platform for embedded computing. It has proven popular with educators and hobbyists alike.

Since the first edition of this book, several million more Raspberry Pis have been sold and a number of new models of Raspberry Pi have been produced. Some models—like the models B+, A+, and Pi 2 model B+—improve the specification of this device, culminating in the Raspberry Pi 2 with quad-core processor and  the Raspberry Pi Compute model, which provide the Raspberry Pi as a plugin board that can become part of a larger system.

This edition has been thoroughly updated to encompass the new models of Raspberry Pi, as well as the many changes and improvements to its Raspbian operating system.

This edition contains a new chapter on computer vision and a chapter of recipes on making Internet of Things projects with your Raspberry Pi.

This book is designed in such a way that you can read it linearly as you would a regular book, or access recipes at random. You can search the table of contents or index for the recipe that you want and then jump right to it. If the recipe requires you to know about other things, it will refer you to other recipes, rather like a cookbook might refer you to base sauces before showing you how to cook something fancier.

The world of Raspberry Pi moves quickly. With a large, active community, new interface boards and software libraries are being developed all the time. In addition to examples that use specific interface boards or software, the book also covers basic principles so that you can have a better understanding of how to use new technologies that come along as the Raspberry Pi ecosystem develops.

As you would expect, a large body of code (mostly Python programs) accompanies the book. These programs are all open source and available on GitHub. You’ll find a link to them at the Raspberry Pi Cookbook website.

For most of the software-based recipes, all you need is a Raspberry Pi. I recommend a Raspberry Pi 2 or 3. When it comes to recipes that involve making your own hardware to interface with the Raspberry Pi, I have tried to make good use of ready-made modules, as well as solderless breadboard and jumper wires to avoid the need for soldering.

For those wishing to make breadboard-based projects more durable, I suggest using prototyping boards with the same layout as a half-sized breadboard, such as those sold by Adafruit, so that the design can easily be transferred to a soldered solution.

Conventions Used in This Book

The following typographical conventions are used in this book:


Indicates new terms, URLs, email addresses, filenames, and file extensions.

Constant width

Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords.

Constant width bold

Shows commands or other text that should be typed literally by the user.

Constant width italic

Shows text that should be replaced with user-supplied values or by values determined by context.


This icon signifies a tip, suggestion, or general note.


This icon indicates a warning or caution.


This icon points you to the related video for that section.

Using Code Examples

Supplemental material (code examples, exercises, etc.) is available for download at

This book is here to help you get your job done. In general, if example code is offered with this book, you may use it in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission.

We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “Raspberry Pi Cookbook, Second Edition, by Simon Monk (O’Reilly). Copyright 2016 Simon Monk, 978-1-491-93910-9.”

If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at .

Safari® Books Online


Safari Books Online is an on-demand digital library that delivers expert content in both book and video form from the world’s leading authors in technology and business.

Technology professionals, software developers, web designers, and business and creative professionals use Safari Books Online as their primary resource for research, problem solving, learning, and certification training.

Safari Books Online offers a range of plans and pricing for enterprise, government, education, and individuals.

Members have access to thousands of books, training videos, and prepublication manuscripts in one fully searchable database from publishers like O’Reilly Media, Prentice Hall Professional, Addison-Wesley Professional, Microsoft Press, Sams, Que, Peachpit Press, Focal Press, Cisco Press, John Wiley & Sons, Syngress, Morgan Kaufmann, IBM Redbooks, Packt, Adobe Press, FT Press, Apress, Manning, New Riders, McGraw-Hill, Jones & Bartlett, Course Technology, and hundreds more. For more information about Safari Books Online, please visit us online.

How to Contact Us

Please address comments and questions concerning this book to the publisher:

  • O’Reilly Media, Inc.
  • 1005 Gravenstein Highway North
  • Sebastopol, CA 95472
  • 800-998-9938 (in the United States or Canada)
  • 707-829-0515 (international or local)
  • 707-829-0104 (fax)

We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at

To comment or ask technical questions about this book, send email to .

For more information about our books, courses, conferences, and news, see our website at

Find us on Facebook:

Follow us on Twitter:

Watch us on YouTube:


As always, I thank my wife Linda for her patience and support.

I also thank the technical reviewer Duncan Amos for his keen eye, good humor, and excellent suggestions that have without a doubt contributed greatly to this book.

Thanks also to all the O’Reilly team, especially those I met at the Cambridge office, who were very welcoming when I visited, and of course Nan Reinhardt for her diligent copyediting.

Get Raspberry Pi Cookbook, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.