Introduction
This document describes how to set up your LEGO RCX microcontroller so that you can download programs from either Macintosh or Intel-based personal computers running the Windows operating system. It also describes the controller itself, including how to connect motors and sensors, as well as the functions of the four buttons.
The RCX
The RCX is a small computer packaged inside a yellow-and-gray LEGO brick. It has three motor outputs, lettered A, B, and C, along with three inputs, numbered 1,2, and 3, which can be used by your program to perform various tasks. There are four buttons on the surface, two of which also may be used by your programs.
Power
The RCX is powered by six AA batteries, which can be
replaced by removing the gray bottom half of the brick. The RCX does not
recharge these batteries! When they wear out, you must replace them with fresh
batteries, and because the RCX must be opened to do this, it is recommended
that you do not use the RCX brick as a structural component of your robot.
Otherwise, you will have to take your robot apart to change the batteries!
Generally speaking, one day of heavy use will drain the batteries. If your
RCX seems a little sluggish, try replacing the batteries.
Figure 1. Replacing the Batteries
When replacing the batteries, do so one at a time. This way, you will not loose your program or any stored data during the process. For the same reason it is also important that the RCX remain off, a tricky thing, because with the RCX upside-down, the power button can be depressed accidentally.
Connections
The image below shows how to connect motors
and sensors to the RCX.
Figure 2. Connecting Motors and Sensors to the RCX
Note that the orientation of the motor wire on the connection affects the direction of the motor. You can change the polarity of the wires by rearranging the connections on the RCX ports. For example, if your computer program directs the RCX to spin your robot's motors forward, but they actually spin in reverse or in opposite directions, you simply need to adjust the wire orientation.
The Four Buttons
The four buttons on the RCX were designed to work with the LEGO firmware, which allowed up to 5 separate programs to be stored in the memory of the RCX. IC 4 only supports one program at a time, so the function of these buttons has been redefined by the IC firmware.
The red “On/Off” button is used to turn the RCX on and off.
The green “Run” button was used to run the program selected with the “Prgm” button. It still has a use, because IC4 does not automatically run a program after download. Instead, you must power cycle the RCX (turn it off and back on again), or press the run button, to start your program.
The gray “Prgm” or “Program” button was used to switch between the 5 program slots. Now, your program may use it to obtain input.
The black “View” button has two uses. When no program is running, it is used to display the value of the sensor or motor ports. Pressing view repeatedly will step through each of the ports. A triangle indicates which port is displayed. When a program is running, the view button can be used in your program in the same way as the “Prgm” button.
Setting Up the RCX
Like any computer, the RCX requires software to function. While some of this software is provided for you, in the form of a firmware file and the IC 4 application, you will write the rest of this software yourself. The firmware and IC 4 application provide enough functionality to allow you to program the controller from a host computer which can be either a Macintosh or an Intel based PC. In addition, IC provides library routines that simplify the process of program input and output. But before you can use IC, you must do three things: physically connect the controller to the computer, and install the IC software onto the computer, and install the appropriate firmware file onto the RCX.
Connecting the RCX to the Computer
The RCX communicates with its host computer through an infrared transmitter and receiver encased in a single unit, which LEGO calls an infrared tower. The tower connects to the host computer through either a serial port or a USB port (IC 4 only works with the serial version of the tower).
Serial Ports: PC
A serial port allows a computer to communicate with other devices, such as modems, or mice. Nearly all Intel based PCs have at least two serial ports usually labeled COMM1 and COMM2. You should first connect the serial-port cable to one of these ports on the backside of your computer. Newer PCs may only have a USB port, which case you will need to add a USB-to-Serial hardware adapter. Try to make a note of which port you select.
Serial Ports: Mac
Macintosh computers used to come with two built-in serial ports usually labeled the “printer” port and the “modem” port. However, Apple has not shipped Macs with serial ports since the introduction of the iMac. Instead, new Macintosh computers are equipped with USB ports, for which USB-to-Serial adapters can be purchased. For users of these Macs, we suggest the Keyspan line of serial adapters, as they have given the best results during our testing of IC. If you do have an USB-only Mac, then install your serial port adapter first. In most cases, you can do this without restarting. If everything went well during installation, IC 4 will see the new serial port just as it would see a built in serial port.
If you have an older PowerMac, plug the round end of the black serial cable into a free port on your Mac. If you have successfully installed a USB serial adapter it may require a 9 pin trapezoidal serial connector such as is used with a PC. Try to make a note of which port you are select. To determine the port name on a USB serial adapter, refer to the instructions that came with it. The ports on an older Mac are labeled with pictures—one looks like a printer, and the other looks like a phone with ones and zeros coming out of it. The former represents the printer port, and the later represents the modem port.
Infrared
It was stated above that the RCX uses an infrared tower to communicate with its host computer. This section describes how to set up and use this tower.
Before attaching the serial cable to the tower, slide down the back cover and install the 9v battery. Make sure the battery is facing the direction of the picture in the bottom of the battery compartment, and be sure that the battery is correctly seated (that the top the battery is flat against the compartment walls, as shown in figure 3). Return the cover and attach the trapezoidal end of the serial cable to the tower. Arrange the RCX and tower so that they are facing one another as shown in the figure 4.
Figure 3. Correctly Seated Battery
Figure 4. Recommended setup for RCX
While there are many advantages to using infrared as a means of communication, one major drawback is interference. Other sources of infrared, like the sun, remote controls, video cameras, some indoor lighting, and nearby RCX bricks can interfere with the signal that you are trying to send to your RCX brick. Small amounts of interference may cause errors during download that can corrupt your program or cause the download to fail halfway through. With large amounts of interference, the computer may not even see the RCX at all.
One solution to interference is a box! Place a cardboard box over both the RCX and the transmitter to block out other sources of infrared light. If this doesn't take care of the problem, check the battery in your tower. Make sure all cables are properly plugged in, and make sure that the RCX is on—the RCX will turn itself off after 5 minutes of inactivity.
On the front of the tower towards the bottom, there is a small switch that controls infrared range. On either side of the switch are triangles embossed into the base of the tower. The small triangle indicates short range, and the large triangle indicates long range. Strangely enough, this switch does something! If the RCX is only a few inches away from the transmitter, make sure it is set to short range. Unnecessary use of long-range mode will waste the battery in the tower, and with the increased intensity of the signal comes increased chance of interference with your neighbors’ RCX. However, If the RCX is farther than two feet away, the switch should be set to long range.
Installing IC
Before you can continue, you need to have the IC application installed on your computer. The IC application program can be obtained from http://www.kipr.org/ic/, or on the BotBall CD. Find the directory that pertains to your computer and operating system, and copy the installer file to your hard drive. Run the installer file, and follow the instructions on the screen.
These installation instructions differ slightly for the Macintosh: If installing from the above address, first download and decompress the archive. To do this you will need Stuffit Expander from Aladdin systems, which is probably already installed on your computer. If installing from CD, just drag the application folder to a suitable location on your hard drive.
Firmware
Before the RCX can be used with IC, it must have the proper firmware. The firmware must match the version number of the IC software, so to use an RCX with IC version 4.01, it must have firmware version 4.01. If the firmware version does not match, IC will not recognize the RCX. This means that IC will not work with firmware provided by the LEGO Mind storms programming environment, or NQC. To tell what type of firmware is installed, turn on the RCX. If the firmware is compatible with IC, you will see "IC" followed by a version number such as "40 1". This means "IC 4.01", but due to the nature of the RCX screen, only five characters can be printed (so no decimal point), and a space will exist between the fourth and fifth characters. If anything else appears on the screen, either no firmware is loaded, or an incorrect firmware is loaded.
Figure 5. RCX with IC 4 firmware (notice the IC 40 1 on the screen)
If the firmware does not match, you will
need to replace it with the correct version. The procedure is very similar
for both the Mac and the PC. Any differences will be pointed out. The first
step is to open the IC application. Select "RCX" when it asks you to choose
the processor type. As soon as you do this, a green LED on the front of
the tower will light. If it does not, then your tower is not set up properly.
Refer to the above description of how to set up the tower.
When the “Port Selection” Dialog Appears, Click the "Connect Later" button.
Choose “Download Firmware” from the “Tools” menu. You will then be asked to choose a serial port again. If you remember what serial port that you plugged the tower into earlier, select it when the dialog box appears, otherwise just guess. A status bar like the one shown below will then appear. The bar should begin moving to the right. If you chose the right port, the LED on the front of the tower will light up.
It will take around two to three minutes to complete the download. Go get a cup of coffee or soda or something while you wait. The RCX will beep twice when the download is completed and IC will load the libraries. You will then be ready to program.
If the progress bar doesn’t move for about 10 seconds, another dialog will appear to tell you that the download failed. Just hit "OK". You will then be back at the serial port selection dialog box. Try a different serial port. If it works, you will be ready to program. If it fails, you are most likely suffering from interference, or the tower is not properly connected. Check all connections, use a cardboard box, and try it again.
Conclusion
If you followed all the instructions in this document, you should now be ready to program your RCX. If you are new to computer programming, follow the link to the Programming Tutorial, which describes the basics of C programming. If you want more information on using Interactive C, follow the link to the IC 4 tutorial, which describes how to use IC 4 in conjunction with an RCX or HandyBoard. If you are already comfortable with both IC 4 and the C programming language, then follow the link to the first activity.