Table of Contents
Acknowledgments xiii
Foreword xiv
Introduction xv
Why Build And Learn About Robots? xvi
Why The Raspberry Pi? xvii
What Is In This Book? xvii
Who Is This Book For? xix
Where Should You Buy Parts? xix
Let's Get Started! xx
Chapter 1 Getting Up And Running 1
Get Your Hands On A Raspberry Pi 2
Your First Taste Of Pi 4
What You'll Need 6
Setting Up Your Raspberry Pi 8
Installing Your Pi's Operating System On Windows/Macos 8
Plugging In And Wiring Up Your Raspberry Pi 12
Installing Raspbian 14
Configuring Raspbian 15
The Terrific World Of The Terminal 17
Touring The Terminal 18
Accessing Your Raspberry Pi From Another Computer 21
What Is Programming? 25
Introducing Python 25
Writing Your First Python Program 26
Summary 28
Chapter 2 Electronics Basics 29
What Is Electricity? 30
Resistance 32
Ohm's Law Of Electricity 33
Making An Led Blink: Raspberry Pi Gpio Output 33
The Parts List 34
Wiring Up Your Led 37
Programming Your Raspberry Pi To Blink Your Led 39
Running Your Program: Make Your Led Blink 42
Challenge Yourself: Change The Timing 43
Input From A Button: Raspberry Pi Gpio Input 43
Explaining The Parts List 44
Wiring Up Your Button 44
Programming Your Raspberry Pi To Display Input From Your Button 46
Running Your Program: Get Input From Your Button 47
Challenge Yourself: Combine Your Button And Led Programs 48
Summary 48
Chapter 3 Building Your Robot 49
Your First Robot 50
What You'll Need 51
Chassis 52
Motors 54
Batteries 57
Voltage Regulator 58
Motor Controller 59
Recommended Tools 60
Assembling Your Robot 60
Making The Chassis 60
Attaching The Motors 62
Stabilizing The Robot 63
Attaching The Batteries 65
Mounting The Raspberry Pi, Breadboard, And Buck Converter 66
Wiring Up Power To The Raspberry Pi 67
Wiring Up The Motors 71
Summary 78
Chapter 4 Making Your Robot Move 79
The Parts List 80
Understanding The H-Bridge 80
First Movement 81
Programming Your Robot With A Predefined Route 81
Running Your Program: Make Your Robot Move 84
Making Your Robot Remote-Controlled 87
The Wiimote Wireless Controller 87
Installing And Enabling Bluetooth 88
Programming Remote Control Functionality 90
Running Your Program: Remote-Control Your Robot 92
Varying The Motor Speed 93
Understanding How PWM Works 93
Understanding The Accelerometer 95
Looking At The Data 96
Figuring Out The Remote Movement Control 97
Programming Your Robot For Variable Speed 99
Running Your Program: Remote-Control Your Robot With PWM 101
Challenge Yourself: Refine Your Remote-Controlled Robot 101
Summary 102
Chapter 5 Avoiding Obstacles 103
Obstacle Detection 104
Using Ultrasonic Sensors For Analog Object Detection 104
Understanding How The HC-SR04 Works 105
Measuring A Short Distance 106
The Parts List 106
Reducing Voltage With Voltage Dividers 107
Wiring Up Your HC-SR04 109
Programming Your Raspberry Pi To Read Distance 112
Running Your Program: Measure A Short Distance 114
Make Your Robot Avoid Obstacles 115
Mounting Your HC-SR04 Ultrasonic Sensor 115
Programming Your Robot To Avoid Obstacles 116
Running Your Program: Make Your Robot Avoid Obstacles 119
Challenge Yourself: Improve The Obstacle Avoidance Program 119
Summary 120
Chapter 6 Customizing With Lights And Sound 121
Adding Neopixels To Your Raspberry Pi Robot 122
Introducing Neopixels And The RGB Color System 122
The Parts List 124
Wiring Up Your Neopixel Stick 125
Installing The Software 127
Configuring The Library's Example Code 129
Running The Example Code 132
Controlling Neopixels Using The Wilmote Program 132
Running Your Program: Neopixels And Wiimote Control 135
Challenge Yourself: Experiment With Color And Pattern 135
Adding A Speaker To Your Raspberry Pi Robot 136
Understanding How 3.5 Mm Speakers Work 136
Connecting Your Speaker 137
Adding A Car Horn To The Wiimote Program 138
Installing The Software 138
Playing Sounds From The Terminal 140
Playing Sound Using The Wiimote Program 141
Running Your Program: Neopixels, Sound Effects, And The Wiimote Control 142
Adding Beeping To The Obstacle Avoidance Program 142
Integrating The Beep Sound Into The Obstacle Avoidance Program 142
Running Your Program: Beeping Obstacle Avoidance 143
Challenge Yourself: Add Sound Effects To Your Other Projects 143
Summary 144
Chapter 7 Line Following 145
Creating A Track 146
The Theory Behind Line Following 149
Using An Ir Sensor To Detect A Line 153
The Parts List 153
Wiring Up Your Tcrt5000 Line-Following Sensor Module 155
Programming Your Raspberry Pi To Detect A Line 156
Running Your Program: Detect A Line! 157
Make Your Robot Follow A Line Autonomously 158
Wiring Up The Second TCRT5000 Line-Following Sensor Module 158
Mounting Your Sensors 159
Programming Your Robot To Follow A Line 160
Running Your Program: Make Your Robot Follow A Line! 162
Summary 164
Chapter 8 Computer Vision: Follow A Colored Ball 165
The Computer Vision Process 166
The Parts List 167
The Target: A Colored Ball 167
The Official Raspberry Pi Camera Module 168
Connecting And Setting Up Your Camera Module 169
Mounting Your Camera 171
Enabling The Camera And VNC, And Setting The Screen Resolution 172
Taking A Test Photo 174
Controlling Your Pi's Desktop Remotely With VNC 175
Installing And Making A Connection With VNC Viewer 175
Taking And Viewing A Photo Using The Raspberry Pi Camera Module 177
Make Your Robot Seek And Follow A Ball 179
Understanding The Theory Behind Colored-Object Recognition 179
Installing The Software 183
Identifying The HSV Color Of Your Colored Ball 183
Running The HSV Test Program 184
Programming Your Raspberry Pi To Follow A Ball 185
Running Your Program: Make Your Robot Follow A Colored Ball! 192
Summary 194
Next Steps 195
The Raspberry Pi GUY 196
Get In Touch! 196
Other Websites 197
Clubs And Events 198
Books And Publications 199
Raspberry Pi GPIO Diagram 200
Resistor Guide 202
How To Solder 204
What You Need 205
Solder 205
Soldering Iron 206
Stand And Soldering Tip Cleaner 207
Soldering Components Together 209
Preparing To Solder 210
Tinning The Tip 210
Setting Up The Components 211
Soldering The Perfect Joint 212
Summary 214
Run Program On Startup 215
Editing The Rc.Local File 216
A Practice Example 217