
Raspberry Pi Hardware Projects, Volume 2
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 UK 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 product names used in this book are trade names, service marks, trademarks or registered trademarks of their respective owners. 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 Wiley logo are trademarks or registered trademarks of John Wiley and Sons, Inc. and/ or its affiliates in the United States and/or other countries, and may not be used without written permission. 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-58890-1 (ePub); ISBN 978-1-118-72390-6 (ePDF)
Set in Chaparral Pro Regular 10/12.5 by Indianapolis Composition Services
Introduction
Youve got a Raspberry Pi now what? This book has the answer; its packed full of fun Raspberry Pi projects to inspire you. From getting your Pi generating comedy insults, controlling slot cars and drawing roto-sketches to building your own harmonograph, prepare to be entertained and amazed by your credit cardsized computer.
One word of warning: 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.
, 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. Along the way you will pick up the skills you need to develop your own ideas to make projects work exactly how you want them to.
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 step by step, theyre easy to follow so you can get results quickly. But then the real satisfaction can come, that which comes from making the project your own. At the end of each chapter there are ideas and suggestions to extend the project, together with background information to point you in the right direction. The real addictive fun begins when you see your own ideas become reality.
Welcome to the world of digital making.
Chapter
Computer-Controlled Slot Car Racing
In This Chapter
Learn how to use your Raspberry Pi to enable and disable a slot car set.
See how to make your own illuminated joystick pad.
Discover how to use an external text file as a question bank.
Understand the interactions between the software and hardware.
This project is a rather different twist on the multiple-choice quiz theme. Not only does it have a novel way of inputting answers, but it also has a rather novel way of keeping the score.
The idea is that you are going to hack into a slot car game and allow the Raspberry Pi to control when the game can be played. Then players can drive their cars for three seconds at a time, if they are the first to answer a question correctly. If they get the question wrong, their opponent gets the time. The game continues until one player crosses the finishing line after completing a set number of laps. The questions come from a plain text file and can be added to, or the subject of them changed. They are multiple-choice questions with four possible answers, and players indicate their answer by moving a special joystick button. The successful players joystick button will light up green, whereas the other players button will light up red.
Obtaining a Slot Car Racer
So how are you going to implement this game? First you need a slot car racing game. These come in all sorts of shapes and sizes, from sleek Formula One racing cars to heavy trucks and even grannies on Zimmer frames. In essence they are very similar: Its a race between two players. Mostly they are set up so that if you go too fast at the corners, the vehicle will come off the track, so it is not just a matter of running the cars at top speed all the time. Normally the track is some form of figure eight, so the track length can be made the same for both players. Sometimes the two vehicles cross at the same level, giving opportunities for crashes, and other times the tracks go over and under each other. Although there are very expensive racing games, some can be had cheaply in thrift shops or second-hand stores.
Hacking Your Slot Car Racer
You need to hack into your slot car racer, and, as there are lots of different types of them, I cant be too prescriptive about what you need to do. However, from the electrical point of view, it is basically all the same. What you are going to do is to wire a PiFace relay in series with each hand controller. This will involve cutting one of the two wires coming from the controller, and connecting each end of your cut wire into the NO and common relay connections. NO stands for normally open this connection is only connected to the common line when the relay is energised; when the relay is not energised, that is the normal state no electrical connection is made. shows how you can do this using a screw connection block. These are the type you use for electrical wiring around the house. They come in various sizes, and the size you want is the smallest, which is often marked something like 3 Amps. A sharp hobby knife can slice the two wires apart, and then you can cut one of them; it doesnt matter which one. You should cut back the insulation and then, following the diagram, attach each end to two of the connector blocks. Take the other end and run wires off to the PiFace board. Do the same for the other controller. When you want to play with your slot car game normally you simply replace the long wires trailing back to the PiFace board with a simple link. Do this close to the track connections so that you have the maximum length of wire on the hand controllers.
Figure 1-1: Hacking into your slot car racing game.