Skip to end of metadata
Go to start of metadata

In this activity you will create a controller to be used with several games.

If you get stuck, go to the Troubleshooting links at the end of the example.

1. Requirements


Two XBee 802.15.4 modules

One XBee breadboard adapter

One XBee USB adapter

to configure the XBees

One solderless breadboard

Two push-buttons

One 2-axis joystick

Jumper wires

One 9V battery clip

One 9V battery 

One breadboard power supply

One mini USB cable



If you have not already done so, use the links below to download and install the software:

For further information about XCTU, go to the XCTU walkthrough.

2. Add the XBees to XCTU

  1. Ensure that the XBee is seated firmly in the XBee USB adapter.

  2. Plug the XBee USB adapter into your computer using the mini-USB cable provided.

  3. Open XCTU.

  4. Make sure you are in Configuration working mode.

  5. Click Discover radio modules from the toolbar.

  6. In the Discover radio devices dialog, select the serial port(s) in which you want to look for radio modules. If you do not know the serial ports where your modules are attached, select all ports. Click Next

  7. In the Set port parameters window, maintain the default values and click Finish.

  8. As XCTU locates radio modules, they appear in the Discovering radio modules… dialog box. Once the discovery process has finished, click Add selected devices.

  9. At this point, you should see something like this in the Radio Modules section on the left:

The port number and MAC address do not necessarily have to be equal as shown in the picture.

3. Configure the XBees

One of the XBees will be the controller and the other the receiver attached to the PC and talking to Processing:

  1. Restore the default settings of all XBees with the Load default firmware settings button at the top of the Radio Configuration section.

  2. Use XCTU to configure the following parameters:

    ParamController XBeeReceiver XBeeEffect
    CHCCDefines the frequency to use to communicate. This must be the same for all radios on your network.
    ID20152015Defines the network that a radio will attach to. This must be the same for all radios on your network.
    DH0DH and DL combined form the destination address. This is where the new position of the joystick and the button values are sent. The address being configured here is known as a short address. A short address is assigned during configuration. An XBee also has a long address (SH and SL combined) which is assigned permanently when the unit is manufactured.
    MY1234Defines the XBee's short address.
    APAPI enabled [1]Enables API mode.
    D1ADC [2]Sets the DIO1/AD1 pin as ADC in the controller to read the analog value from the joystick y-axis.
    D2ADC [2]Sets the DIO2/AD2 pin as ADC in the controller to read the analog value from the joystick x-axis.
    D4DI [3]Sets the DIO4/AD4 pin as digital input in the controller. This pin is connected to the right button.
    D6DI [3]Sets the DIO6/AD6 pin as digital input in the controller. This pin is connected to the left button.
    IC50Configure the controller XBee to transmit an IO sample when pin DIO4/AD4 and DIO6/AD6 changes. In other words, when left or right button is pressed.
    01010000 (binary) = 50 (hexadecimal)
    IR32Sample quickly (every 50ms) so controller latency is minimized (50 ms = 32 in hexadecimal).

    — keep the default value.

  3. Write the settings of all XBees with the Write radio settings  button at the top of the Radio Configuration section.

4. Connect the components

  1. Create the following circuit with your components.

    Ensure that each wire is connected to the same column on the breadboard as the pin of the XBee breadboard adapter footprint. This ensures that the signals to the XBee are correct.

    Click to expand diagram

  2. Push down firmly on the breadboard adapter board to ensure it is seated properly on the breadboard. Do not be afraid to use a little force.

  3. Insert the Controller XBee into the XBee breadboard adapter. Push down firmly on the XBee to ensure it is seated properly on the breadboard adapter.

  4. Double check that the breadboard adapter and XBee are positioned in the correct location and oriented the same as the image below. Incorrect placement has the potential to result in damage to components.

    Click to expand diagram

    The headers connecting the joystick to the breadboard provide stability on one side. If the joystick is not as stable as you would like, wrap a piece of tape from the top of the joystick around to the bottom of the breadboard to hold the other side firmly in place.

  5. Insert the Receiver XBee into the XBee USB adapter.

  6. Connect the XBee USB adapter to the USB port of the computer which will run Processing.

5. Put it all together

  1. If you have not already done so, download and extract the latest zip archive from the XBee/Arduino Compatible Coding Platform release page.

  2. Follow the instructions in the Manual Install section of How to install a Contributed Library to install the provided library in your Processing environment. From the processing_getting_started folder, install the contents of the files and

  3. Enjoy playing some of the provided games, or make your own.

6. Use the library yourself

  1. Start the Processing application.

  2. Add the library to your sketch with  Sketch > Import Library.... The library appears as usable at the bottom under the Contributed section.

The library has one class named  Controller . A Controller object can be created as follows:

The arguments to the constructor are:

  1. A reference to your application (represented by the keyword this)
  2. Serial port device name
  3. Serial port baud rate

Match the serial settings as appropriate to communicate with the XBee attached to the Processing computer.

Currently the library assumes that only one controller will send it data.

Once you create the Controller object, it provides getX and getY methods that return the 10-bit ADC value from the XBee. The value is configured to match the orientation of the Processing drawing context; up reduces the y-axis value, down increases it. The draw method can use these getters to retrieve the joystick position in each frame for the game logic.

To be informed of button-press events, provide a void buttonEvent(boolean leftButton, boolean rightButton)method in the sketch. This will be called each time the button state changes.

7. Troubleshooting

If you are encountering problems, these suggestions may help:

 How do I find the serial port of my module?

You can remove the XBee Grove Development Board from the USB port and see which port name disappears from your port list. The name that disappears is your XBee board.

Many people figure out which port is right via trial and error, but you can also use XCTU to find it:

  1. Open XCTU and discover the radio modules attached to your computer by clicking  on the top-left corner.
  2. Select all ports to be scanned.
  3. Click Next and then Finish.
  4. Once the discovery process has finished, a new window notifies you how many devices have been found and their details. The serial port and the baud rate are shown in the Port label.
 An error saying that the port is already in use by other applications is displayed.

The serial port where the local XBee module is connected can only be in use by one application. Check that the connection with the module in the XCTU console is closed and there are no other applications using the port.

 The error 'Device driver software was not successfully installed' is displayed.

Sometimes when you connect the XBee Grove Development Board into you computer, the operating system cannot install the driver automatically. If you get that error, try to remove and re-insert the board into your computer. If the OS is still unable to install the driver, remove and re-insert the board into another USB port.

As a last resort, install manually the USB drivers following the instructions that appear in the step 4 of the Downloading and installing XCTU section.

 How can I physically identify the XBee modules?

Once you have added the modules to XCTU, a simple way to identify them is to read the radio settings of each one and check the Rx and Tx LEDs of the XBee Grove Development Boards. These LEDs indicate that the XBee module is receiving (Rx) or transmitting (Tx) information through the serial port.

When you read or write the settings of a module, its Rx and Tx LEDs blink, so you can identify which module is connected to each serial port.

 An error is reported when installing XCTU.

XCTU requires Administrator permissions

Check that you have Administrator access on the machine where you are installing XCTU. On Windows systems, a User Account Control dialog may appear when you install XCTU or try to run the XCTU program. You must answer yes when prompted to allow the program to make changes to your computer, or XCTU will not work correctly. Note that you may also need to talk to your network manager to gain permission to install or run applications as administrator.

 No radios are found when discovery is performed or no serial ports are listed.

Check cables

Double check all cables. The USB cable should be firmly and fully attached to both the computer and the XBee Grove Development Board. When attached correctly, the association LED on the adapter will be lit.

Check that the XBee is fully seated in the XBee Grove Development Board

When the XBee is correctly installed, it should be pushed fully into the board and no air or metal should be visible between the plastic of the adapter socket and the XBee headers. Also, double check that all ten pins on each side of the XBee made it into a matching hole in the socket.

