-->
Navigation
Beginning Robotics with Raspberry Pi and Arduino: Using Python and OpenCV

Beginning Robotics with Raspberry Pi and Arduino: Using Python and OpenCV

Now pay Easier and Secure using Paypal
Price:

Read more

Jeff Cicolani


e-books shop
e-books shop
Purchase Now !
Just with Paypal



Book Details
 Price
 3.00 USD
 Pages
 372 p
 File Size
 8,118 KB
 File Type
 PDF format
 ISBN-13 (electronic) 
 ISBN-13 (pbk)
 978-1-4842-3462-4
 978-1-4842-3461-7
 Copyright   
 2018 by Jeff Cicolani  

About the Author

Jeff Cicolani currently lives in the Austin,
Texas, area with his wife, two dogs, and
dozen or so robots. He is currently working
as an embedded systems engineer, building
robotic and automated platforms for an AI
(artificial intelligence) company in Austin.
His journey to robotics was circuitous, taking
him through an odd career path that included
systems analysis and design and database
programming. In 2012, he joined The Robot
Group in Austin, where he joined a group of
robotics enthusiasts and began building robots as a hobby. In 2016, he
became president of The Robot Group. In this role, he leads the group in
their mission to promote STEM (science, technology, engineering, and
mathematics) education through robotics. He is currently working to
develop a better understanding of advanced robotics through ROS (the
robot operating system) and machine learning.

About the Technical Reviewer

Massimo Nardone has more than 22 years
of experiences in security, web/mobile
development, cloud, and IT architecture. His
true IT passions are security and Android.
He has been programming and teaching
how to program with Android, Perl, PHP, Java,
VB, Python, C/C++, and MySQL for more than 20 years.
He holds a Master of Science degree in
Computing Science from the University of Salerno, Italy.
He has worked as a project manager, software engineer, research
engineer, chief security architect, information security manager, PCI/
SCADA auditor, and senior lead IT security/cloud/SCADA architect for many years.
His technical skills include security, Android, cloud, Java, MySQL,
Drupal, Cobol, Perl, web and mobile development, MongoDB, D3, Joomla,
Couchbase, C/C++, WebGL, Python, Pro Rails, Django CMS, Jekyll, Scratch, and more.
He currently works as a chief information security officer (CISO) for
Cargotec Oyj. He worked as visiting lecturer and supervisor for exercises at
the Networking Laboratory of the Helsinki University of Technology (Aalto
University). He holds four international patents (PKI, SIP, SAML, and Proxy areas).

Introduction
Robotics does not have to be difficult. In this book, I introduce you to the
field of robotics. The journey will be challenging; it’s intended to be. But
by the end of the book, you will have hands-on exposure to many of the
fundamental—and not so fundamental—aspects of robotics. You will work
with hardware, assemble and solder a circuit board, write code in two
programming languages, install and configure a Linux environment, and
work with computer vision. Everything else you do with robots will be an
extension of the lessons learned in this book.

