ebook img

Raspberry Pi Projects! PDF

480 Pages·2013·30.143 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Raspberry Pi Projects!

Raspberry Pi® Projects Dr. Andrew Robinson Mike Cook Jonathan Evans Sean McManus This edition first published 2014 © 2014 John Wiley & Sons, Ltd. Registered office John Wiley & Sons Ltd, The Atrium, Southern Gate, Chichester, West Sussex, PO19 8SQ, United Kingdom For details of our global editorial offices, for customer services and for information about how to apply for permission to reuse the copyright material in this book please see our website at www.wiley.com. The right of the authors to be identified as the authors of this work has been asserted in accordance with the Copyright, Designs and Patents Act 1988. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording or otherwise, except as permitted by the U.K. Copyright, Designs and Patents Act 1988, without the prior permission of the publisher. Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books. Designations used by companies to distinguish their products are often claimed as trademarks. All brand names and prod- uct names used in this book are trade names, service marks, trademarks or registered trademarks of their respective own- ers. The publisher is not associated with any product or vendor mentioned in this book. This publication is designed to provide accurate and authoritative information in regard to the subject matter covered. It is sold on the understanding that the publisher is not engaged in rendering professional services. If professional advice or other expert assistance is required, the services of a competent professional should be sought. Trademarks: Wiley and the John Wiley & Sons, Ltd. logo are trademarks or registered trademarks of John Wiley and Sons, Ltd. and/ or its affiliates in the United States and/or other countries, and may not be used without written permis- sion. Raspberry Pi is a trademark of the Raspberry Pi Foundation. All other trademarks are the property of their respective owners. John Wiley & Sons, Ltd. is not associated with any product or vendor mentioned in the book. A catalogue record for this book is available from the British Library. ISBN 978-1-118-55543-9 (paperback); ISBN 978-1-118-55556-9 (ePub); ISBN 978-1-118-55553-8 (ePDF) Set in Chaparral Pro Regular 10/12.5 by Indianapolis Composition Services Printed simultaneously in Great Britain and the United States. To the kitchen table inventors, and their long-suffering families that have to live with them. –Andrew Robinson To Mike Bibby, who was the first editor to give me the opportunity to write regularly about computers and hardware. His unfailing enthusiasm about all things and his inability to take anything just on trust are an example to us all. A continuing and valued friend. –Mike Cook Publisher’s Acknowledgements Some of the people who helped bring this book to market include the following: Editorial and Production Marketing VP Consumer and Technology Publishing Associate Marketing Director Director Louise Breinholt Michelle Leete Marketing Manager Associate Director–Book Content Lorna Mein Management Martin Tribe Senior Marketing Executive Kate Parrett Associate Publisher Chris Webb Marketing Assistant Polly Thomas Executive Commissioning Editor Craig Smith Project Editor Dana Lesh Copy Editors Dana Lesh, Kathryn Duggan Technical Editor Genevieve Smith-Nunes Editorial Manager Jodi Jensen Senior Project Editor Sara Shlaer Editorial Assistant Annie Sullivan About the Authors Andrew Robinson is the founder of a successful embedded computing design consultancy firm based in Manchester. Passionate about education, he runs workshops and training sessions for all levels of experience, from design engineers to teachers and school children. His projects with the Raspberry Pi have appeared in the national press and on ITV, Channel 5 and BBC television. He is an Honorary Research Fellow of the University of Manchester, where previously he completed his Ph.D. in low power-embedded processors. Andrew can trace his enthusiasm for electronics and computers back to building a working model lighthouse at the age of five. Mike Cook, veteran technical author and electronics maker from the U.K., was born in Manchester and still lives close by. He is best known to the public for a series of over 300 articles which appeared in The Micro User, Acorn Computing and Acorn User from 1983 to 2000. These were called the “Body Building Course” and “Run the Risc” and covered the design and build of new gadgets, interfaces and peripherals for the old (vintage) BBC computer and the RISC PC. He also wrote numerous reviews, software articles and the readers’ problem page in these magazines. Mike started work in the late sixties at an industrial electronics company in Oldham. He went on to take a degree in physical electronics at Newcastle, including a year spent working at the Admiralty Underwater Weapons establishment at Portland. His post-graduate research was in sound compression at the University of Salford. He spent over 20 years at Manchester Metropolitan University (initially Manchester Polytechnic) lecturing in physics, specialising in computer instrumentation, astronomy and image processing. Later he moved back into industry where he headed the hardware design team for the pioneering digital terrestrial set top box, and has been a development manager for security and RFID products. He now works freelance as an embedded electronics consultant and author. His last book was The Raspberry Pi For Dummies published by Wiley. Recently he has been designing even more things in the arena of physical computing, exhibiting at the U.K. Maker Fairs, Mini Maker Fairs and the prestigious New York World Maker fair. Mike was the recipient of a Maker of Merit Blue Ribbon at the 2013 Rome Maker Faire. Jonathan Evans has had a life-long interest in computers and electronics. At the tender age of 10, he taught himself how to program a computer, and he quickly learned how computers and electronics could be married for a functionality to keep his siblings out of his room. He has gone on to become a distinguished IT professional with over 20 years of experience. His passion for creation and innovation combines perfectly with the Raspberry Pi phenomenon, and in his spare time he enjoys exploring projects to make the Raspberry Pi relevant to everyday life. He enjoys sharing his ideas at www.projects.privateeyepi. com where he continues to explore the endless possibilities of this computing platform. Sean McManus writes inspiring books and articles about computing. He contributed the chapter on Minecraft to Raspberry Pi Projects, and his previous books include Raspberry Pi For Dummies (written with Mike Cook), Scratch Programming in Easy Steps, iPad for the Older and Wiser, Microsoft Office for the Older and Wiser, and Web Design in Easy Steps. Visit his website at www.sean.co.uk. Contents Introduction ..................................................................................1 A History of Making ..........................................................1 Consumer Computing ........................................................2 Why Everyone Should Learn About Computing ..................................2 Enter the Raspberry Pi ........................................................3 About This Book .............................................................4 How to Use This Book ........................................................4 The Future ..................................................................6 Part I: Getting Started with the Raspberry Pi CHAPTER 1 Getting Your Raspberry Pi Up and Running.......................................9 The Operating System .......................................................10 Connecting Your Raspberry Pi ................................................16 The Boot Process ............................................................25 Starting the Graphical Desktop ................................................26 Starting a Terminal under X ..................................................26 Troubleshooting ............................................................26 Let the Fun Begin! ...........................................................28 CHAPTER 2 Introductory Software Project: The Insult Generator ........................29 Running Your First Python Program ...........................................30 Saving Your Program ........................................................33 Generating an Insult .........................................................36 Insult Your Friends by Name! .................................................39 Create a Stream of Insults! ...................................................41 Putting It All Together .......................................................45 Part II: Software Projects CHAPTER 3 Tic-Tac-Toe ................................................................................49 Errors .....................................................................50 Making a Start ..............................................................51 A Two-Player Game .........................................................55 Getting the Computer to Play .................................................59 Over to You ................................................................70 CHAPTER 4 Here’s the News...........................................................................71 Early Teleprompters .........................................................72 The Pi Prompter. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .73 What You Need to Do .......................................................73 A Step Closer to a Usable Program .............................................78 Your Final Pi Prompter Code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .84 The Physical Setup for Your Prompter ..........................................89 Over to You ................................................................92 vi RASPBERRY PI PROJECTS CHAPTER 5 Ping...........................................................................................93 Early Commercial Products ...................................................94 The Ping Game ..............................................................94 Improving the Ping Game ....................................................99 A Single-Player Game .......................................................104 A Two-Player Game ........................................................111 Over to You ...............................................................118 CHAPTER 6 Pie Man ....................................................................................121 The Pie Man Game .........................................................122 Gather Your Resources ......................................................123 Setting the Stage ...........................................................127 The Game Action ...........................................................133 Drawing the Screen .........................................................141 The Final Function .........................................................144 Over to You ...............................................................150 CHAPTER 7 Minecraft Maze Maker ................................................................151 Installing Minecraft ........................................................152 Starting Minecraft. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .153 Playing Minecraft ..........................................................154 Preparing for Python .......................................................156 Using the Minecraft Module .................................................156 Over to You ...............................................................174 Part III: Hardware Projects CHAPTER 8 Colour Snap ..............................................................................177 Implementing the Game ....................................................178 The Software for Testing the Game ...........................................193 The Software for the Game ..................................................196 Over to You ...............................................................202 CHAPTER 9 Test Your Reactions...................................................................203 Welcome to the Embedded World!. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .204 Obtaining Components .....................................................205 Setting up PiFace Digital ....................................................206 Connecting PiFace Digital ...................................................210 Using the Emulator .........................................................210 Interfacing with Python .....................................................211 The Reaction Timer .........................................................214 What Will You Interface? ....................................................226 vii TABLE OF CONTENTS CHAPTER 10 The Twittering Toy.....................................................................227 Hacking the Toy ...........................................................228 Making It Talk .............................................................232 Making It Move ............................................................235 Connecting to Twitter ......................................................239 Putting It All Together ......................................................245 Wrapping Up ..............................................................248 CHAPTER 11 Disco Lights ..............................................................................251 Defining Your Sequence .....................................................252 Getting the Code to Do More ................................................254 A Small Detour into Theory ..................................................256 Designing the Sequencer ....................................................257 Implementing the Sequencer ................................................258 The Lights .................................................................265 Using Longer Strip Lights ...................................................268 Making the Lights Move ....................................................269 Designing the Circuit .......................................................270 Building the Circuit .........................................................273 Running the Circuit ........................................................273 Over to You ...............................................................274 CHAPTER 12 Door Lock ................................................................................275 The System Overview .......................................................276 Safety-Critical Systems ......................................................276 The Door Lock Hardware ....................................................277 The Initial High-Level Software Simulation ....................................278 The Output Block ..........................................................281 The Input Block ............................................................283 The Authentication Block ....................................................284 Unlocking Doors Without Touching ..........................................286 Testing the Program and Fitting the Lock .....................................292 Networking Multiple Doors .................................................293 Over to You ...............................................................294 The Art of Programming ....................................................295 CHAPTER 13 Home Automation ......................................................................297 The Internet Of Things ......................................................298 Project 1: How to Create a Motion Sensor and Door Switch ......................298 Project 2: How to Monitor Your Home with a Webcam ..........................305 Project 3: How to Make a Temperature Gauge ..................................312 Project 4: How to Send an E-mail Alert ........................................317 viii RASPBERRY PI PROJECTS Project 5: How to Send an E-mail Using a Wireless Remote ......................324 Over to You ...............................................................331 CHAPTER 14 Computer-Controlled Slot Car Racing...........................................333 Obtaining a Slot Car Racer ...................................................334 Hacking Your Slot Car Racer .................................................334 Getting the Player Input ....................................................336 The Software ..............................................................346 The Game .................................................................348 Over to You ...............................................................354 CHAPTER 15 Facebook-Enabled Roto-Sketch ...................................................355 The Concept ...............................................................356 Rotary Encoder Types ......................................................356 The Encoder Output ........................................................357 Posting to Facebook ........................................................366 The Final Roto-Sketch Program ..............................................369 Creating a Symmetrical Pattern ..............................................375 Over to You ...............................................................381 CHAPTER 16 The Pendulum Pi, a Harmonograph .............................................383 The Concept ...............................................................385 The Hall Effect .............................................................385 Enter the Arduino ..........................................................387 Putting It Together .........................................................388 Programming the Arduino ...................................................399 Programming the Pi ........................................................412 Using the Pendulum Pi ......................................................418 Over to You ...............................................................419 CHAPTER 17 The Techno–Bird Box, a Wildlife Monitor.....................................421 Building Invisible Light Beam Sensors .........................................423 Mounting the Sensors ......................................................427 Recording Activity to a File ..................................................431 Processing the Data ........................................................442 Dealing with Sensor Noise ...................................................448 Drawing a Graph ...........................................................454 Putting the Nest Box into Service .............................................458 Over to You ...............................................................458 The Possibilities Are Endless .................................................460 Index........................................................................................461

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.