The Art of LEGO MINDSTORMS NXT-G Programming

( 3 )


The LEGO® MINDSTORMS® software and its NXT-G programming language are powerful tools that make it easy to write custom programs for your robots. NXT-G is a great first programming language, but that doesn't mean it's easy to understand—at least not right away.

In The Art of LEGO MINDSTORMS NXT-G Programming, author and experienced software engineer Terry Griffin explains how to program MINDSTORMS robots with NXT-G. You'll learn how to work with the core parts of the NXT-G ...

See more details below
$26.81 price
(Save 10%)$29.95 List Price
Other sellers (Paperback)
  • All (11) from $11.68   
  • New (6) from $15.96   
  • Used (5) from $11.68   
The Art of LEGO MINDSTORMS NXT-G Programming

Available on NOOK devices and apps  
  • NOOK Devices
  • Samsung Galaxy Tab 4 NOOK 7.0
  • Samsung Galaxy Tab 4 NOOK 10.1
  • NOOK HD Tablet
  • NOOK HD+ Tablet
  • NOOK eReaders
  • NOOK Color
  • NOOK Tablet
  • Tablet/Phone
  • NOOK for Windows 8 Tablet
  • NOOK for iOS
  • NOOK for Android
  • NOOK Kids for iPad
  • PC/Mac
  • NOOK for Windows 8
  • NOOK for PC
  • NOOK for Mac
  • NOOK for Web

Want a NOOK? Explore Now

NOOK Book (eBook)
$13.49 price
(Save 43%)$23.95 List Price


The LEGO® MINDSTORMS® software and its NXT-G programming language are powerful tools that make it easy to write custom programs for your robots. NXT-G is a great first programming language, but that doesn't mean it's easy to understand—at least not right away.

In The Art of LEGO MINDSTORMS NXT-G Programming, author and experienced software engineer Terry Griffin explains how to program MINDSTORMS robots with NXT-G. You'll learn how to work with the core parts of the NXT-G language, such as blocks, data wires, files, and variables, and see how these pieces can work together. You'll also learn good programming practices, bad habits to avoid, and useful debugging strategies.

As you follow along with the book's extensive instructions and explanations, you'll learn exactly how NXT-G works and how to:

  • Write custom programs that make your robots appear to think and respond to your commands
  • Design, create, and debug large programs
  • Write programs that use data wires and the NXT buttons to turn a robot into a contraption, like a sound generator or a sketch pad
  • Use My Blocks in your programs, and share them with others
  • Store data on the NXT, manage its memory, and transfer files between the NXT and your computer

The book's programs work with one general-purpose test robot that you'll build in Chapter 3.

Whether you're a young robotics enthusiast, an adult working with children to learn robotics, a parent, a FIRST LEGO League coach, or a teacher using NXT in the classroom, this is the complete guide to NXT-G that you've been looking for.

Requirements: One LEGO MINDSTORMS NXT or NXT 2.0 set

Read More Show Less

Product Details

  • ISBN-13: 9781593272180
  • Publisher: No Starch Press San Francisco, CA
  • Publication date: 9/15/2010
  • Edition number: 1
  • Pages: 288
  • Product dimensions: 7.90 (w) x 9.90 (h) x 0.90 (d)

Meet the Author

Terry Griffin has been a software engineer for over 20 years and has spent most of that time creating software for controlling various types of machines. He works for Carl Zeiss SMT on the Orion Helium Ion Microscope, programming the user interface and high-level control software. He lives in Massachusetts with his wife, Liz, a middle school math and science teacher, and their three daughters, Cheyenne, Sarah, and Samantha.

Read More Show Less

Table of Contents



who this book is for


what to expect from this book

how best to use this book

1 LEGO and robots: a great combination 1


the NXT online community 2


NXT versions 3

MINDSTORMS software versions 3

art and engineering 4

qualities of a good program 4

software, firmware, and hardware 5


what you'll learn from this book 6

what's next? 6

2 the NXT-G programming environment 7

a tour through the MINDSTORMS environment 7

a work area 8

b programming palettes 8

c robo center 8

d my portal window 8

e configuration panel 9

f help panel 9

g navigation panel 9

h controller 9

writing an NXT-G program 9

your first program 10

saving your work 10

running your program 11

your second program 11

debugging 12

reproduce the bug 12

simplify the program 12

look at the parts of the program 12

fix the bug 12

the edit-compile-test cycle 13

comments 13

adding comments 14

rules for working with comments 15

the configuration panel 15

general layout 15

changing panels 15

disabled items 16

