Transcription of Raspberry Pi User Guide - Computer Science
1 Raspberry Pi User GuideTable of ContentsIntroductionProgramming is fun!A bit of historySo what can you do with the Raspberry Pi?Part I: Connecting the BoardChapter 1: Meet the Raspberry PiARM vs. x86 Windows vs. LinuxGetting Started with the Raspberry PiConnecting a DisplayConnecting AudioConnecting a Keyboard and MouseFlashing the SD CardConnecting External StorageConnecting the NetworkConnecting PowerChapter 2: Linux System AdministrationLinux: An OverviewLinux BasicsIntroducing DebianUsing External Storage DevicesCreating a New User AccountFile System LayoutLogical LayoutPhysical LayoutInstalling and Uninstalling SoftwareFinding SoftwareInstalling SoftwareUninstalling SoftwareUpgrading SoftwareChapter 3: TroubleshootingKeyboard and Mouse DiagnosticsPower DiagnosticsDisplay DiagnosticsBoot DiagnosticsNetwork DiagnosticsThe Emergency KernelChapter 4: Network ConfigurationWired NetworkingWireless NetworkingChapter 5: Partition ManagementCreating a New PartitionResizing Existing PartitionsAutomatic ResizingManual ResizingMoving to a Bigger SD CardImaging from LinuxImaging from OS XImaging from WindowsChapter 6.
2 Configuring the Raspberry PiHardware Settings the DisplayBoot OptionsOverclocking the Raspberry PiDisabling L2 CacheEnabling Test ModeMemory Partitioning Settings II: Using the Pi as a Media Centre, Productivity Machine and Web ServerChapter 7: The Pi as a Home Theatre PCPlaying Music at the ConsoleDedicated HTPC with RasbmcStreaming Internet MediaStreaming Local Network MediaConfiguring RasbmcChapter 8: The Pi as a Productivity MachineUsing Cloud-Based AppsUsing Editing with The GimpChapter 9: The Pi as a Web ServerInstalling a LAMP StackInstalling WordPressPart III: Programming and HackingChapter 10: An Introduction to ScratchIntroducing ScratchExample 1: Hello WorldExample 2: Animation and SoundExample 3: A Simple GameRobotics and SensorsSensing with the PicoBoardRobotics with LEGOF urther ReadingChapter 11: An Introduction to PythonIntroducing PythonExample 1: Hello WorldExample 2: Comments, Inputs, Variables and LoopsExample 3: Gaming with pygameExample 4: Python and NetworkingFurther ReadingChapter 12: Hardware HackingElectronic EquipmentReading Resistor Colour CodesSourcing ComponentsOnline SourcesOffline SourcesHobby SpecialistsThe GPIO PortUART Serial BusI C BusSPI BusUsing the GPIO Port in PythonInstalling the GPIO Python LibraryGPIO Output: Flashing an LEDGPIO Input: Reading a ButtonMoving Up From the BreadboardA Brief Guide to SolderingChapter 13: Add-on BoardsCiseco Slice of PiAdafruit Prototyping Pi PlateFen Logic GertboardPart IV: AppendixesAppendix A: Python RecipesAppendix B: HDMI Display ModesRaspberry Pi User GuideEben Upton and Gareth HalfacreeRaspberry Pi User GuideThis edition first published 2012 2012 Eben Upton and Gareth HalfacreeRegistered officeJohn Wiley & Sons Ltd.
3 , The Atrium, Southern Gate, Chichester, West Sussex, PO19 8SQ, UnitedKingdomFor details of our global editorial offices, for customer services and for information about how to applyfor permission to reuse the copyright material in this book please see our website at right of the authors to be identified as the authors of this work has been asserted in accordancewith the Copyright, Designs and Patents Act rights reserved. No part of this publication may be reproduced, stored in a retrieval system, ortransmitted, in any form or by any means, electronic, mechanical, photocopying, recording orotherwise, except as permitted by the UK Copyright, Designs and Patents Act 1988, without the priorpermission of the also publishes its books in a variety of electronic formats. Some content that appears in print maynot be available in electronic used by companies to distinguish their products are often claimed as trademarks. Allbrand names and product names used in this book are trade names, service marks, trademarks orregistered trademarks of their respective owners.
4 The publisher is not associated with any product orvendor mentioned in this book. This publication is designed to provide accurate and authoritativeinformation in regard to the subject matter covered. It is sold on the understanding that the publisher isnot engaged in rendering professional services. If professional advice or other expert assistance isrequired, the services of a competent professional should be : Wiley and the Wiley logo are trademarks or registered trademarks of John Wiley andSons, Ltd. and/or its affiliates in the United States and/or other countries, and may not be used withoutwritten permission. Raspberry Pi and the Raspberry Pi logo are registered trademarks of the RaspberryPi 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 Drive is a registered trademark of Google .A catalogue record for this book is available from the British 978-1-118-46446-5 (pbk); ISBN 978-1-118-46448-9 (ebk); ISBN 978-1-118-46447-2 (ebk); ISBN978-1-118-46449-6 (ebk)Set in 10 pt.
5 Chaparral Pro by Indianapolis Composition ServicesPrinted simultaneously in Great Britain and the United StatesPublisher s AcknowledgementsSome of the people who helped bring this book to market include the following:Editorial and ProductionVP Consumer and Technology Publishing DirectorMichelle LeeteAssociate Director Book Content ManagementMartin TribeAssociate PublisherChris WebbExecutive Commissioning EditorCraig SmithAssistant EditorEllie ScottProject EditorKathryn DugganCopy EditorKathryn DugganTechnical EditorOmer KilicEditorial ManagerJodi JensenSenior Project EditorSara ShlaerEditorial AssistantLeslie SaxmanMarketingAssociate Marketing DirectorLouise BreinholtMarketing ManagerLorna MeinSenior Marketing ExecutiveKate ParrettComposition ServicesCompositorErin ZeltnerProofreaderWordsmith EditorialIndexerBIM Indexing & Proofreading ServicesAbout the AuthorsEben Upton is a founder and trustee of the Raspberry Pi Foundation, and serves as its Executive Director. He is responsible forthe overall software and hardware architecture of the Raspberry Pi, and for the Foundation's relationships with its key suppliersand customers.
6 In an earlier life, he founded two successful mobile games and middleware companies, Ideaworks 3d Ltd. andPodfun Ltd., and held the post of Director of Studies for Computer Science at St John's College, Cambridge. He holds a BA, aPhD and an MBA from the University of his day job, Eben works for Broadcom as an ASIC architect and general Halfacree is a freelance technology journalist and the co-author of the Raspberry Pi User Guide alongside project co-founder Eben Upton. Formerly a system administrator working in the education sector, Gareth s passion for open sourceprojects has followed him from one career to another, and he can often be seen reviewing, documenting or even contributing toprojects including GNU/Linux, LibreOffice, Fritzing and Arduino. He is also the creator of the Sleepduino and Burnduino openhardware projects, which extend the capabilities of the Arduino electronics prototyping system. A summary of his current workcan be found at Liz, who made it all possible.
7 EbenFor my father, the enthusiastic past, and my daughter, the exciting future. GarethIntroduction Children today are digital natives , said a man I got talking to at a fireworks party last year. I don t understand why you remaking this thing. My kids know more about setting up our PC than I do. I asked him if they could program, to which he replied: Why would they want to? The computers do all the stuff they need forthem already, don t they? Isn t that the point? As it happens, plenty of kids today aren t digital natives. We have yet to meet any of these imagined wild digital children,swinging from ropes of twisted-pair cable and chanting war songs in nicely parsed Python. In the Raspberry Pi Foundation seducational outreach work, we do meet a lot of kids whose entire interaction with technology is limited to closed platforms withgraphical user interfaces (GUIs) that they use to play movies, do a spot of word-processed homework and play games . Theycan browse the web, upload pictures and video, and even design web pages.
8 (They re often better at setting the satellite TV boxthan Mum or Dad, too.) It s a useful toolset, but it s shockingly incomplete, and in a country where 20% of households still don thave a Computer in the home, even this toolset is not available to all the most fervent wishes of my new acquaintance at the fireworks party, computers don t program themselves. We needan industry full of skilled engineers to keep technology moving forward, and we need young people to be taking those jobs to fillthe pipeline as older engineers retire and leave the industry. But there s much more to teaching a skill like programmatic thinkingthan breeding a new generation of coders and hardware hackers. Being able to structure your creative thoughts and tasks incomplex, non-linear ways is a learned talent, and one that has huge benefits for everyone who acquires it, from historians todesigners, lawyers and is fun!It s enormous, rewarding, creative fun. You can create gorgeous intricacies, as well as (much more gorgeous, in my opinion)clever, devastatingly quick and deceptively simple-looking routes through, under and over obstacles.
9 You can make stuff that llhave other people looking on jealously, and that ll make you feel wonderfully smug all afternoon. In my day job, where I designthe sort of silicon chips that we use in the Raspberry Pi as a processor and work on the low-level software that runs on them, Ibasically get paid to sit around all day playing. What could be better than equipping people to be able to spend a lifetime doingthat?It s not even as if we re coming from a position where children don t want to get involved in the Computer industry. A big kickup the backside came a few years ago, when we were moving quite slowly on the Raspberry Pi project. All the developmentwork on Raspberry Pi was done in the spare evenings and weekends of the Foundation s trustees and volunteers we re acharity, so the trustees aren t paid by the Foundation, and we all have full-time jobs to pay the bills. This meant that occasionally,motivation was hard to come by when all I wanted to do in the evening was slump in front of the Arrested Development boxedset with a glass of wine.
10 One evening, when not slumping, I was talking to a neighbour s nephew about the subjects he wastaking for his General Certificate of Secondary Education (GCSE, the British system of public examinations taken in varioussubjects from the age of about 16), and I asked him what he wanted to do for a living later on. I want to write Computer games , he said. Awesome. What sort of Computer do you have at home? I ve got some programming books you might be interested in. A Wii and an Xbox. On talking with him a bit more, it became clear that this perfectly smart kid had never done any real programming at all; that therewasn t any machine that he could program in the house; and that his information and communication technology (ICT) classes where he shared a Computer and was taught about web page design, using spreadsheets and word processing hadn t reallyequipped him to use a Computer even in the barest sense. But Computer games were a passion for him (and there s nothingpeculiar about wanting to work on something you re passionate about).