Sending and Receiving Messages (One-Way)

From FIRE Wiki
Revision as of 19:35, 14 December 2011 by Ipflot (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Project Description

This first lesson is to achieve basic communication between two robots. Robot A (the sender) will send a single message to Robot B (the receiver). Once Robot B receives the message, it should display it to it's LCD screen for a few seconds so the user can confirm the message was received.


Topics Covered In This Lesson:

  • Sending and Receiving Data
  • Using the NXT LCD screen
  • Using External Libraries


Oneway robots.png

User Notes

Note: The concepts outlined in this lesson are geared towards an intermediate user of ROBOTC and C Programming languages. Users should familiarize themselves with ROBOTC before beginning the Multi-Robot lessons.

  • Remember when using Multi-Robot communications to always start the robot that is the receiver first. Otherwise, the receiving robot will not be listening when the sending robot broadcasts it's message.



  • Have Robot A send a message (“M1”) and have Robot B display (“M1”) on its LCD.
  • Example: Robot A sends “Hello” and Robot B displays “A said: Hello”.

Hardware Setup

  • Each Robot should have a programmed Xbee radio attached to a NXTBee adapter. The NXTBee Adapter should be connected to sensor port 4 of the LEGO NXT.


Commands Used

  • InitRS485(); - Function to initializes the XBee radio
  • SendString(message); - Sends a string to every other robot in range on the same communication channel. This function will delay the program to allow the message to properly sent (roughly 1ms per character in the string).
  • ReceiveString(message); - Receives a string that was sent from another robot. This function will delay the program until a message is received (internal loop).

Lesson Steps

1. The first robot (Robot A) is programmed to send a message to the second robot (Robot B). Before you can do this, you will need to add the "InitRS485()" command to set up the wireless radio on your NXT.

2. Now add to first robot's program (Robot A) the command to send a message. Use the "SendString()" command to broadcast out a string to the receiving robot.

3. The first robot (Robot A) will do nothing else besides sending a single message. The program will end after sending the message.

4. Start a new program for (Robot B) - The second robot (Robot B) is programmed to receive the message sent by (Robot A) and display that message to its LCD screen. Before you can do this, you will need to add the "InitRS485()" command to set up the wireless radio on your NXT.

5. To receive a message, you will use the "ReceiveString()" command. This command has a single parameter - incomingString. You will need to create a string to store the incoming message into, as function types in ROBOTC cannot return string, so we use the "Pass By Reference" command have the "ReceiveString" function overwrite the string we provide as a parameter. The "ReceiveString" command will erase the string you provide to receive the incoming message and then will delay your program until a message is received. Once it is received, it will combine the incoming data into a single string and store it into the string you provided as a parameter.

6. Once we've received a string, we will use the "nxtDisplayString" command to view the received string on the NXT's LCD screen. Remember to give your program a few seconds of "wait1Msec" time at the end to keep the message displayed on the screen.

Robot A Source Code

Robot B Source Code