In this activity, you create a scalable car racing game using three XBees.
If you get stuck, go to the Troubleshooting links at the end of the example.
2. Add the XBees to XCTU
Ensure that the XBee is seated firmly in the XBee USB adapter.
Plug the XBee USB adapter into your computer using the mini-USB cable provided.
Make sure you are in Configuration working mode.
Click Discover radio modules from the toolbar.
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.
In the Set port parameters window, maintain the default values and click Finish.
As XCTU locates radio modules, they appear in the Discovering radio modules… dialog box. Once the discovery process has finished, click Add selected devices.
- 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.
Leave your XBee coordinator plugged into the USB after you are done configuring it. Write down which serial port you are using, you will need to change it in the Processing code after you assemble the hardware.
3. Configure the XBees
Restore the default settings of all XBees with the Load default firmware settingsbutton at the top of the Radio Configuration section.
Use XCTU to configure the following parameters:
Param Race Game Controller 1 Race Game Controller 2 Receiver - XBee connected to PC Effect CH C C C Defines the frequency to use to communicate. This must be the same for all radios on your network. ID 2015 2015 2015 Defines the network that a radio will attach to. This must be the same for all radios on your network. MY 0001 0002 — Defines the XBee's short address. AP — — AP enabled  Enables API mode. D1 DI  DI  — Sets the DIO1/AD1 pin as digital input in the game controllers. This pin is connected to a button. IC 02 02 —
Configures the game controller XBees to transmit an IO sample when pin DIO1/AD1 changes.
00000010 (binary) = 02 (hexadecimal)
Write the settings of all XBees with the Write radio settingsbutton at the top of the Radio Configuration section.
4. Connect the components
Follow the instructions below for both controllers:
Create the following circuit using the hardware components. Use a blue button for controller #1 and a red button for controller #2.
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
Push down firmly on the breadboard adapter to ensure it is seated properly on the breadboard. Do not be afraid to use a little force.
- Insert the XBee into the breadboard adapter. Push down firmly on the XBee to ensure it is seated properly on the breadboard adapter.
Double check your wiring and ensure that the breadboard adapter and XBee are positioned in the correct location and oriented the same as the images below. Incorrect placement has the potential to result in damage to components.
Click to expand diagram
5. Put it all together
You are now ready to run the racing game.
- Apply power to both Race Game Controllers using the 9V battery clips and batteries.
- Exit XCTU.
- Download and extract the latest zip archive from the XBee/Arduino Compatible Coding Platform release page.
- Open the Processing application.
- From the File menu select Open.
- Browse to the
racegame_scalablefolder from the extracted archive, and select the
racegame_scalable.pdefile. Click Open.
In the Processing IDE editor window, change line 13 of the code to match the serial port setting that you noted above.
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:
- Open XCTU and discover the radio modules attached to your computer by clicking on the top-left corner.
- Select all ports to be scanned.
- Click Next and then Finish.
- 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.
- Click Run
- The cars are at the starting line ready to race.
6. Play the game
- Press the button to your car as fast as you can. The speed of button presses determines the velocity of the car (rectangle).
- The first car to the top of the window wins. Race the cars to the top of the screen with a friend.
If you are encountering problems, these suggestions may help:
For more information about the hardware and software you use in this activity, see: