• NXT-to-NXT Communication

    by  • October 10, 2013 • How Do I...? • 0 Comments

    Connecting (pairing) the NXTs
    Here I describe how to do NXT-to-NXT communication.  The first way that we'll do it is through Bluetooth, and pairing the two NXTs together.  Once paired, we can write code that allows them to communicate.  The basic method for pairing is:
    • Give your NXT a unique name (something other than default "NXT") using the NXT Terminal; this is so you can find it in a list of other NXTs in the room
    • From the main screen of the NXT, turn on Bluetooth
    • You will know Bluetooth is on by the symbol in the top-left corner
    • Search for other NXTs (or, if you've previously paired, look in My Contacts)
    • Select the NXT with which you want to pair
    • Once you are connected, you will see a "< >" in the top-left corner
    Periodically double check the "< >" in the top left to make sure you are still paired.  If either of your NXTs turns off, you will lose the connection.
    Give your NXT a name

    Turn on Bluetooth
    Bluetooth is on
    Search for other NXTs
    Select the NXT with which you want to pair
    Connection established with the other NXT (here: on connection 1)
    Writing the Code
    You need to write two sets of code: one that runs on the host (the NXT that initiated the connection) and the second that sits on the client (the second NXT).  Communication can go both ways, but you need to know which NXT is which, and on which connection number (1, 2, or 3) they were paired.
    The following code:
    - for the host (here: SheWolf), it reads the motor value, displays to screen, and sends to the client
    - for the client (here: HAL9000), it waits for a new message (motor value) to come from the host, and then displays it on the screen
    Host code: sending message to client (and displaying)
    Client code: receiving message from host (and displaying)
    Here is the code running (looks same on host and client)
    Another way (without Bluetooth)
    There is another way to have two NXTs communicate without using Bluetooth.  Instead of using remote mode (and downloading the code to the NXTs), it's possible to have all the code run on the computer (staying in Main Application Instance).  In this case, you need both NXTs to be connected to the computer via USB at the same time.  To communicate with the NXTs (e.g. read sensors, run motors, draw on the screen, and play sounds) you need to specify which NXT you are interacting with.  This information is contained in the LabVIEW "pink wire" that connects the NXT functions.
    In this way, you can have two parts of code that are using sensor/motor values from two NXTs but doing so simultaneously and interacting together.  For Instance, in the following example, two NXTs are "in a race" with each other, and the current motor value for each is displayed on the screen, as well as which NXT is ahead ("winning").
    You can find the "Specify NXT" function under: NXT Robotics > NXT IO > Advanced
    Dual NXT Code
    Dual NXT Code.zipDual NXT Codeapplication/zip13.06 KB

    Leave a Comment