Getting Started with Raspberry Pi Zero - Richard Grimmett - E-Book

Getting Started with Raspberry Pi Zero E-Book

Richard Grimmett

0,0
26,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

Get started with the smallest, cheapest, and highest-utility Pi ever—Raspberry Pi Zero

About This Book

  • Get started with Raspberry Pi Zero and put all of its exciting features to use
  • Create fun games and programs with little or no programming experience
  • Learn to use this super-tiny PC to control hardware and software for work, play, and everything else

Who This Book Is For

This book is for hobbyists and programmers who are taking their first steps toward using Raspberry Pi Zero. No programming experience is required, although some Python programming experience might be useful.

What You Will Learn

  • Understand how to initially download the operating system and set up Raspberry Pi Zero
  • Find out how to control the GPIO pins of Raspberry Pi Zero to control LED circuits
  • Get to grips with adding hardware to the GPIO to control more complex hardware such as motors
  • Add USB control hardware to control a complex robot with 12 servos
  • Include speech recognition so that projects can receive commands
  • Enable the robot to communicate with the world around it by adding speech output
  • Control the robot from a distance and see what the robot is seeing by adding wireless communication
  • Discover how to build a Robotic hand and a Quadcopter

In Detail

Raspberry Pi Zero is half the size of Raspberry Pi A, only with twice the utility. At just three centimeters wide, it packs in every utility required for full-fledged computing tasks. This practical tutorial will help you quickly get up and running with Raspberry Pi Zero to control hardware and software and write simple programs and games. You will learn to build creative programs and exciting games with little or no programming experience. We cover all the features of Raspberry Pi Zero as you discover how to configure software and hardware, and control external devices. You will find out how to navigate your way in Raspbian, write simple Python scripts, and create simple DIY programs.

Style and approach

This is a practical and fun ?getting started? tutorial that will guide you through everything new that the Raspberry Pi has to offer.

Sie lesen das E-Book in den Legimi-Apps auf:

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 181

Veröffentlichungsjahr: 2016

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

Getting Started with Raspberry Pi Zero
Credits
About the Author
About the Reviewer
www.PacktPub.com
eBooks, discount offers, and more
Why subscribe?
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 Zero
Setting up the Raspberry Pi Zero
Powering the board
Hooking up a keyboard, mouse, and display
Installing the operating system
Adding Internet access
Accessing your Raspberry Pi Zero from your host PC
Summary
2. Programming Raspberry Pi Zero
Powering up Raspberry Pi Zero with Linux
Creating, editing, and saving files
Creating and running Python programs
Basic programming constructs on Raspberry Pi Zero
The if statement
The while statement
Working with functions
Libraries/modules in Python
Summary
3. Accessing the GPIO Pins on Raspberry Pi Zero
The GPIO capability of Raspberry Pi Zero
Simple GPIO digital voltage output
Raspberry Pi Zero and LED code
Adding a sonar sensor
Raspberry Pi Zero and the sonar sensor code
Connecting a digital compass to Raspberry Pi Zero
Accessing the compass programmatically
Summary
4. Building and Controlling a Simple Wheeled Robot
The basic platform
Controlling an H-bridge interface to the DC motors
Controlling your mobile platform programmatically using the Raspberry Pi Zero
Controlling the speed of your motors with PWM
Using a motor controller board to control the DC motors
Controlling the vehicle using the Raspberry Pi Zero in Python
Planning your path
Summary
5. Building a Robot That Can Walk
Robots that can walk
How servo motors work
Building the quadruped platform
Using a servo controller to control the servos
Communicating between the servo controller and a PC
Connecting the servo controller to the Raspberry Pi Zero
Creating a program in Linux to control your quadruped
Summary
6. Adding Voice Recognition and Speech – A Voice Activated Robot
Communication between the Raspberry Pi Zero and the robot
Giving your robot voice commands
Using eSpeak to allow your robot to respond with an audible voice
Using pocketsphinx to accept your voice commands
Interpreting commands and initiating actions
Summary
7. Adding Raspberry Pi Zero to an RC Vehicle
Configuring and controlling an RC car with Raspberry Pi Zero
Controlling the RC car in Python
Accessing the RC car remotely
Connecting a webcam
Summary
8. Playing Rock, Paper, or Scissors with Raspberry Pi Zero
A robotic hand
Moving the robotic hand
Connecting the servo controller to the Raspberry Pi Zero
Creating a program on Raspberry Pi Zero so that you can control your hand
Installing a USB camera on Raspberry Pi Zero
Downloading and installing OpenCV – a fully featured vision library
Gesture detection
Summary
9. Adding Raspberry Pi Zero to a Quadcopter
Constructing the platform
Mission planning software
Summary
Index

Getting Started with Raspberry Pi Zero

Getting Started with Raspberry Pi Zero

Copyright © 2016 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 2016

Production reference: 1210316

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham B3 2PB, UK.

ISBN 978-1-78646-946-5

www.packtpub.com

Credits

Author

Richard Grimmett

Reviewer

David Whale