a block's configuration icons 16

conclusion 16

3 the test robot 17

right-side motor 19

left-side motor 21

chassis 23

caster wheel 25

caster wheel for the NXT 2.0 retail kit 25

caster wheel for the original NXT retail kit and education set 27

attach the caster wheel 29

add the NXT 31

touch sensor bumper 33

attach the bumper to the chassis 36

ultrasonic sensor 37

sound sensor 38

color sensor or light sensor 39

attach the wires 41

the final beam 42

alternate placement for the color sensor 42

alternate placement for the ultrasonic sensor 43

conclusion 44

4 motion 45

the NXT motor 45

the move block 46

the move block's configuration panel 46

the feedback boxes 48

the NXT intelligent brick view menu 48

there and back 49

moving forward 49

turning around 49

testing a single block 50

moving back to the start 50

around the block 50

the first side and corner 50

the other three sides and corners 51

testing the program 52

the motor block 52

brake, coast, and the reset motor block 53

the CoastTest program 53

a problem with coasting 54

the reset motor block 55

the record/play block 55

configuration panel 55

the remote control tool 56

conclusion 56

5 sensors 57

using the sensors 57

the touch sensor 58

configuration panel 58

feedback box 58

the NXT's view menu 59

the BumperBot program 59

detecting an obstacle 60

backing up and turning around 60

testing 61

the sound sensor 61

configuration panel 61

setting the trigger value 61

BumperBot with sound 62

the light and color sensors 63

light sensor configuration panel 63

using the color sensor as a light sensor 64

the RedOrBlue program 64

determining red and blue values 64

the switch block 64

improving the program 66

using color sensor mode 67

the ultrasonic sensor 68

configuration panel 68

door chime 68

detecting a person 69

playing a chime 69

stopping the chime 69

the rotation sensor 70

configuration panel 70

the rotation sensor block 70

the BumperBot2 program 71

conclusion 72

6 program flow 73

the sequence beam 73

the switch block 73

configuration panel 74

the LineFollower program 75

more than two choices 76

using tabbed view 78

comments and tabbed view 78

the loop block 79

the keep alive block 79

the stop block 80

BumperBot3 80

conclusion 82

7 the WallFollower program: navigating a maze 83

pseudocode 83

solving a maze 86

program requirements 86

assumptions 88

initial design 88

following a straight wall 89

writing the code 89

testing 90

turning a corner 91

writing the code 91

testing 92

going through an opening 93

writing the code 94

using sound blocks for debugging 95

testing 95

final test 96

conclusion 96

8 data wires 97

what is a data wire? 97

the GentleStop program 97

tips for drawing data wires 101

the SoundMachine program 101

controlling the volume 102

using the math block 103

adding tone control to the SoundMachine program 103

understanding data types 104

using the number to text block 105

displaying the tone frequency 105

using the text block 107

adding labels to the displayed values 108

dealing with broken wires 109

conclusion 110

9 data wires and the switch block 111

the switch block's value option 111

rewriting the GentleStop program 112

advantages of using a sensor block 113

passing data into a switch block 113

passing data out of a switch block 113

matching more than two values 116

adding and removing conditions 117

the default condition 117

using numbers with the NXT-G 2.0 switch block 117

fixing the SoundMachine program's volume display 117

calculating the input value using NXT-G 1.1 118

calculating the input value using NXT-G 2.0 118

modifying the program 118

conclusion 121

10 data wires and the loop block 123

the loop count 123

creating the LoopCountTest program 123

restarting a loop 124

setting the final loop count value 124

setting the loop condition 125

timers 125

the timer block 125

a programmable timer, version 1 126

the compare block 127

a programmable timer, version 2 127

a programmable timer, version 3 129

conclusion 129

11 variables 131

a place for your data 131

managing variables 131

the variable block 132

the RedOrBlueCount program 133

creating the variables 133

initializing the variables 134

initializing the display 135

displaying the initial values 135

counting the red objects 135

counting the blue objects 137

grouping common settings 138

replacing long data wires with variables 138

the LightPointer program 138

defining the variables 139

finding the light source 140

initializing the values 140

the LightPointer program, part 1 141

the LightPointer program, part 2 143

constants 144

managing constants 145

the constant block 145

conclusion 146

12 the NXT buttons and the display block 147

the NXT buttons 147

the NXT buttons block 148

the PowerSetting program 148

defining the variable 148

the initial value and the loop 149

displaying the current value 149

adjusting the power value 150

testing the program 151

making the program faster 151

the display block 152

displaying an image 152

power setting with Images 153

