Introduction - Raspberry Pi Projects (2014)

Raspberry Pi Projects (2014)

Introduction

When we’re young, making things is second nature – painting a picture, inventing a game, telling a story, building a rocket from a washing-up liquid bottle that we’re convinced will fly all the way to the moon. Childhood is all about adventure, discovery – the quest for something new.

Although these joys don’t fade with age, it can become harder to find space and time for play and discovery as “real life” takes over. But yet, some of the greatest inventions and discoveries of history were the result of curious people not being afraid to “have a go”, often tinkering away in their own homes or garden sheds rather than high-tech well-funded engineering companies.

What’s this got to do with a book on things to do with a Raspberry Pi?

Well, after reading and having a go at some of the projects in this book you might discover the pleasure of making something with a computer can bring. Computing offers a fantastic world of new and untapped opportunities for adventure and creativity. It touches so many areas of our lives (game consoles, set top boxes and smartphones are all computers) that you can combine it with almost any other passion or hobby.

You’ll see why a sprinkling of computing is beneficial for everyone, and that a moment of personal creativity on the kitchen table can have a much bigger impact. You’ll also discover the story behind a particular credit-card sized computer.

A History of Making

World-changing inventions can come from unconventional places.

Orville and Wilbur Wright were two ordinary brothers from Ohio who owned a bicycle shop. Fascinated with the workings of these simple machines, they became convinced that they could build a flying machine. And they did. In 1903, they launched the world’s first aeroplane. Nearly a century later, as HIV/AIDS swept through Africa, Trevor Baylis, an ex-stuntman, became convinced he could help. He sat in his suburban garden shed and invented an inexpensive and durable wind-up radio for use across Africa to spread simple health messages and undoubtedly prevented many, many deaths. Steve Jobs and Steve Wozniak, the founders of Apple, both learned about electronics and computers from experimenting in their bedrooms and family garages. These are just three examples that show the worldwide impact on millions tinkering at home can have.

Many inventors can clearly imagine what they want to make, but might not know how to build it. But, spurred on by the joy of creativity, they teach themselves the skills needed to build what they could imagine. Wozniak and Jobs developed their skills this way, taking apart existing appliances, figuring out how they work and putting them back together. Sometimes the appliances would be enhanced by tinkering, and sometimes they’d no longer work at all! But they weren’t put off; sometimes it was just about discovering how something worked, or the journey to overcome technical adversity, rather than producing a polished product.

Consumer Computing

It is ironic that the birth of Apple computers was a result of poking around in the innards of appliances. Nowadays, computers are sold as sleek, refined aluminium caskets of magic, sealing in opportunities to experiment and discover how they actually work. In a continual quest to add value to their products, manufacturers lure customers with the promise of easy-to-use products and an effortless user experience with your every need taken care of.

Unfortunately it’s not been a smooth journey. Rarely do modern computer systems do exactly what users want. How often are we left frustrated by a computer system failing, consoled by the manufacturer’s line that “that will be fixed in the next update” or “you need to buy the next version if you want it to do that”? For the technologically fearless, these statements are more like rallying cries, an excuse to tinker until the computer does what they really want. But these days, there are few people brave or skilled enough to roll their sleeves up and get inside.

Why Everyone Should Learn About Computing

Computers really are everywhere, pervading every aspect of our lives. As well as the laptop, desktop and smartphone, just think about the computers behind life support systems and medical records in our hospitals, in banking and shopping keeping the economy going, in manufacturing and our food-supply chain. They are key for our communications, powering digital TV and radio and mobile phone networks, as well as the Internet. With computers so integral to the functioning of our media, commerce and government, it seems odd that so many of us are ignorant of how they work.

Given how widespread the reliance on computers is, think how much we could all benefit from a little bit more understanding. Business leaders and politicians could make more informed decisions on projects involving computers, and the man-on-the-street would be less likely to fall prey to online scams or be duped by overimpressive advertising claims about products. They’d have the skills to make computers work for them to improve their lives.

