Raspberry Pi Projects for Kids (Second Edition) - Daniel Bates - E-Book

Raspberry Pi Projects for Kids (Second Edition) E-Book

Daniel Bates

0,0
20,39 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

This book is for kids who wish to develop games and applications using the Raspberry Pi. No prior experience in programming is necessary; you need only a Raspberry Pi and the required peripherals.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 167

Veröffentlichungsjahr: 2015

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

Raspberry Pi Projects for Kids Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Getting Started with Raspberry Pi
Materials needed
Power supply
Storage
Input
Video
Network
Preparing the SD card
Starting up the Raspberry Pi
Using your Raspberry Pi
The command line
Updating and installing new software
Other uses of the Raspberry Pi
Troubleshooting common issues
Summary
2. Animating with Scratch
Scratch
Hello world!
Code tour
Some more interesting movements
Setting the scene
Another way to animate
Interactive animation
Variables
Movement
Keeping count
If-then-else
Summary
3. Making Your Own Angry Birds Game
Creating a character
Creating a level
Moving the character
Initialization
Moving the character with the keyboard
Launching the character!
Flight
Adding physics
Gravity
Bouncing
Ending the game
Scoring
Extensions
Summary
4. Creating Random Insults
Python
Python programming
The program we're going to use to generate phrases
Lists
Adding randomness
Creating phrases
Making mischief
Dictionaries
Loops
Conditionals
Functions
Complete code listing
Summary
5. Testing Your Speed
Materials needed to make your own controller
Creating the game controller
The controller base
Adding buttons
Connecting to the Raspberry Pi
Coding the game
Random behavior
Using the controller
Adding a time limit
Bringing it all together
Complete code listing
The keyboard version
What's next?
Summary
6. Making an Interactive Map of your City
Hello world!
Tkinter
Writing the program
Getting a map
No Internet? No problem!
Google Maps
Generating the address
Downloading an image
Using an image
Adding markers
Detecting mouse clicks
Reacting to mouse clicks
Adding labels
Basic labels
Pop-up windows
Code listing
Extensions
Layout
Additional widgets
Checkbutton
Frame and LabelFrame
Listbox
Menu
Menubutton
Message
OptionMenu
Radiobutton
Scale
Spinbox
Summary
7. Building Beats with Sonic Pi
Sonic Pi
Getting started with Sonic Pi
Creating a tune
New sounds
A real tune
Adding rhythm
Bass line
More fun
Code listing
Summary
Index

Raspberry Pi Projects for Kids Second Edition

Raspberry Pi Projects for Kids Second Edition

Copyright © 2015 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

First published: March 2014

Second edition: April 2015

Production reference: 1240415

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham B3 2PB, UK.

ISBN 978-1-78528-152-5

www.packtpub.com

Credits

Author

Daniel Bates

Reviewers

Ed Baker

Colin Deady

Ian McAlpine

Commissioning Editor

Priya Singh

Acquisition Editors

Harsha Bharwani

Sonali Vernekar

Content Development Editor

Nikhil Potdukhe

Technical Editor

Rohith Rajan

Copy Editors

Sonia Cheema

Merilyn Periera

Project Coordinator

Akash Poojary

Proofreaders

Simran Bhogal

Safis Editing

Indexer

Tejal Soni

Graphics

Sheetal Aute

Production Coordinator

Arvindkumar Gupta

Cover Work

Arvindkumar Gupta

About the Author

Daniel Bates is a computer science researcher at the University of Cambridge. His day job involves inventing designs for future mobile phone processors and when he gets home, he likes playing games or working on one of his coding projects (or both!). Daniel has been a volunteer for the Raspberry Pi Foundation since 2011 and is enthusiastic about introducing new people to computing. He has previously written Instant Minecraft: Pi Edition Coding How-to and Raspberry Pi Projects for Kids (First Edition), both published by Packt Publishing.

About the Reviewers

Ed Baker graduated with a BSc in physics from Imperial College, London, in 2007 and somehow ended up working in the Entomology Department of the Natural History Museum shortly after. His work focuses on how technology, both hardware and software, can improve the way research is performed, from field data collection to final publication. Outside the technology world, he is a specialist on stick insects, cockroaches, and grasshoppers.

Recently, his work has focused on automated acoustic and environmental monitoring, protocols for sensor networks, and starting the biodiversity technology company http://www.infocology.co.uk.

