Documentation Center

  • Trial Software
  • Product Updates

Contents

Exchange Data Between Two NXT Bricks

This topic explains how to exchange data between two separate NXT Intelligent Bricks ("NXT bricks") over a Bluetooth® connection.

If, instead, you are looking for information about exchanging data between your host computer and an NXT brick, see Tune Parameters and Monitor Data in a Model Running on NXT Brick.

Tips for Use Bluetooth Blocks

Here are some tips for using the Send via Bluetooth Connection block and Receive via Bluetooth Connection block:

  • Use two separate models, one for each NXT brick.

  • You can only use the Bluetooth blocks for connecting two NXT bricks.

  • For each Send via Bluetooth Connection block in one model, use a corresponding Receive via Bluetooth Connection block in the other model. Set the Mailbox parameter in both blocks to the same number.

  • For each Receive via Bluetooth Connection block in a model, use a unique Mailbox number.

  • A model can contain no more than five Receive via Bluetooth Connection blocks.

Add Bluetooth Blocks to your Models

Add Bluetooth blocks to your models and configure them:

  1. Open legonxtlib.

  2. Open two models. One for each NXT brick.

  3. Add a Send via Bluetooth Connection block to a model, and connect it to the data source, as shown in the following example.

  4. Add a Receive via Bluetooth Connection block to the other model, and connect it to the data sinks, as shown in the following example.

  5. In the model that contains the Send via Bluetooth Connection block, select the Display > Signals & Ports > Port Data Types menu item. Then, select Simulation > Update Diagram Ctrl+D. Observe the data type that appears above the connector attached to the Send via Bluetooth Connection block. For example "int32" in the following example.

  6. Open the Receive via Bluetooth Connection block in the other model. Apply the data type from the previous step to the Data type parameter in the Receive via Bluetooth Connection block.

  7. In the model that contains the Send via Bluetooth Connection block, select the Display > Signals & Ports > Signal Dimensions menu item. Then, select Simulation > Update Diagram Ctrl+D.

    • If the signal dimensions are greater than 1, the connector attached to the Send via Bluetooth Connection block displays the signal dimension. Multiply the signal dimensions to get the value you will apply to the Message size parameter. For example, if the signal dimensions are 2x10, the set Message size to 10.

    • If the signal is one-dimensional, the connector attached to the Send via Bluetooth Connection block does not display a signal dimension. For a one-dimensional signal, set Message size to 1.

  8. In the model that contains the Receive via Bluetooth Connection block, apply the signal dimension from the previous step to the Signal dimension parameter in the Receive via Bluetooth Connection block.

  9. Save all of your changes and leave the models open.

Configure Bluetooth Slave

Using your models, configure the NXT brick to operate as a slave Bluetooth node. You can make this choice arbitrarily, without regard to which device is sending or receiving data.

To configure an NXT brick as a slave Bluetooth node:

  1. Open one model and select Tools > Run on Target Hardware > Options.

  2. In the Run on Target Hardware pane that opens, select the Enable communication between two NXT bricks check box, and set Bluetooth mode to Slave.

      Note:   This action disables the External mode parameter. Enabling communication between two NXT bricks requires exclusive use of the Bluetooth device on the NXT brick.

  3. Click OK. This saves and closes the Configuration Parameters.

  4. In your model, click the Deploy to Hardware button to run your model on the NXT brick.

    This process can take a couple of minutes. When the download completes, the NXT brick automatically runs the application.

  5. When Simulink® software finishes downloading the application to the slave NXT brick, the LCD displays "Waiting".

    Observe the number on the second line of the LCD. The first 12 digits of this number are the Slave Bluetooth address, which you will use as you configure the Bluetooth master in the next procedure.

Configure Bluetooth Master

Configure the other NXT brick as a master Bluetooth node:

  1. Open one model and select Tools > Run on Target Hardware > Options.

  2. In the Run on Target Hardware pane that opens, select the Enable communication between two NXT bricks check box, and set Bluetooth mode to Master.

      Note:   This action disables the External mode parameter. Enabling communication between two NXT bricks requires exclusive use of the Bluetooth device on the NXT brick.

  3. Enter the 12-digit Slave Bluetooth address, inserting a colon between each pair of digits. For example, if the slave NXT brick displays 00165312926900, enter 00:16:53:12:92:69. Disregard the last two digits, 00.

  4. Click OK. This saves and closes the Configuration Parameters.

  5. In your model, click the Deploy to Hardware button to run your model on the NXT brick.

    This process can take a couple of minutes. When the download completes, the NXT brick automatically runs the application and connects to the Bluetooth slave.

  6. On the Bluetooth master, turn the wheel back and forth. Observe the direction and speed of the wheel on the Bluetooth slave.

Was this topic helpful?