NXT Unplugged - Programming Without the Computer

With the NXT 1.26 (don't use that version!) and 1.28 firmware, you can write simple programs directly on the NXT brick.  This is really handy for activities where you need the NXT to just do simple tasks - where the main goal is construction, rather than programming.  It's under the "NXT Program" icon.  Press .
When you select it, the next screen tells you which ports you should use to connect the motors and sensors (if you're using any).  Make sure your wires are connected correctly.

Now we're ready to program.  Press .

The Big Picture - Five Program Blocks

This screen illustrates how you enter a program.  You have 5 "blocks" that hold one step of the program.  The black triangle indicates that you're going to enter the action for the first block.  The five blocks are not all the same - different blocks can do different things:
Block  1 : Action (move forward, backward, turn, or make a sound).
Block  2 : Wait-For (time or sensor).
Block  3 : Action - same as before.
Block  4 : Wait-For - same as before.
Block  5 : Stop or Loop.

An example program might be:
 1  - Move forward.
 2  - Continue moving until the touch sensor is pressed.
 3  - Back up turning right for 2 seconds.
 4  - (empty)
 5  - Loop "forever".
This program will make the robot wander around the room until the dog finds it and starts chewing on it, or something like that.

We'll now step through the process of building a program.

Fifteen Action Choices

The first and third blocks can contain actions that make the robot move or play a sound.  If you scroll left and right using the arrow buttons, you'll see that there are 15 different actions:
The two musical notes play a sounds of different pitches.  The empty box means "do nothing".  You probably wouldn't want to "do nothing" in the first action box, but you might in the second.  All of the other choices are movement.  The movement choices come in pairs, with and without a number.  With the number, the NXT does that movement for either two or five seconds, depending on the number.  Without the number, the NXT will do the action until the wait-for condition in the next block is satisfied.  The possible movements are, from left to right:
  • Back up, turning left.
  • Go forward, turning left.
  • (do nothing)
  • Go straight backward.
  • Go straight forward.
  • Go forward, turning right.
  • Back up, turning right.
  • (play a sound)
Choose your action, then press .

The next screen shows two things.  First, the black triangle has moved to the second block, indicating that you're going to choose a wait-for condition.  Second, you can see a tiny spec of an icon in the first block - which is actually enough to tell you which action was selected.  In this case, the action is forward (the arrow) for 5 seconds (the speck at the tip of the arrow).

Nine Wait-For Conditions

The second and fourth blocks can contain wait-for conditions that make the robot continue moving until the condition is satisfied.  If you scroll left and right using the arrow buttons, you'll see that there are nine different conditions:
The empty box means "don't wait - just go on to the next block".  The possible conditions are, from left to right:
  • Wait until the sound sensor hears something.
  • Wait until the light sensor sees more light.
  • Wait until the light sensor sees less light.
  • Wait until the touch sensor is pressed.
  • Don't wait - immediately cancel the previous movement.
  • Wait for 2, 5, or 10 seconds.
  • Wait until the ultrasonic range finder notices an object getting close.
If you're familiar with programming these wait-for conditions in NXT-G, you've probably noticed that there's no way to set thresholds here – how bright, how loud, or what distance.  You're right.  The NXT makes a guess about the threshold, probably based on the sensor value when the wait-for block starts.

When the condition is satisfied (for example, the touch sensor is pressed), the movement (and the only possibility is movement) chosen in the previous block is canceled.  "Don't wait" can be confusing, because the motors will immediately stop.  So, if the motor runs for just a fraction of a second and stops, you've probably chosen a "run until" in an action block followed by a "don't wait" in the next block.  You should only choose "don't wait" when the previous action was a timed movement or sound.

Choose your wait-for condition, then press .

The next two blocks (3 and 4) are exactly the same as 1 and 2.  So, for example, you could choose "forward 5 seconds, wait 2 seconds, backward 5, wait 2 seconds".

The last block lets you choose what happens when the first four blocks have finished.  You've got two choices: stop and loop.  Stop means just that - run the first four blocks and then stop.  This will be fine for many situations, but is also useful when you're debugging a program that you plan to have loop.

Loop means to keep running the first four blocks, over and over - forever.  Or, at least until the batteries run down.

Choose whether to stop or loop, then press .

Finally - you've finished the program.  Just press to run it.  While the program is running, the five blocks are shown with the black arrow underneath the active block.  This is hand if, for example, your robot runs without stopping - you'd probably see that it was stuck in one of the wait-for blocks, waiting for... something.

The other two choices are to go back to the main NXT menu - forgetting about the program or to save the program.  Personally, I don't find the save option to be very interesting, because it takes longer to enter the name for the program than to re-create the program.

What if I make a mistake?

The dark-gray "back" or "up" button is your friend, at least a little.  Each time you press it, you will erase one program block.  So, pressing it once will take you to block 5, press again to get to block 4, etc.

I hope that you've found this tutorial helpful.

Colophon

I hope you enjoyed the graphics I put in here.  They are actual screen shots from my NXT, which I obtained using a handy utility called "NXT Screen", which is part of NeXT Tools for Mac OS X, an open-source project.  Those screen shots actually end up in gray scale.  I massaged them into black-and-white, then changed the background color to green, using GraphicConverter.
ą
Glenn Trewitt,
Sep 25, 2009, 11:13 PM
ą
Glenn Trewitt,
Sep 25, 2009, 11:14 PM
ą
Glenn Trewitt,
Sep 25, 2009, 11:14 PM
ą
Glenn Trewitt,
Sep 25, 2009, 11:15 PM
ą
Glenn Trewitt,
Sep 25, 2009, 11:15 PM
ą
Glenn Trewitt,
Sep 25, 2009, 11:15 PM
ą
Glenn Trewitt,
Sep 25, 2009, 11:15 PM
ą
Glenn Trewitt,
Sep 25, 2009, 11:15 PM
ą
Glenn Trewitt,
Sep 26, 2009, 8:17 AM
ą
Glenn Trewitt,
Sep 25, 2009, 11:54 PM
Comments