Commissioning Editor

Kartikey Pandey

Acquisition Editor

Tushar Gupta

Content Development Editor

Merint Thomas Mathew

Technical Editor

Saurabh Malhotra

Copy Editors

Kevin McGowan

Sneha Singh

Project Coordinator

Francina Pinto

Proofreader

Safis Editing

Indexer

Priya Sane

Graphics

Disha Haria

Production Coordinator

Shantanu N. Zagade

Cover Work

Shantanu N. Zagade

About the Author

Richard Grimmett has always been fascinated by computers and electronics since his very first programming project that used Fortran on punch cards. He has a bachelor's and master's degree in electrical engineering and a PhD in leadership studies. He also has 26 years of experience in the radar and telecommunications industries, and even has one of the original brick phones. He now teaches computer science and electrical engineering at the Brigham Young University, Idaho, where his office is filled with his numerous robotics projects.

This book is the result of working with the wonderful students at BYU-Idaho. It also wouldn't be possible without the help of my wonderful wife, Jeanne.

About the Reviewer

David Whale is a software developer living in Essex, UK. He started coding as a schoolboy aged 11, inspired by the school science technician to build his own computer from a kit and quickly progressed to writing machine code programs because they were "small and fast". These early experiments led to some of his code being used inside a saleable educational word game when he was only 13.

He has been developing software professionally ever since, mainly writing small and fast code that goes into electronic products, including automated machinery, electric cars, mobile phones, energy meters, and wireless doorbells.

These days, he runs his own software consultancy called Thinking Binaries and spends nearly half of his time helping to design the next wave of the Internet called The Internet of Things, by connecting electronic devices to it. The rest of the time he volunteers for The Institution of Engineering and Technology, running training courses for teachers, designing and running workshops and clubs for school children, and being busy with his Raspberry Pi, BBC micro:bit and Arduino.

He was the technical editor for the book Adventures in Raspberry Pi and the co-author of the book Adventures in Minecraft, and is a regular reviewer and editor of technical books from a number of book publishers.

I was really pleased to be asked to review this great new book of projects using the Raspberry Pi Zero. The size of the Pi Zero makes it ideal for building into other products. In this book, Richard Grimmett takes us on an amazing journey of circuit bending, coding, and innovating using this tiny computer! But don't stop here; the projects in this book will give you the skills you need and inspire you to come up with many new ideas yourself!

www.PacktPub.com

eBooks, discount offers, and more

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

Preface

For many years, robots and other advanced electronic wonders could only be seen on the television, movies, or in university or military labs. In recent years, however, the availability of new and inexpensive hardware and also free and open source software, has provided the opportunity for almost anyone with a little technical knowledge and imagination to build these technical wonders. The first wave of projects were fueled by Arduino, an inexpensive and simple-to-program microcontroller. The next wave was carried further by the introduction of the Raspberry Pi, an even more capable processor powered by the Linux operating system.

Now there is an even less expensive, powerful microprocessor: the Raspberry Pi Zero. This little processor packs a processor powerful enough to run Linux into a small and even less expensive package. This capability, coupled with some additional power, inexpensive hardware, and free open source software provides a platform for projects that range from simple wheeled robots to advanced flying machines.

What this book covers

Chapter 1, Setting Started with Raspberry Pi Zero, is designed to go through the details of setting up a useful development environment on Raspberry Pi Zero. The chapter begins with a discussion of how to connect power and continues through setting up a full system, configured and ready to be connected to any of the amazing devices and SW capabilities to develop advanced robotics applications.

Chapter 2, Programming Raspberry Pi Zero, reviews, for those who are already familiar, basic Linux, editing, and programming techniques that will be useful through the rest of the book. You'll learn how to interact from the command line, how to create and edit a file using an editor, and basic Python programming.

Chapter 3, Accessing the GPIO Pins on Raspberry Pi Zero, discusses the GPIO capabilities of Raspberry Pi Zero by building and controlling some simple LED circuits.

Chapter 4, Building and Controlling a Simple Wheeled Robot, discusses one of the amazing things you can do with Raspberry Pi Zero, controlling a simple wheeled robot. This chapter will show you how to add motor control, so you can build your very own autonomous mobile robot.

Chapter 5, Building a Robot That Can Walk, tells us about another impressive robotic project, an autonomous robot that can walk. This is done using servos whose position can be controlled using Raspberry Pi and some additional USB-controlled hardware.

Chapter 6, Adding Voice Recognition and Speech – A Voice Activated Robot, tells us about a voice-activated robot. One of the significant new features of today's computer system is the ability to input commands and provide output without a screen or keyboard. A few years ago, the concept of a computer that can talk and listen was science fiction, but today it is becoming a standard part of new cell phones. This chapter introduces how Raspberry Pi Zero can both listen to speech and also respond in kind. This is not as easy as it sounds (pun intended) and you'll be exposed to some basic functionality, while also understanding some of the key limitations. You'll take a standard toy and turn it into a responsive robot.

