Programming the NXT
Objectives
- Learn about a new robotic platform called NXT
- Compare the workings of the RCX to the NXT
- Learn about how to multitask on both robots
Tools and Parts Needed
- RCX robot with charged batteries
- NXT brick with charged battery pack
In this lab, you will learn to use a new robotic platform, called the NXT, which like the RCX is created by Lego.
The Mindstorm Robots: The RCX and the NXT
The first retail version of Lego Mindstorms was released in 1998 and marketed commercially as the Robotics Invention System (RIS). The next version was released in 2006 as Lego Mindstorms NXT. Note that they are both Mindstorm robots.
Let's look at the specifications for both the RCX and NXT:
RCX Specifications
RCX Buttons
- Red ‘ON/OFF’ button: Turns the RCX on or off.
- Grey ‘PRGM’ button: The RCX brick can store up to five programs. Every time the ‘PRGM’ button is pressed, the RCX moves to the next program until it eventually returns to program 1.
- Green ‘RUN’ button: When the ‘RUN’ button is pressed the RCX runs the selected program.
- Black ‘VIEW’ button: used to view sensor readings such as light levels.
- 8-bit Hitachi "H8/3292" MicroController
- 32 K RAM
- 3 input pads, using the Lego stud type connector.
- 3 output pads - using the Lego stud type connector.
- LCD display, capable of displaying 5 digits (with a sensor arrow before and a little walking man between the digits).
- Piezoelectric speaker
- Power source: 6 AA batteries
NXT Specifications
NXT Buttons
- Orange button : On/Enter /Run
- Light gray arrows: Used for moving left and right in the NXT menu
- Dark gray button: Clear/Go back
- 32-bit ARM7 micro controller
- 256 Kbytes FLASH, 64 Kbytes RAM
- 8-bit AVR micro controller
- 4 Kbytes FLASH, 512 Byte RAM
- Bluetooth wireless communication (Bluetooth Class II V2.0 compliant)
- USB full speed port (12 Mbit/s)
- 4 input ports, 6-wire cable digital platform (One port includes a IEC 61158 Type 4/EN 50 170 compliant expansion port for future use)
- 3 output ports, 6-wire cable digital platform
- 100 x 64 pixel LCD graphical display
- Loudspeaker - 8 kHz sound quality. Sound channel with 8-bit resolution and 2-16 KHz sample rate.
- Power source: 6 AA batteries or battery pack
Most RoboLab programs written for the RCX will work AS IS on the NXT, but there are a few improvements which work only on the NXT and which are worth discussing.
For example, the begin icon:

