|
|
|
| created 20/07/2009 last update 20/07/2009 | author: Claude Baumann |
| Introduction:
Although the LEGO NXT is much more performing than the RCX, you might want to continue using the good old device. Perhaps you even would like to combine both microcontroller systems. That's where the problems begin. LEGO didn't really care about such an eventuality. So, there is no direct way, how the RCX can talk to the NXT. The gap was rapidly filled with third party links like the Hitechnic IR Link sensor . The rather expensive device is handy, but under certain conditions not always reliable. In fact, sometimes the sensor returns garbage and the NXT program needs to run a special error-detection in order to avoid troubles. (We especially run into such troubles with the Nic_3 projects.) As an alternative, we propose on this page a simple, slow, but reliable communication between the RCX and the NXT. We start from the challenge that the RCX should send data to the NXT at a rate of 1Hz. We directly connect the RCX PortA and PortB to the NXT input ports 1 and 2 respectively, using two "legacy" wires. The RCX output ports are toggled between float and brake mode. Electronically this changes between open and short circuit and the NXT inputs may read logical ones and zeros. The RCX is used as the master of this communication, providing the clock pulse and initiating the communication. The data is written by the RCX at the falling edges of the clock pulses, while the NXT reads at the rising edges. The RCX function is written in Ultimate ROBOLAB.
The NXT program works as a state machine with the states: UNDEFINED, IDLE, RX and VALID. At start, the NXT enters UNDEFINED state. Once it detects that the clock line didn't change from HIGH for more than 100ms (a variable threshold), then the state changes to IDLE. If the NXT detects a transition on the clock line from HIGH to LOW, it changes to RX. Now it is waiting for 8 rising edges and each time it reads the data bit. After 8 clock pulses, the state machine changes to VALID. Now the NXT program that uses the state machine should read the valid byte and free the channel to UNDEFINED state. The state machine does not care about errors or time-out conditions. (Note that for test reasons in the following code, the state machine changes directly from VALID to UNDEFINED without waiting for the calling program to validate.) The data is exchanged at the speed 2 bytes/second.
|
|
| Download the LV86 library | |
| Webopedia: | |