Raspberry Pi by Example

Raspberry Pi by Example

www.allitebooks.com Raspberry Pi By Example Start building amazing projects with the Raspberry Pi right out of the box Ashwin Pajankar Arush Kakkar BIRMINGHAM - MUMBAI www.allitebooks.com Raspberry Pi By Example 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 authors, 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: April 2016 Production reference: 1190416 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78528-506-6 www.packtpub.com www.allitebooks.com Credits Authors Copy Editors Ashwin Pajankar Stuti Srivastava Arush Kakkar Madhusudan Uchil Reviewers Project Coordinator Nathan Johnson Nikhil Nair Elliot Kermit-Canfield Anna Torlen Proofreader Safis Editing Commissioning Editor Dipika Gaonkar Indexer Priya Sane Acquisition Editor Ashwin Nair Graphics Kirk D'Penha Content Development Editor Merwyn D'souza Production Coordinator Shantanu N. Zagade Technical Editors Nirant Carvalho Cover Work Shantanu N. Zagade Mohit Hassija www.allitebooks.com About the Authors Ashwin Pajankar is a software professional and IoT enthusiast with more than 5 years' experience in software design, development, testing, and automation. He graduated from IIIT Hyderabad, earning an M.Tech in computer science and engineering. He holds multiple professional certifications from Oracle, IBM, Teradata, and ISTQB in development, databases, and testing. He has won several awards in college through outreach initiatives, at work for technical achievements, and community service through corporate social responsibility programs. He was introduced to Raspberry Pi while organizing a hackathon at his workplace, and he's been hooked on Pi ever since. He writes plenty of code in C, Bash, Python, and Java on his cluster of Pis. He's already authored one book on Raspberry Pi and reviewed three other titles related to Python for Packt Publishing. His LinkedIn Profile is at https://in.linkedin.com/in/ashwinpajankar. I would like to thank my wife, Kavitha, for motivating me to write this book and share my knowledge with others. I would like to thank my coauthor, Arush Kakkar, for taking over the project after the first few chapters. I also thank Merwyn D'Souza from Packt Publishing for providing me with the opportunity, guidance, and required support in writing this book. Last but not least, I would like to thank all the reviewers who helped me make the book better by providing their precious feedback. www.allitebooks.com Arush Kakkar is a computer vision and deep learning researcher and an undergraduate at Delhi Technological University. His primary focus is on autonomous robotics, which includes drones and self-driving cars, and he has been involved in building such systems in different capacities, such as navigation, localization, path planning. He has also leveraged state-of-the art computer vision and deep learning technologies for them. He is the electrical systems head of the Solar Car team of his university, Solaris DTU. He is currently working on his own driverless car company, CruiseX, which uses deep learning to drive more smoothly and with fewer errors. You can connect with him through his website at http://www.arushkakkar.com and read up on some of his projects at http://blog.arushkakkar.com. I would like to thank my parents for supporting me in writing this book. I would like to thank Ashwin for collaborating while writing this book, and I would also like to thank Merwyn from Packt Publishing for coordinating the collaboration. I am thankful to all the reviewers for helping me improve the book and expanding my knowledge. www.allitebooks.com About the Reviewers Nathan Johnson is an NC State University graduate and the author and maintainer of the node-arm project. Apart from node-arm, he has also contributed to several other Raspberry Pi projects. He currently works for the Charlotte-based company Red Ventures as a software engineer writing applications in Node.js. I would like to thank my mom, dad, and brother for reminding me to use all the talents I've been given. Elliot Kermit-Canfield is a graduate student studying computer music at the Center for Computer Research in Music and Acoustics at Stanford University. In addition to a degree in music, science, and technology from Stanford, he holds degrees in integrative arts and music theory from Penn State. Elliot is an avid computer musician and has worked with Raspberry Pi and other embeddable systems with audio applications. Anna Torlen is an artist, educator, and techie. She received a bachelor of arts degree in studio art at The College of Santa Fe and a master of fine arts degree in media, technology, and entertainment at Florida Atlantic University. She has worked on Raspberry Pi projects at her college and at Hacklab in Boynton Beach, FL. She has contributed to the Adafruit Community Corner blog. She is currently working at Palm Beach State College as a multimedia adjunct professor. She is interested in building outdoor solar-powered Internet of Things Raspberry Pi projects. www.allitebooks.com 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. TM 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 Packt • Copy and paste, print, and bookmark content • On demand and accessible via a web browser www.allitebooks.com www.allitebooks.com Table of Contents Preface vii Chapter 1: Introduction to Raspberry Pi and Python 1 Single-board computers 1 Raspberry Pi 3 Raspberry Pi models 3 Operating systems 7 Raspbian 8 Setting up the Raspberry Pi 8 Preparing MicroSD card manually 10 Booting up our Pi for the first time 14 Shutting down and rebooting Pi safely 17 Updating the Pi 18 Getting started with Python 19 Turtle programming with Python 24 Summary 28 Chapter 2: Minecraft Pi 29 Introduction to Minecraft Pi 29 Playing Minecraft Pi 30 Movement control in Minecraft Pi 34 Action control in Minecraft Pi 35 Other controls in Minecraft Pi 38 Python programming for Minecraft Pi 38 Summary 44 [ i ] www.allitebooks.com Table of Contents Chapter 3: Building Games with PyGame 45 Introducing PyGame 45 Installing PyGame 46 Drawing a binary fractal tree 47 Building a snake game 51 Summary 58 Chapter 4: Working with a Webcam and Pi Camera 59 Working with webcams 59 Crontab 61 Creating a timelapse sequence using fswebcam 62 Webcam video recording and playback 64 Working with the Pi Camera and NoIR Camera modules 66 Using raspistill and raspivid 68 Using picamera in Python with the Pi Camera module 71 The Pi camera versus the webcam 72 Summary 72 Chapter 5: Introduction to GPIO Programming 73 Introducing GPIO pins 74 Building an LED Blinker 76 Connecting a button 78 Installing PiGlow 80 Using PiGlow 83 Building a binary clock 85 Summary 89 Chapter 6: Creating Animated Movies with Raspberry Pi 91 Introducing stop-motion animation 91 Setting up the prerequisites 92 Setting up and testing the camera 93 Adding the hardware button 96 Rendering the video 98 Summary 99 Chapter 7: Introduction to Computer Vision 101 Introducing Computer Vision 102 Introducing OpenCV 102 Setting up Pi for Computer Vision 103 Testing the OpenCV installation with Python 106 [ ii ] Table of Contents Introducing NumPy 106 Array creation 107 Basic operations on arrays 107 Linear algebra 108 Working with images 109 Using matplotlib 112 Working with Webcam using OpenCV 114 Saving a video using OpenCV 116 Pi Camera and OpenCV 117 Retrieving image properties 117 Arithmetic operations on images 118 Splitting and merging image color channels 122 Negating an image 123 Logical operations on images 124 Colorspaces and conversions 126 Tracking in real time based on color 129 Summary 130 Chapter 8: Creating Your Own Motion Detection and Tracking System 131 Thresholding images 131 Otsu's method 134 Noise 136 Kernels for noise removal 136 2D convolution filtering 137 Low pass filtering 138 Morphological transformations on images 141 Motion detection and tracking 142 Summary 146 Chapter 9: Grove Sensors and the Raspberry Pi 147 Introducing the GrovePi 147

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    294 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us