Chapter 7, Adding Raspberry Pi Zero to an RC Vehicle, tells us about another astounding capability of Raspberry Pi Zero, the ability to add "sight" to you projects. Raspberry Pi Zero makes this very easy by supporting open source software and readily available USB webcams. By adding this and a remote control, you can build a remote control vehicle that can go around corners, into rooms, wherever you'd like to go.

Chapter 8, Playing Rock, Paper, or Scissors with Raspberry Pi Zero, tells us about how we can use our toolkit to build and control a robotic hand that can see and respond to the world around it. In this case, you'll program your hand to play rock, paper, and scissors.

Chapter 9, Adding Raspberry Pi Zero to a Quadcopter, talks about the fact that building a robot that can walk, talk, or play air hockey is cool, but one that can fly is the ultimate goal.

What you need for this book

You need a Raspberry Pi Zero. You can refer to the software list along with the code bundle of the book.

Who this book is for

This book is designed for the beginner. It requires little more than a vivid imagination and a desire to learn the basics of programming and hardware configuration.

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 for this book from your account at http://www.packtpub.com. 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.

You can download the code files by following these steps:

Log in or register to our website using your e-mail address and password.Hover the mouse pointer on the SUPPORT tab at the top.Click on Code Downloads & Errata.Enter the name of the book in the Search box.Select the book for which you're looking to download the code files.Choose from the drop-down menu where you purchased this book from.Click on Code Download.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

WinRAR/7-Zip for WindowsZipeg/iZip/UnRarX for Mac7-Zip/PeaZip for Linux

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 http://www.packtpub.com/sites/default/files/downloads/GettingStartedwithRaspberryPiZero_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 Errata Submission Form 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 Zero

There has been a major shift in electronics and computer accessibility driven by the introduction of the Raspberry Pi microcomputer and its variants. With a completely different price point along with a significantly expanded support community, the Raspberry Pi has been an unprecedented success in bringing inexpensive computing to a wide audience. The Raspberry Pi Zero continues with that important approach, providing unprecedented computer power at an even lower price point.

The Raspberry Pi Zero is particularly useful as it can be paired with inexpensive hardware and open-source software to do a wide range of different Do-It-Yourself projects. You'll learn about many of these in this book. You'll learn how to control DC motors, how to control servos, how to hook up a microphone for speech recognition, and even how to connect a webcam to view and interpret the outside world.

The Raspberry Pi Zero can do amazing things, but first you'll need to understand how to access all of this capability. In this chapter, you'll learn how to:

Provide power to the boardConnect a display, keyboard, and mouseLoad and configure the operating systemConfigure the board for remote access

Setting up the Raspberry Pi Zero

While the Raspberry Pi Zero is a powerful computer, you'll need some additional hardware to access this capability. Here are the items that you'll need for this chapter's projects:

A Raspberry Pi ZeroA micro USB cable and power supply to provide power to the boardA display with an HDMI video inputA keyboard, a mouse, and a powered USB hubA microSD card – with at least 4 GB capacityA microSD card writerAnother computer that is connected to the InternetA WLAN USB dongleA 40x2 pin connector strip

Before you get started, let's get familiar with the Raspberry Pi Zero. Here is an image of the hardware:

Note that the GPIO pin male headers are not pre-soldered to the board; you'll want to do that. You can buy these at most online electronics retailers. You should also become familiar with the various connections on the board. Here, you can see the Raspberry Pi Zero with the connector soldered and the connections labeled for your information:

Powering the board

One of the first issues you'll want to consider is how to power the board. To do this, you need to connect through the USB power connection. There are two choices to provide power to the Raspberry Pi Zero:

Connect the microUSB connector labeled power to a 5V DC source powered by a USB power supply. This can be either a power supply that can plug directly into an outlet or power supplied by a powered USB port like those available on most computers.Connect the microUSB connector to a battery. The simplest connection is to batteries that have a USB connector, like those used to charge cellphones. Here is a image of just such a battery:

In both cases, make sure that the unit can supply enough current. You'll need a supply that can provide at least 1000 mA at 5 volts. There are two USB charge connections on this battery which makes it easy to plug the Raspberry Pi Zero into one and the powered USB hub into the other. Do not plug in the board just yet, you first need to connect the rest of the hardware and configure the microSD card. However, you are now ready to connect the rest of the hardware.

Hooking up a keyboard, mouse, and display

The next step is to connect a keyboard, mouse, and display to the Raspberry Pi Zero. You may have much of this stuff already but, if you don't, there are some things to consider before buying additional equipment. Let's start with the keyboard and mouse.

To connect any device to the Raspberry Pi Zero you'll need some sort of adapter or hub. You can buy a simple hub that goes from the microUSB connector on the Raspberry Pi Zero to the more common standard connector. You can find these at most electronics online retailers, and it looks something like this:

However, there will be projects when you will want to connect more than one device to the Raspberry Pi Zero. For these cases you may want to consider purchasing a powered USB hub. Before deciding on the hub to connect to your board, you need to understand the difference between a powered USB hub and one that gets its power from the USB port itself.