9780789755384
9780789755384
9780789755384
John Baichtal
Editor-in-Chief
Hacking Your LEGO® Mindstorms® EV3 Kit
Greg Wiegand
Executive Editor
Copyright © 2016 by John Baichtal
Rick Kughen
All rights reserved. No part of this book shall be reproduced, stored in
a retrieval system, or transmitted by any means, electronic, mechanical, Development Editor
photocopying, recording, or otherwise, without written permission from Susan Arendt
the publisher. No patent liability is assumed with respect to the use of
the information contained herein. Although every precaution has been Managing Editor
taken in the preparation of this book, the publisher and author assume Sandra Schroeder
no responsibility for errors or omissions. Nor is any liability assumed for
damages resulting from the use of the information contained herein. Project Editor
Proofreader
Trademarks Jess DeGabriele
All terms mentioned in this book that are known to be trademarks or
service marks have been appropriately capitalized. Que Publishing cannot Technical Editor
attest to the accuracy of this information. Use of a term in this book should James Floyd Kelly
not be regarded as affecting the validity of any trademark or service mark.
LEGO® and MINDSTORMS® are registered trademarks of The LEGO Editorial Assistant
Group. This book is not authorized or endorsed by the LEGO® Group. Kristen Watterson
Designer
Warning and Disclaimer Mark Shirar
Every effort has been made to make this book as complete and as accurate
as possible, but no warranty or fitness is implied. The information provided Compositor
is on an “as is” basis. The author and the publisher shall have neither Studio GaLou
liability nor responsibility to any person or entity with respect to any loss or
damages arising from the information contained in this book.
Special Sales
For information about buying this title in bulk quantities, or for special
sales opportunities (which may include electronic versions; custom
cover designs; and content particular to your business, training goals,
marketing focus, or branding interests), please contact our corporate sales
department at [email protected] or (800) 382-3419.
For government sales inquiries, please contact governmentsales@
pearsoned.com.
For questions about sales outside the U.S., please contact international@
pearsoned.com.
iii
Contents at a Glance
CHAPTER 1 Introduction 1
CHAPTER 2 Project: Plotter Bot 7
CHAPTER 3 Hacking LEGO I: Connections 51
CHAPTER 4 Project: Remote-Controlled Crane 63
CHAPTER 5 Hacking LEGO II: Alternate Controllers 105
CHAPTER 6 Project: Robot Flower 123
CHAPTER 7 Hacking LEGO III: Create Your Own LEGO Parts 157
CHAPTER 8 Project: Ball Contraption 177
CHAPTER 9 Hacking LEGO IV: Add-on Electronics 239
CHAPTER 10 Project: Flagpole Climber 259
Glossary 303
Index 307
iv Hacking Your LEGO Mindstorms EV3 Kit
Table of Contents
Chapter 1 Introduction 1
Hacking Mindstorms 2
Chapter Topics 6
Chapter 2 Project: Plotter Bot 7
Parts List 8
Building the Plotter Bot 9
Program the Plotter Bot 43
Moving the Motors 44
A Simple Program 45
Resetting the X Axis 47
Hacking Opportunities 49
Summary 49
Chapter 3 Hacking LEGO I: Connections 51
Mindstorms Wires Explained 51
Inside the Mindstorms Wire 52
Hacking Mindstorms Wires 53
Exploring Wireless Options 56
Infrared Sensor and Beacon 56
Bluetooth 57
Hacking Wireless 58
Summary 62
Chapter 4 Project: Remote-Controlled Crane 63
Parts List 64
Building the Crane 65
Programming the Crane 93
Controlling the Crane with Infrared 98
Using Your Phone’s Commander App 98
Summary 104
Chapter 5 Hacking LEGO II: Alternate Controllers 105
Microcontrollers and Microcomputers 106
Arduino 106
Raspberry Pi 108
BeagleBone Black 110
But Why? 112
Example Projects 114
Book Reader 114
Mini Tank 115
Chocolate Milk Maker 116
Ball Counting Robot 117
Rolling Alarm Robot 118
BeagleBone Black Robot 119
Programing Environments 120
Table of Contents v
LeJos 121
RobotC 121
Monobrick 121
ev3dev 121
Summary 122
Chapter 6 Project: Robot Flower 123
Robot Flower Mindstorms Build 124
Parts List 124
Steps 125
Program the Robot Flower 146
Substituting the Arduino 150
Quick and Dirty Arduino 151
Parts 152
Steps 153
Programming the Arduino 154
Summary 155
Chapter 7 Hacking LEGO III: Create Your Own LEGO Parts 157
Designing Your Own Parts 158
Check Your Dimensions 159
Create the Design File 160
Output and Iterate 161
Finding Designs 161
Thingiverse 162
LDraw 163
SketchUp Warehouse 163
Outputting Your Own Parts 164
CNC Mill 164
Laser Cutter 167
3D Printer 170
Tip: Parametric 3D Models 175
Summary 176
Chapter 8 Project: Ball Contraption 177
Building the Contraption 178
Parts List 178
Steps 179
Program the Contraption 224
Creating Your Own Parts 225
The Baseplate 226
The Gear 233
Summary 237
Chapter 9 Hacking LEGO IV: Add-on Electronics 239
Motors and Wheels 240
Motor Driver 240
Omni-Wheels 240
8-Channel Servo Controller 241
vi Hacking Your LEGO Mindstorms EV3 Kit
Index 307
About the Author vii
Dedication
This book is dedicated to my wife Elise, my kids Arden, Rosemary, and Jack, my mom Barbara, and to all
those who strive to make an item or platform work better for them by hacking it!
Acknowledgments
Thanks for the inspiration and assistance (in no particular order) to Miguel Valenzuela,
Pete McKenna, Steve Norris, Steven Anderson, MakerBeam, Jude Dornisch, SparkFun
Engineering, Adam Wolf, Michael Freiert, Sophi Kravitz, Christina Zhang, Lenore Edman,
Rick Kughen, Sean Michael Ragan, John Wilson, Susan Solarz, Akiba, Mark Frauenfelder,
Chris Berger, Michael Krumpus, Alex Dyba, Brian Jepson, Becca Steffen, Dave Bryan,
Actobotics, Mike Hord, Makeblock, Pat Arneson, Erin Kennedy, Mindsensors, Windell H.
Oskay, Johngineer, Matthew Beckler, Riley Harrison, David Lang, Trammell Hudson, Kristina
Durivage, AnnMarie Thomas, Pete Prodoehl, Bruce Shapiro, Alex Allmont, John Edgar Park,
and Dexter Industries. Apologies to anyone I forgot!
viii Hacking Your LEGO Mindstorms EV3 Kit
Reader Services
Visit our website and register this book at quepublishing.com/register for convenient access
to any updates, downloads, or errata that might be available for this book.
This page intentionally left blank
3
Hacking LEGO I: Connections
Mindstorms’ components consist of modules linked together. The motors connect to the
Intelligent Brick but not directly—they use wires to link the power and data of both modules
together. Those linkages are themselves fascinating. This chapter explores what’s up with those
Mindstorms wires and demonstrates how to hack them into different configurations. Then, I
describe some of the common methods Mindstorms hackers employ to control and connect
components without using wires.
FIGURE 3.1 Mindstorms cables’ off-center tabs are all that differentiate them
from RJ12s.
Not surprisingly, these three sizes aren’t good for everyone, so some established suppliers
have come up with different wire sets:
■ HiTechnic’s NXT Extended Connector Cable Set (P/M NWS1000) includes six cables,
ranging in length from 120mm (4.7-inch) to 900mm (35.4-inch). You can buy the set
at hitechnic.com.
■ Mindsensors’ Flexi-Cable pack (P/N FLEX-Nx) includes four cables: 200mm, 350mm,
and 500mm just like regular LEGO cables. However, Mindsensors’ cables have thinner
and more flexible insulation, allowing them to move around and bend more readily than
LEGO’s stiffer wires. You can buy the Flexi-Cables at mindsensors.com.
1. The blue wire is the SDA (serial data) wire, one-half of a two-wire data transfer protocol
called I^2C. EV3 can transmit sensor data and commands through the I^2C bus.
2. Yellow is the SCL (serial clock) wire, the other half of the protocol.
3. Green is power, typically delivering either 3.3 or 5V from the EV3’s battery pack. You can
use this wire to power electronic circuitry and add-on modules.
4. Red is ground. Creating a circuit with the power pin and this ground yields 5V.
5. Black is also ground. A circuit with this ground and the power pin yields 3.3V.
6. White is analog, transmitting analog sensor signals back to the EV3 Intelligent Brick.
Knowing the purpose of each wire helps you hack them, and it never hurts to understand
what’s going on under the insulation.
I^2 C Data
I^2 C Clock
Power
Gnd
Gnd
Analog
FIGURE 3.2 The Mindstorms wire actually consists of six smaller wires.
FIGURE 3.3 To alter a Mindstorms wire, just cut it apart and solder it back
together.
FIGURE 3.4 To access the inner wires individually, use a breakout board.
Mindstorms Wires Explained 55
The sensor has one added feature that most IR receivers lack: It can be used as a proximity
sensor, beaming out infrared light and sensing as it bounces back. This feature has a
short range compared to other proximity sensors (for example, ultrasonic), and can detect
proximity only within 50cm to 70cm, or around 2 to 3 inches.
The beacon is what LEGO calls its remote control, and this is not just for fun: One of the
projects described in the EV3 set is an IR-homing robot that wanders around until it senses
the infrared signal from the beacon and rolls toward it. The controller’s range is only about
2 meters, unfortunately.
FIGURE 3.6 The infrared sensor and beacon give you simple wireless control of
your robot.
Bluetooth
Another intriguing option is the EV3 brick’s Bluetooth capabilities. The Intelligent Brick
has a Bluetooth chip on-board, allowing it to connect to other EV3 bricks as well as take
commands from smartphones using an application called the Commander, which includes
preset control configurations for the five sample robots that are part of the EV3 set (see
Figure 3.7). You can also create an interface for a custom robot, pulling out sliders and
buttons from a library to match what you’re building.
EV3’s Bluetooth capability also allows you to control the Intelligent Brick from your PC or
Mac wirelessly, just as if you had it plugged in with a Bluetooth cable.
58 CHAPTER 3: Hacking LEGO I: Connections
Finally, one cool aspect of the robot, both in terms of Bluetooth and regular wiring, is you
can link up to four EV3 bricks together if you want to build a gloriously complicated robot.
FIGURE 3.7 LEGO’s Bluetooth app allows you to control robots wirelessly.
Hacking Wireless
It almost goes without saying that Mindstorms fans have figured out how to control their
robots in ways not officially supported by LEGO. Here are just a few ways to wirelessly
control your Mindstorms robot.
XBee
A common hobbyist and professional wireless specification is called Zigbee, and XBee is a
brand of wireless modules built to that spec. Dexter Industries (dexterindustries.com) sells a
Exploring Wireless Options 59
Mindstorms-compatible XBee breakout called the NXTBee, though I’m not sure whether it’s
compatible with EV3 yet. Another technique is to ditch the EV3 brick altogether and use an
Arduino: Check out the cool LEGO bracer shown in Figure 3.8. It has an Arduino, battery
pack, XBee, and Wii nunchuk, allowing me to operate a robot with a wearable controller.
SparkFun sells XBee radios (P/N 8665) as well as its own flavor of breakout board.
FIGURE 3.8 This wireless controller combines LEGO, Wii, and Arduino.
Radio Control
Normal radio control (RC) technology doesn’t mesh well with Mindstorms, but it can
be made to work. RC flight electronics consist (in their most basic configuration) of a
radio, shown in Figure 3.9, as well as a receiver. The receiver interprets the data from the
transmitter and triggers pins that tell the motors what to do. Not surprisingly, those same
pins can trigger Arduino actions or could be used to bump Mindstorms touch sensors with
a servo.
60 CHAPTER 3: Hacking LEGO I: Connections
PlayStation Controller
Mindsensors.com and a couple of other places sell a wireless controller that consists of
a PlayStation 2 (PS2) interface card that plugs into the EV3 Intelligent Brick—onto which
a wired PS2 controller may connect (see Figure 3.10). Mindsensors also sells a 2.4Ghz
wireless PS2 controller and a matching dongle that plugs into that interface card, allowing
you to wirelessly control your robot.
Exploring Wireless Options 61
FIGURE 3.10 Mindsensors’ PS2 adapter lets you control your model with a game
controller.
FIGURE 3.11 The NetGear WNA1100 is the only Wi-Fi dongle that works with
the EV3.
62 CHAPTER 3: Hacking LEGO I: Connections
Summary
This chapter is all about connections: hacking Mindstorms wires and playing around
with wireless options such as infrared, radio control, and Wi-Fi. In Chapter 4, “Project:
Remote-Controlled Crane,” you put this knowledge to good use, making a rolling crane that
responds to a variety of wireless control methods.
This page intentionally left blank
Index
Symbols B breakout boards, 54
BrickPi
3D printers, 170-174 backlights, 239
installing, 292-294, 297-301
5x3 bricks, 157-158 Ball Contraption project, 177
mounting plates, 169-170
8-channel servo controller, 241 building instructions, 179-223
shield, 62, 110
80/20 interface, 173 creating bricks, 225
Book Reader project,
baseplate, 226-232 114-115
A gear, 233-237 bricks, creating, 157-158
absolute IMU-ACG (accelerom- parts list, 178-179 Ball Contraption project, 225
eter), 250-251 programming instructions, baseplate, 226-232
accelerometers, 250-251 224-225
gear, 233-237
alternatives to EV3. See controllers Ball Counting Robot project,
designing parts, 158
aluminum bricks, 166-167 117-118
dimensions, 159
Arduino baseplate, creating (Ball
Contraption project), 226-232 output and iteration stages,
Ball Counting Robot project, 161
117-118 BeagleBone Black (BBB)
software for design files,
Bricktronics shield, 107-108 components of, 110-111
160
components of, 106-107 EVB cape, 112
finding designs, 161-164
Mini Tank project, 115-116 Gyro Boy project, 119-120
parametric 3D models, 175
resources for information, beams, curved, 161-162
tools for output, 164
151-152 black wires, 53
3D printers, 170-174
Robot Flower project, 150-155 blue wires, 53
CNC mills, 164-167
building instructions, 153 Bluetooth controls
laser cutters, 167-170
parts list, 152 explained, 57-58
Brickstuff
programming instructions, Remote-Controlled Crane
light strands, 245
154-155 project, 98-103
proximity sensor, 247-248
Arduino-to-LEGO interface pieces, Book Reader project, 114-115
169 Bricktronics, 240
breadboard-to-PF hybrid wires,
55-56 shield, 3, 107-108
Mini Tank project, 115-116
308 Budel, Tristram
Budel, Tristram, 166-167 Wi-Fi dongles, 61 reasons for using EV3 alter-
building instructions XBee modules, 58-59 natives, 112-114
Ball Contraption project, wires relay drivers, 256
179-223 breadboard-to-PF hybrid Rolling Alarm Robot
Flagpole Climber project, wires, 55-56 project, 118-119
262-287 breakout boards, 54 sBrick, 256-257
Plotter Bot project, 9-43 changing length of, XBee modules, 258
Raspberry Pi and BrickPi 53-54 crane project. See Remote-
installation, 294-298 components of, 52-53 Controlled Crane project
Remote-Controlled Crane length of, 51-52 Creative Robotics, Hub-ee
project, 65-92 controllers, 105 wheels, 242
Robot Flower project, Arduino curved beams, 161-162
125-146 Customizable Technic Hub,
Bricktronics shield,
Arduino version, 153 107-108 175
components of, 106-107
C resources for informa-
D
C programming language, tion, 151-152 dCompass module, 3-4
RobotC, 121 Robot Flower project, designing bricks, 158
cables. See wires 150-155 dimensions, 159
Cailliau, Robert, 159 Ball Counting Robot finding designs, 161-164
project, 117-118
cameras, Pixy, 248-249 output and iteration stages,
BeagleBone Black 161
capes, 111
components of, 110-111
Cartesian coordinates, 43-44 parametric 3D models, 175
EVB cape, 112
changing wire length, 53-54 software for design files,
Book Reader project, 160
Chocolate Milk Maker project, 114-115
116-117 tools for output, 164
Chocolate Milk Maker
Chronodot, 113-114 3D printers, 170-174
project, 116-117
CNC (computer-numerically Gyro Boy project, 119-120 CNC mills, 164-167
controlled) mills, 164-167 laser cutters, 167-170
Mini Tank project, 115-116
Commander app, 57 Dexter Industries
PlayStation controller
Remote-Controlled Crane interface, 257 BrickPi installation, 292
project, 98-103
programming environ- dGPS, 246-247
connections ments, 120 dLights, 244-245
wireless LeJos, 121 dPressure, 251
Bluetooth controls, Monobrick, 121 NXTBee, 58
57-58
RobotC, 121 thermal infrared sensor, 252
BrickPi shield, 62 Raspberry Pi, 291 XBee modules, 258
IR (infrared) controls, BrickPi shield, 110
56-57 dGPS sensor, 246-247
components of, 108-109 dimensions, designing bricks,
PlayStation controllers,
60-61 installing, 292-294, 159
297-301
RC (radio control) dLights, 244-245
technology, 59-60 instructional overview,
292
Makeblock Constructor 309
dPressure sensor, 251 Grove Sensor Adapter, 246 Universal Connector Kit,
drawing pens. See Plotter Bot Gyro Boy project, 119-120 172
project IR (infrared) controls.
H See infrared (IR)
E hacking suggestions
controls
iteration stage (designing
ecosystems for hardware and Plotter Bot project, 49 bricks), 161
code, 113
wireless controls
Education set. See LEGO
Education
BrickPi shield, 62 J-L
PlayStation controllers, Janssen, Jorg, 157
education usage, 113
60-61 Java, LeJos programming envi-
EV3, alternatives to.
RC (radio control) tech- ronment, 121
See controllers
nology, 59-60
EVB cape, 112
Wi-Fi dongles, 61 Klann linkage, 165-166
Gyro Boy project, 119-120
XBee wireless modules,
58-59
F wires
laser cutters, 167-170
finding brick designs, 161-164 LazerStorm mounting plates,
breadboard-to-PF hybrid 168
Flagpole Climber project, wires, 55-56
259-260 LDraw, 163
breakout boards, 54
building instructions, LEGO bricks. See bricks,
changing length of, creating
262-287 53-54
installing ultrasonic sensor, LEGO Education, 252
HiTechnic NXT Extended
289 Connector Cable Set, 52 NXT temperature sensor,
parts list, 260-261 253-254
Hub-ee wheels, 242
programming instructions, pneumatics add-on set,
288 I 252-253
programming ultrasonic LeJos, 121
infrared (IR) controls
sensor, 290-291 length of wires
Remote-Controlled Crane
Raspberry Pi and BrickPi changing, 53-54
project, 98
installation, 292-301 standard lengths, 51-52
sensors and beacons, 56-57
troubleshooting, 301 libraries, 107
Inkscape, 160
Flexi-Cables, 52 lighting
installing
Flower project. See Robot backlights, 239
Flower project BrickPi, 292-301
Brickstuff light strands, 245
Raspberry Pi, 292-301
G ultrasonic sensor (Flagpole
NXT light sensor, 253
Climber project), 289 RGB LED modules, 244-245
gear, creating (Ball
Contraption project), interface pieces linear actuators, 242-243
233-237 80/20 interface, 173 Linux, 112
GoPro camera mount, 171-172 Arduino-to-LEGO pieces,
green wires, 53 169 M
PlayStation controller inter- Makeblock building set, 4
face, 257 Makeblock Constructor, 170
310 McFarlan, Stuart