Chapter Overview
You start by learning about the Raspberry Pi and how to work with it. You
download and install the Raspbian operating system, and then configure
the Pi for our project. The goal is to set up your system to be able to easily
access your robot and write your code directly on it.
Once you are able to access your Pi remotely, in Chapter 3, you
delve into programming with Python. I’ll show you how to write simple
programs on the Raspberry Pi. I also take you beyond the basics and cover
some intermediate topics, such as modules and classes. This is one of the
longest chapters since there is a lot of material to cover.
From there, you learn how to interface the Raspberry Pi with external
electronics, such as sensors and LEDs, through the Pi’s GPIO header.
Chapter 4 discusses the different ways of addressing the pins on the
header, some of the functionality exposed through the header, and how to
use an ultrasonic rangefinder to detect objects. This gets you ready for the
next chapter, which introduces the Arduino.
In Chapter 5, you connect the Arduino to the Raspberry Pi. I discuss
some of the reasons you want to do this. I show you how to work with the
Arduino IDE to write programs. I cover serial communication between the
two boards and how to pass information back and forth between them. We
do this using the same ultrasonic rangefinder used in the previous chapter.
Chapter 6 has you turning motors with your Raspberry Pi. You use a
special board called a hat, or plate, to control the motors. This is where I
introduce another skill that you will inevitably need in robotics: soldering.
The header and terminals need to be soldered on to the board that was
selected for this purpose. The nice thing about soldering headers and
terminal blocks is that it’s hard to damage anything, and you will get plenty of practice.
Chapter 7 is where we bring it all together. You build the robot, and I
discuss some of the physical characteristics of robotics. I cover some of
the design considerations that you will need to keep in mind when you
design your own chassis. Although I am listing a specific chassis kit for this
project, you do not need to use the same one. In fact, I encourage you to
explore other options to find the one that is right for you.
In Chapter 8, I introduce another type of sensor—the IR sensor, and
I show you how to use a very common control algorithm called a PID
controller. I talk about the various types of IR sensors and where you want
to use them. (The chapter on PID control discusses what it is and why you want to use it.)
Chapter 9 is about computer vision, where you see the true power of
the Raspberry Pi. In this chapter, I cover an open source package called
OpenCV. By the end of Chapter 9, your little robot will be chasing a ball
around the table.
I leave you with some parting thoughts in Chapter 10. I provide a few
tips that I picked up, and I give you a glimpse into my workflow and tools.
After that, you will be ready to begin your own adventures in robotics.
Table of Contents
About the Author .................................................................................xi
About the Technical Reviewer ...........................................................xiii
Introduction ........................................................................................xv
Chapter 1: Introduction to Robotics
Robotics Basics .....................................................................................................2
Linux and Robotics ..........................................................................................3
Sensors and GPIO ............................................................................................4
Motion and Control ..........................................................................................5
Raspberry Pi and Arduino .....................................................................................5
Project Overview ...................................................................................................8
The Robot ........................................................................................................8
Bill of Materials (BOM) ....................................................................................9
Summary ............................................................................................................15
Chapter 2: An Introduction to Raspberry Pi 
Downloading and Installing Raspbian .................................................................17
Raspbian with OpenCV ..................................................................................19
The “Hard” Way .............................................................................................19
The “Easy” Way .............................................................................................22
Connecting Raspberry Pi .....................................................................................24
Configuring Your Pi ..............................................................................................26
Using raspi-config .........................................................................................27
Users .............................................................................................................34
Connecting to a Wireless Network ................................................................37
Going Headless ...................................................................................................37
Remote Access ..............................................................................................38
Summary ............................................................................................................45
Chapter 3: A Crash Course in Python
Python Overview .................................................................................................49
Downloading and Installing Python .....................................................................49
Python Tools ........................................................................................................50
The Python Shell ............................................................................................51
The Python Editor ..........................................................................................52
The Zen of Python ..........................................................................................55
Writing and Running a Python Program ..............................................................56
Hello World ....................................................................................................57
Basic Structure ..............................................................................................58
Running a Program ........................................................................................61
Programming in Python ......................................................................................61
Variables ........................................................................................................62
Data Types .....................................................................................................62
A Final Note on Variables ...............................................................................74
Control Structures .........................................................................................75
Functions .......................................................................................................81
Adding Functionality through Modules ..........................................................85
Classes ..........................................................................................................91
Styling ...........................................................................................................99
Summary ..........................................................................................................101
Chapter 4: Raspberry Pi GPIO
Raspberry Pi GPIO .............................................................................................103
Pin Numbering .............................................................................................105
Connecting to the Raspberry Pi ...................................................................106
Limitations of Raspberry Pi’s GPIO ..............................................................107
Accessing GPIO with Python ........................................................................108
Simple Output: LED Example .......................................................................110
Simple Input ................................................................................................117
Summary ..........................................................................................................127
Chapter 5: Raspberry Pi and Arduino
Raspberry Pi’s GPIO in Review ..........................................................................130
Real-Time or Near Real-Time Processing ...................................................130
Analog Input ................................................................................................131
Analog Output ..............................................................................................131
Arduino to the Rescue .......................................................................................132
Using Arduino ....................................................................................................134
Installing the Arduino IDE ............................................................................135
Connecting an Arduino ................................................................................135
Programming Arduino ..................................................................................136
Sketches ......................................................................................................145
A Brief Introduction to the Arduino Language ...................................................149
Including Other Files ....................................................................................150
Variables and Data Types .............................................................................150
Control Structures .......................................................................................155
Working with Pins ........................................................................................162
Objects and Classes ....................................................................................167
Serial ...........................................................................................................167
Arduino to Pi and Back Again ......................................................................171
Pinguino ............................................................................................................181
Setting up the Circuit ...................................................................................182
Summary ..........................................................................................................185
Chapter 6: Driving Motors
Motors & Drivers ...............................................................................................188
Types of Motors ...........................................................................................188
Motor Properties ..........................................................................................192
Motor Drivers ...............................................................................................195
Working with Motor Controllers ........................................................................195
Adafruit DC & Stepper Motor HAT ................................................................196
L298N Generic Motor Driver ........................................................................217
Summary ..........................................................................................................228
Chapter 7: Assembling the Robot
Assembling the Chassis ....................................................................................230
Choosing a Material .....................................................................................230
The Whippersnapper ...................................................................................231
Mounting the Electronics ..................................................................................239
Wiring ................................................................................................................246
Mounting Sensors .............................................................................................249
The Finished Robot ...........................................................................................252
Making the Robot Mobile .............................................................................253
Summary ..........................................................................................................266
Chapter 8: Working with Infrared Sensors
Infrared Sensors ...............................................................................................267
Types of IR Sensors .....................................................................................268
Working with IR Sensors ...................................................................................272
Connecting an IR Sensor .............................................................................273
Mounting the IR Sensors .............................................................................276
The Code ......................................................................................................278
Understanding PID Control ................................................................................289
Control Loops ..............................................................................................289
Implementing the PID Controller .................................................................292
Summary ..........................................................................................................296
Chapter 9: An Introduction to OpenCV
Computer Vision ................................................................................................297
OpenCV ........................................................................................................299
Selecting a Camera .....................................................................................302
Installing the Camera ..................................................................................304
OpenCV Basics ..................................................................................................305
Working with Images ...................................................................................306
Capturing Images ........................................................................................308
Image Transformations ................................................................................316
Working with Color ......................................................................................319
Blobs and Blob Detection ............................................................................325
Ball-Chasing Bot ...............................................................................................333
Summary ..........................................................................................................340
Chapter 10: Conclusion
Types of Robotics ..............................................................................................344
Tools .................................................................................................................344
Software ......................................................................................................345
Hardware .....................................................................................................351
Summary .....................................................................................................354
Index .................................................................................................355

Bookscreen
e-books shop

Who This book Is For
This book is for those who are new to electronics and IoT; those who have
never used a Raspberry Pi or Arduino separately, let alone together.
This book is for the hobbyist who is interested in learning a little more
about working with robots. Perhaps you’ve built a few circuits with an
Arduino or a custom home entertainment system with a Raspberry Pi, and
now you are curious about what goes into building a robot. You will learn
how these two devices work together to provide very powerful capabilities.
This book is for the entrepreneur who needs to learn more about
technology; someone who doesn’t necessarily have the time to read through
many different books on Arduino, Raspberry Pi, electronics, or programming;
someone who is looking for a broad yet condensed introduction to some of the fundamentals.

This book is also for the student who wants to take their robot-building
experience beyond bricks and puzzle-piece programming; someone who
wants to work with hardware and software that more closely resembles
what they might see in college or in the professional world.

No assumptions are made about experience or background in
technology. As you go through the chapters, you may find parts that you
are already familiar with, and you can skip ahead. But if you are new to
these topics, I try to provide you with a quick but easy introduction.

0