I see similarities between computing and cooking. Cooking has recipes, which is about following steps. It is about making meals, consisting of sets of dishes. To make an apple pie, you need to break down the task into manageable elements (making the pastry, coring the apples, baking for just the right amount of time), all of which add to a complete (and hopefully tasty) apple pie. This is an example of abstraction, and is key to mastering computing. The problem-solving and logical-thinking techniques, such as managing abstraction, that are developed in computing are valuable to other aspects of life.

We teach our children how to cook, not because we want to train them to become professional chefs, but because we view it as an essential life skill. Without it, we condemn our children to a lifetime of preheating ready meals, often unfulfilling and expensive. For many people, learning the basic skills is the start of a lifelong love of cooking. They see it as an outlet for their creativity, perhaps starting with a recipe and adapting it to make it their own. It’s a social occupation, a chance to show achievements and discuss techniques, challenges and adventures around a lively dinner table.

I’d argue that learning to use computers has parallels with learning to cook. Everyone needs the basic skills. Some may use those skills to go on to become professional programmers, but I’d hope that for most people it is an opportunity for creativity, as well as a survival skill in today’s modern environment.

However, given the need for more people to learn more about how computers work and the reliance on them, it’s also ironic that getting into computing has become more difficult with modern computers. That is, until a certain credit-card–sized computer came along. . . .

Enter the Raspberry Pi

For most people, beginning to experiment on a £1000 laptop, putting precious data at risk is a daunting prospect. I’d think twice before putting all my digital photos, my music collection and my online banking at risk! Games consoles and some phones actively prevent people from creating their own games and apps, presumably to protect revenue by forcing consumer to buy manufacturer’s products.

With the desire to share the fun of computing and the need for more people to know how computers worked, Eben Upton created a small, cheap computer on his kitchen table. With the help of Dr. Rob Mullins, Professor Alan Mycroft and Jack Lang from Cambridge University; Pete Lomas, an expert in hardware; and David Braben, the Raspberry Pi Foundation was born, a charity that set out to promote the study of computer science and related topics, especially at the school level, and to put the fun back into learning computing.

The Raspberry Pi Foundation aimed to open up the world of computing by creating a hardware device that was pocket-money affordable, so it was accessible to everyone, and there’d be no need to worry about experimenting with it. It was unboxed to make it easy to tinker with.

In 2011, after five years’ intense kitchen-table engineering, the first prototype Raspberry Pi computers were produced. After a feature about the Raspberry Pi on technology journalist Rory Cellan-Jones’s blog went viral the Foundation wondered if they were at the early stages of something bigger than they were expecting.

After some clever engineering to allow the Raspberry Pi to be built cheaply enough to be sold for $25, an initial batch of 10,000 went on sale on 29th February 2012 at 6 a.m. A few minutes later, they had sold out. Eighteen months later, 1.75 million had been sold worldwide.

About This Book

During the development of the Raspberry Pi I’d been working on public engagement projects at the University of Manchester to encourage more people into computing.

I’d been following the Raspberry Pi from an early stage, and thought it had great potential. Like thousands of other engineers, I was also very excited by the technology crammed in this tiny PCB of components. I was also aware that for most people less familiar with computers, the same PCB wouldn’t be particularly exciting, and perhaps a scary mass of wires, components and metal. Like the Foundation, I wanted to share the wonder and joy computing could bring.

The big advantage of the Raspberry Pi was that it could be put it in places you couldn’t put a PC. I wanted the Raspberry Pi to be relevant to what people are interested in. To make it easy to connect to the Raspberry Pi, I came up with the PiFace Digital interface, developed at home on the kitchen table in my free evenings and weekends. I’m still amazed when I see people all over the world posting videos online showing what they’re doing with the Raspberry Pi and PiFace. I’ve seen children building robots, door-entry systems for the elderly, games and industrial applications in banks and railway stations.

How to Use This Book

This book aims to answer the question “You’ve got a Raspberry Pi – now what?” and is packed full of fun Raspberry Pi projects to inspire you.