Ed's first book, provisionally titled Arduino for Biologists, will be published in 2015 with Pelagic Publishing.

I would like to thank Philippa for believing that the writing and 'tinkering' would bring reward in the end.

Colin Deady's career in IT started in the late 1990s, when he discovered software testing ("they want me to break it?"), having previously fallen in love with computers when his parents brought him and his brother a ZX81 and ZX Spectrum+ in the 1980s and later an Amiga 1200 in the early 1990s. With over 15 years of experience in testing, he works as a Technical Test Manager, emphasizing the benefits of test automation and extolling the virtues of agile using Kanban and Behavior-Driven Development to great effect: define behaviors, then test early, test often. He combines BDD with a fix early, fix often approach that he terms Zero Known Defects.

Colin was one of the technical reviewers for Tim Cox's excellent Raspberry Pi Cookbook for Python Programmers, by Packt Publishing, and has written several articles for The MagPi, a community magazine for the Raspberry Pi. He has also reviewed and edited many more, building up extensive knowledge on this tiny platform.

He currently runs a blog related to all things Raspberry Pi, which can be found at www.rasptut.co.uk.

Ian McAlpine was first introduced to computers when he used his school's Research Machines RML 380Z and his physics teacher's Compukit UK101. This was followed by a Sinclair ZX81 and then a BBC Micro Model A, which he still has to this day. The interest he has in computers resulted in an MEng degree in electronic systems engineering from Aston University and an MSc in information technology from the University of Liverpool. Ian is currently a product expert in the Business Intelligence and Analytics Competence Center at SAP Labs in Vancouver, Canada.

The introduction of the Raspberry Pi rekindled his desire to "tinker" but also provided him with an opportunity to give back to the community. Ian is also a very active volunteer, who works for The MagPi, a monthly magazine for the Raspberry Pi community, which you can read online or download for free from www.themagpi.com. He also holds an amateur radio license (callsign VE7FTO) and is a communications volunteer for his local community emergency management office. He was a technical reviewer for Raspberry Pi Cookbook for Python Programmers, by Packt Publishing.

I would like to thank my darling wife, Louise, and my awesome kids, Emily and Molly, who've allowed me to disappear into my office and have, consequently, trained our dog to fetch me!

www.PacktPub.com

Support files, eBooks, discount offers, and more

For support files and downloads related to your book, please visit www.PacktPub.com.

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

https://www2.packtpub.com/books/subscription/packtlib

Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.

Why subscribe?

Fully searchable across every book published by PacktCopy and paste, print, and bookmark contentOn demand and accessible via a web browser

Free access for Packt account holders

If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view 9 entirely free books. Simply use your login credentials for immediate access.

Preface

The Raspberry Pi is a credit card-sized computer designed to make computing accessible to all. With the trend towards making computers easier and easier to use, the art of programming has been in decline. Programming is a powerful tool that lets us tell the computer exactly what we want to do. In much the same way as we use a hammer or screwdriver to help us with a physical task, we can use programming to help us with a mental task. The Raspberry Pi exposes programming software to make it as easy as possible to get started.

After introducing the Raspberry Pi computer and showing you how to set it up, this book will guide you through six separate mini-projects. Each project is fun, visual, and has plenty of scope for personalization. By the end of this book, you will understand and be able to use three different programming languages, and will be able to use them to build creative programs of your own.

What this book covers

Chapter 1, Getting Started with Raspberry Pi, shows you what Raspberry Pi is and how you can get one set up and ready to use.

Chapter 2, Animating with Scratch, introduces the Scratch programming language and uses it to create simple (and not-so-simple) animations.

Chapter 3, Making Your Own Angry Birds Game, teaches you how to make your very own computer game using the Scratch programming language.

Chapter 4, Creating Random Insults, explores how random funny phrases can be generated using the Python programming language.

Chapter 5, Testing Your Speed, helps you to connect electronic components to your Raspberry Pi to create a physical game controlled by your computer code written in Python.

Chapter 6, Making an Interactive Map of Your City, teaches you more about Python and shows you how to access Google Maps to create a personal map of your area.

Chapter 7, Building Beats with Sonic Pi, introduces the Sonic Pi application and shows you how the programming concepts learned so far can be applied to the creation of music.

What you need for this book