drawing on the screen 155

the NXTSketch program 155

defining the variables 156

initialization 156

drawing the line 156

saving the new location 158

testing the program 158

conclusion 159

13 my blocks 161

building bigger blocks 161

creating a my block 161

the custom palette 163

editing a my block 163

configuring a my block 164

changing the name of a configuration item 165

the DisplayNumber block 166

configuration items 166

controlling the line setting using a data wire 166

building the DisplayNumber block 167

testing 170

creating the DisplayNumber block 170

changing the names of the configuration items 171

using the DisplayNumber block 173

managing the custom palette 174

sharing programs with my blocks 175

copying files 175

create pack and go 175

advanced my block topics 175

variables and my blocks 176

nesting my blocks 176

broken my blocks 176

adding a data plug 177

conclusion 177

14 math and logic 179

computer math 179

integer math 179

range of values 179

division 180

odometer 181

floating-point math 183

range 183

precision 183

the number to text block 183

the random block 184

adding a random turn to BumperBot 184

the logic block 185

adding some logic to BumperBot 186

the range block 189

improving RedOrBlue 189

improving RedOrBlueColorMode 192

conclusion 194

15 files 195

using files 195

the file access block 195

the filename 196

the action setting 196

the type setting 196

saving the RedOrBlueCount data 197

checking for errors 199

the FileReader program 200

restoring the RedOrBlueCount data 201

managing memory 207

deleting files 207

transferring files 208

common problems 208

conclusion 208

16 data logging 209

data collection and the NXT 209

the VerifyLightPointer program 209

collecting the brightness data 210

running the program 211

analyzing the data 212

adding rotation sensor data and a timestamp 212

gaps in the data 214

setting the initial file size 215

controlling the amount of data 216

data logging using the Lego Mindstorms education NXT software 2.0 217

the data-logging blocks 217

the VerifyLightPointer2 program 218

the NXT data logging application 219

conclusion 220

17 using multiple sequence beams 221

multitasking 221

adding a second sequence beam 221

avoiding a busy loop 223

adding a sequence beam to a loop block 223

the crowbar and pin technique 224

adding the sequence beam 225

expanding the loop block 226

making the light flash 227

understanding program flow rules 229

starting blocks and data wires 229

starting a loop or switch block 229

using values from a loop or switch block 229

using my blocks 230

synchronizing two sequence beams 230

the AroundTheBlock program 230

the DoorChime program 230

keeping out of trouble 232

conclusion 232

18 the LineFollower program 233

following a line 233

requirements 233

assumptions 233

the starting point 234

selecting the sensor trigger values 234

building the LineFollowerConfig program 235

testing the LineFollowerConfig program 237

changing the LineFollower program 238

improving the control algorithm 243

how far from the edge? 244

controlling the motors 248

setting the power values 248

testing the program 251

conclusion 251

A NXT websites 253

B moving from NXT-G 1.0/1.1 to NXT-G 2.0 255

numbers 255

block changes 255

using old programs 256

side-by-side installation 256

index 257

Read More Show Less

Customer Reviews

Average Rating 4.5
( 3 )
Rating Distribution

5 Star


4 Star


3 Star


2 Star


1 Star


Your Rating:

Your Name: Create a Pen Name or

Barnes & Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation


  • - By submitting a review, you grant to Barnes & and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Terms of Use.
  • - Barnes & reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously
Sort by: Showing all of 3 Customer Reviews
  • Posted December 7, 2010

    Great Resource

    OK, so I am a bit biased. My husband wrote the book. But here is the story. I am a middle school math and science teacher. I got a grant to buy some Lego Mindstorm kits. Who could pass up such a deal? I knew the kids would love them. I knew the students could follow the directions to build the robots but what then. I knew nothing about programming the robots. Luckily I am married to a great software engineer who is also a great teacher. Terry helped me through that first year of teaching robotics to middle schoolers. He was concerned, however, that there really was no resource out there for teachers like me who wanted to use the robots as a tool to teach. So he wrote this book. He wrote it for me and for all the other teachers who want to inspire students beyond a textbook. It is written in a clear, well organized, step by step manner. You don't need any programming background to be able to develop great programs that will challenge your students. And you will be able to answer all their questions.

    2 out of 2 people found this review helpful.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted March 14, 2014



    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted December 27, 2012

    I want this book

    It looks SO good

    Was this review helpful? Yes  No   Report this review
Sort by: Showing all of 3 Customer Reviews

If you find inappropriate content, please report it to Barnes & Noble
Why is this product inappropriate?
Comments (optional)