Create something like the above program and try running this on the NXT. It will also run on the RCX if you swap out the green stoplight which starts the program for the one we have used on the RCX.
Musicalcompostions for the Mindstorm robots are also available from
- http://www.legoengineering.com/ music page 1
- http://www.legoengineering.com/ music page 2
- http://www.legoengineering.com/ music page 3
- http://www.legoengineering.com/ music page 4
- Click the song title you want to download, saving the song file in the "My Songs" folder located in "My Documents/ROBOLAB Data/Songs/My Songs" on your laptop.
- Open Robolab Inventor Level 4 and choose Project>Piano Player from the menu bar.
- Once in the Piano Player, Open the song file. The notes of the song should appear in the Piano Player.
- Next push one of the following scroll icons:
. Note that using one of the colored scroll icons will allow you to run your program without a dialog box. The last scroll icon is called "load scroll from file" and will allow you to save into a file after editing.
- Then to play the music just include the same scroll icon in your RoboLab code. Note that when you use the "load scroll from file" icon, you will have to type the filename into a dialog box when the program runs.
- Note: You may also compose your own music for the RCX and the NXT, but please do this after you finish the rest of the lab or outside of class.
Changing the NXT Display
It is easy to write a program which will run on both the RCX and the NXT. The following program will run on both robots.
Note that the NXT does not have the same kind of screen as the RCX,
so the set display LCD sceen icon, ,
will not run properly on the NXT and will need to be removed from
programs before trying to run them on the NXT, so the following
program will not run on the NXT.
Of course, one can display values on the NXT, but the screen differs from the RCX. The following program will display the value of the red container on the NXT, but will not run on the RCX.
The NXT allows many programs to be stored, so naming programs is important. The following program will be easier to find on the NXT. It will not run on the RCX.
Multitasking
Humans are naturals at multitasking. Did you ever try to walk and chew gum at the same time? How about whistling while you work--okay maybe humming while you listen to music AND working at the same time? As the word itself is suggests, multitasking means processing two or more tasks at the same time. In previous assignments, all the RoboLab programs ran sequentially--never at the same time. This was true for all of our labs, even when you used conditionals because the execution of the program after the condional branch followed only one of the two possible branches at a given instant in time, NOT both branches at the same time.
With the use of the multitasking property, tasks can be run on our robots at the same time, like chewing gum while walking or whistling while you work. This property helps robots do several tasks simultaneously and hence makes the programs more versatile.
In RoboLab, multitasking can be accomplished on both the RCX and the NXT is enabled by the Task Split icon:
For example, the following program uses a Task Split to drive in a circle for 4 seconds while playing music continuously. Observe also, that when multitasking there cannot be a fork join to a common program end for the two tasks--each task must have an individual end as follows:
In this example, there are two tasks: Task 1 drives motor A forward for 4 seconds and then stops, while Task 2 plays the musical note forever. You will observe that the music will play simultaneously while motor A is moving and even after the motor stopped because Task 2 involves an infinite loop created by the green land and jump icons.
The above has just two tasks, but by using multiple Task Split icons, a programmer can have as many tasks running at the same time as he/she wants. It is just a matter of having additional task structures.Your Main Task
In this lab you are required ultimately to program your NXT robot to whistle while it works. It is suggested that you first program the RCX and then make changes to your program to make it work on the NXT.First, you must use a task split to get the robot to multitask.
- On one branch, you must get the robot to repeat a piece of music forever.
- On the other branch, the robot should drive about in a seemingly random pattern.
Hints: You may need random numbers and nested conditional forks to make this work. Use the red, blue, or yellow scrolls. Be sure that once the tune is chosen, it still will play over and over forever.
Once all of the above is working, add complexity to the random driving patterns.
Once all this is working on the RCX, see if you can run the same program on the NXT.
- Be sure to include explanatory comments to your RoboLab code by
using the Edit Text icon:
In particular, it is required that you add the following comments:
- Lab L14
- All of your team member's names
- Comments about what the robot will do on each fork.
- When using the NXT, use the "Begin NXT"
icon to begin your program. Give this start icon the name of L14-tablename
- Finally, modify your pseudocode, robot, and RoboLab program to improve your robot's performance.
- Answer the questions in your Lab Report.
Your Lab Report
This lab report should contain all of the following information at the top:- The lab number: Lab L14
- Initials: JP-JA (Use your initials, so Jan Pearce and
Josh Absher would be JP-JA)
- How long each person served in each of the roles:
- Driver:
- Navigator
- Scale Program: Try the something like a scale program on the NXT. Describe what modifications need to make to make it run on the NXT as compared to what it would have looked like on the RCX.
- Your Pseudocode for the main task: Include the final version of your pseudocode in your Lab Report.
- Your Success: Be sure to use an NXT start icon such as
with L14-initials where "initials" represents your initials and your
partner's initials.
(Jan Pearce and Josh Absher is JP-JA)
Describe how to use your program and whether or not your NXT robot functions as desired. If not, what goes wrong and under what conditions? - Testing and Refining: Describe what changes you made in your algorithm during the testing and refining phase for the NXT.
- The NXT: What is your team's reaction to programming on the NXT?
- Future Modifications: Discuss at least on idea for changes you might consider making which would make this an even cooler program for the outreach to kids. (Remember that kids love interaction!)
- Comments and Suggestions: Write a paragraph that summarizes your team's reaction to RoboLab and to this lab. If there are any problems you encountered or any questions that remain, please ask! Also, be sure to include any suggestions you have for how this lab could be improved.