All the projects in this book require Raspberry Pi and all the necessary peripherals (listed at the beginning of Chapter 1, Getting Started with Raspberry Pi). Chapter 5, Testing Your Speed, adds simple electronic components, listed at the beginning of that chapter. Chapter 7, Building Beats with Sonic Pi, requires headphones or speakers.

Who this book is for

This book is designed to help adults and children jump into creative coding using the Raspberry Pi. You will need patience, a sense of adventure, and a vivid imagination!

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail <[email protected]>, and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from: https://www.packtpub.com/sites/default/files/downloads/1525OS_ColorImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the ErrataSubmissionForm link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at <[email protected]> with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at <[email protected]>, and we will do our best to address the problem.

Chapter 1. Getting Started with Raspberry Pi

In the mid-2000s, some of the staff at the University of Cambridge noticed that there were fewer students applying to study computer science each year, and that they didn't have very much experience. Something had to be done about this situation. The answer was the Raspberry Pi: a small, inexpensive computer which makes programming as accessible and as fun as possible. The idea is that students can play with the Raspberry Pi in their spare time, and in the process, learn valuable core computer science skills. Since its creation, many other groups have discovered how useful the Raspberry Pi can be, including schools, adults who want to brush up on their skills with technology, and electronics hobbyists.

This chapter describes how to get a Raspberry Pi computer up and running. Once this is done, the Pi behaves just like any other ordinary computer, and is capable of standard tasks, such as browsing the web and playing games. We will learn in later chapters that the Raspberry Pi is also capable of some things which ordinary computers can't easily do.

The following image shows an example of the Raspberry Pi that we will be using in the rest of the book:

Materials needed

Any model of the Raspberry Pi will work for the projects used in this book. The preceding image shows a Raspberry Pi Model B+, with four USB ports and a network connection. The Model A+ (with one USB port and no network connection) will also work, but a USB hub (which is described later) will be needed to allow both a keyboard and mouse to be used at the same time.

The Models A+ and B+ replace the older Models A and B, and have the same capabilities, but neater designs. You can identify the Plus models by looking at the mounting holes surrounded by metal. The Plus (+) models have four mounting holes in a rectangle, whereas the previous models have two or zero mounting holes. In the preceding image, two mounting holes are in the corners at the left end of the board, and the other two mounting holes are on the mid-right of the board.

The Raspberry Pi 2 looks almost the same as Model B+, but has a faster processor. This is not important for the projects in this book. Along with a Raspberry Pi computer, you will need other peripherals. In order to keep costs down, the Raspberry Pi was designed to work with devices that people already owned; you may find many of these components around your house already. Just make sure they're not in use before you take them!

Tip

http://elinux.org/RPi_VerifiedPeripherals is a useful website to check whether a particular device will work with the Raspberry Pi.

Power supply

The Raspberry Pi requires a micro-USB connection, which is capable of supplying at least 700 mA (or 0.7A) at 5V. Power supplies, which can give 1000 mA or more are available (and will be more reliable), but it must supply exactly 5 V. Most standard mobile phone chargers are suitable for this purpose, and have their capabilities written on them, so you can check. Do not attempt to power your Pi from the USB port of another computer or hub; they are often incapable of supplying the required current.

Storage

The operating system and files of Raspbian are stored on an SD card, which is similar to what you may find in a digital camera. The Raspberry Pi models A and B use a standard-sized SD card, while the A+, B+ and Pi 2 models use smaller microSD cards. You will need at least 4 GB of space (preferably 8 GB or more). The Raspberry Pi Foundation sells very affordable 8 GB SD cards with the operating system pre-installed, and these can be found at http://swag.raspberrypi.org/.

If you start with a blank SD card, you will also need a way of writing to it from another computer. Many computers have SD writers built in, but it is possible to buy USB dongles which do the job too.

Input

For inputs, we will use a USB keyboard and mouse:

Keyboard

Mouse

Video

We will use a monitor or a television with HDMI or DVI input, and a video cable connected from the Pi's HDMI port to the screen's input, as shown in the following figures. It is possible to connect to an older VGA or composite screen, but this is more complicated. Take a look at this website more information http://elinux.org/RPi_VerifiedPeripherals.

The following images show the display monitor and cables that you might use to connect the Pi to your monitor:

Monitor

DVI connector

HDMI connector

Network

An Internet connection