Check the XBee orientation

The angled "nose" of the XBee should match the lines on the silk screening of the board and point away from the USB socket on the XBee Grove Development Board.

Check driver installation

Drivers are installed the first time the XBee Grove Development Board is plugged in. If this process is not complete or has failed, try the following steps:

  1. Remove and re-insert the board into your computer. This may cause driver installation to re-occur.
  2. Remove and re-insert the board into another USB port.
  3. (Windows) Open Computer management, find the failing device in the Device Manager section and remove it.
  4. You can download drivers for all major operating systems from FTDI for manual installation.

Check if the modules are sleeping

The On/Sleep LED of the XBee Grove Development Board indicates if the module is awake (LED on) or asleep (LED off). When a module is sleeping, it cannot be discovered in XCTU, so press the Commissioning button and will wake up for 30 seconds.

 After resetting an XBee to factory defaults, XCTU reports errors for the KY and DD settings.

This is a known issue with the 6.1.2 versions of XCTU or less.

When the Invalid settings dialog appears, it is safe to continue to write settings.

  • AES Encryption Key (KY) is a setting that must be set by the user when encryption is used and does not apply with factory settings.
  • Device Type Identifier (DD) is a diagnostic parameter which is not used in the operation of the radio and can safely be set to any value.
Circuit assembly
 Do I need to match the wire colors used in the diagrams?

No, in many of the diagrams the color of the wires indicates something unique about its role in the circuit such as power, ground, and so forth. However, the color does not matter when assembling the circuit.

My circuit doesn't work
 Things to check first.

Is everything fully inserted?

Make sure that all components are fully inserted into the breadboard, sockets or connectors. When connecting, ensure that the wire or headers are aligned correctly and push firmly and evenly on the part. Header pins on the XBee or breadboard carrier boards should insert fully such that the plastic molding sits flush with the socket or board.

Do wires connect to the correct pins?

Check the diagram against the circuit that you have built. It can be easy to place wires so that they are one row off from the desired location. If you have any questions about which portions of the breadboard are connected, check out How to use a breadboard which describes the anatomy of a breadboard. This will help you to understand component placement in each game.

Are all XBees configured correctly?

Make sure that the configuration of each XBee matches the settings provided in the instructions. Before you configure the XBee, restore each module's default settings using the factory defaults button at the top of the Radio Configuration section.

 An LED does not light when expected.

Check LED polarity

An LED has a correct installation direction. When installed backwards it will not light when expected. The long leg of the LED (anode) must be provided with a higher voltage than the short leg (cathode). In most of the projects, the cathode is connected to ground and the voltage to the anode is controlled by connecting it to a digital output on the XBee or Arduino.

Another way to identify the cathode if you've clipped the wires, or want to check while it is installed is to look at the colored plastic housing. Many LEDs will make the body flat on the cathode side as well.

Check resistor

Resistors are placed in series with each LED to ensure that it does not receive too much current. Compare the stripes on the resistor being used to check that you are using the correct resistor. The resistors in these games are 330Ω and should have stripes that are orange-orange-brown.

 Do you get an error when uploading code to the Arduino?

If the Arduino IDE displays the message "Problem uploading to board." after you click Upload, enable the option "Show verbose output during upload" in the preferences (File menu > Preferences):

Click Upload again, and find the error message that appears above the line Problem uploading to board. See for suggestions.

Does the error message read "avr_dude: ser_send(): write error: sorry no info avail"?

This error appears occasionally on 64-bit versions of Windows. In order to upload code successfully to the Arduino, you must reset the Arduino at a specific time during the upload.

  1. In the Arduino IDE, click Upload.
  2. Press and hold the RESET button on the Arduino board.
  3. Release the RESET button on the Arduino board when messages like the following appear in the Arduino message window:

  4. After the code is uploaded to the Arduino, the following message appears at the bottom of the window:

Learn more

For more information about the hardware and software you use in this activity, see:

  • No labels