This book is divided into three parts. There is some progression, but after you’ve got your Raspberry Pi up and running it should be fairly easy to dip into any of the other chapters. You can just follow the step-by-step instructions to get results quickly, but don’t be afraid to experiment and make them your own. That’s where the real fun lies! Background information is provided that will help you learn the skills you will need if you want to extend the projects.

At the end of each chapter, there are ideas and suggestions for extensions, but you will probably have your own too. We want to see what you create, so share your work with social media such as Facebook, Twitter and YouTube and tag them with RaspberryPiProjects.

Some code listings are available to download from the companion website at www.wiley.com/go/raspberrypiprojects if you get really stuck, but part of learning to program is about typing code in, so not all the code is provided!

Much of the background information is relevant to the classroom, and the book can be used to supplement teaching the new U.K. computing qualifications. If you’re a teacher, look out for supporting information that can help students learn through Raspberry Pi projects.

Part I: Getting Started with the Raspberry Pi

This part will take you through plugging together your Raspberry Pi and installing the software, plus introduces you to Python:

Chapter 1, “Getting Your Raspberry Pi Up and Running”, covers your first basic steps in getting your Raspberry Pi running.

Chapter 2, “Introductory Software Project: The Insult Generator”, gets you started programming in Python.

Part II: Software Projects

This contains some fun software projects:

Chapter 3, “Tic-Tac-Toe”, has you programming a game of tic-tac-toe, particularly covering lists and artificial intelligence.

Chapter 4, “Here’s the News”, shows you how to program your own teleprompter.

Chapter 5, “Ping”, covers how to program your own computer Ping-Pong game, describe movement to a computer, detect collisions and handle the physics of reflection.

Chapter 6, “Pie Man”, shows you how to program your own version of Pac-Man using animated sprites, layers and transparent pixels.

Chapter 7, “Minecraft Maze Maker”, uses a Python program to build a maze in Minecraft.

Part III: Hardware Projects

This contains some exciting and challenging hardware projects:

Chapter 8, “Colour Snap”, is an introductory hardware project that implements the game of Snap using different coloured lights and shows you how to safely power LEDs and use surface mount components.

Chapter 9, “Test Your Reactions”, gets you wiring up simple computer-controlled circuits.

Chapter 10, “The Twittering Toy”, shows you how to make your code talk to Twitter and gets you hacking household items.

Chapter 11, “Disco Lights”, shows you how to control LED strips and make them dance in time to music.

Chapter 12, “Door Lock”, covers how to build a computer-controlled door lock controlled by RFID tags and explains computer authentication.

Chapter 13, “Home Automation”, shows you how to create home-automation projects to make your home environment more intelligent, implementing door switches, motion sensors, a webcam and e-mail alerts.

Chapter 14, “Computer-Controlled Slot Car Racing”, gets you wiring up a slot car game and using it to keep score in a two-player multiple choice quiz.

Chapter 15, “Facebook-Enabled Roto-Sketch”, shows you how to use rotary controls to draw elaborate designs and automatically post them to Flickr and on to Facebook.

Chapter 16, “The Pendulum Pi, a Harmonograph”, shows you how to create a harmonograph for producing intricate patterns using an Arduino to help the Pi with real-time data gathering.

Chapter 17, “The Techno–Bird Box, a Wildlife Monitor”, covers how to build a “techno–bird box” that will monitor the bird activity in your garden.

The Future

Computers are set to be an ever-bigger part of our lives and touch more areas. Systems will be more complex with more connectivity. In the future your washing machine and other appliances in your home will likely talk to your smartphone. And we’ll all need more computing skills to master them. New ways of using computers will mean that there will be new areas for adventure and opportunities to change people’s lives and solve problems in the world.

One word of warning before you begin your adventure: After you start you might never stop! Electronics and coding can be addictive; who knows what you might go on to make with the skills you learn from this book.

Building and making is incredibly rewarding and satisfying. We want to get more people of the world to become producers of technology rather than consumers. The projects in this book are starting points – but then the real rewards come from making the project your own and seeing your own ideas become reality.

Welcome to the world of digital making. Are you ready to invent the future?