In this activity, you will create a car racing game using two 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 receiver XBee plugged into 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 settings
Use XCTU to configure the following parameters:
Param Race Game Controller XBee Receiver - XBee connected to PC Effect CH C C Defines the frequency to use to communicate. This must be the same for all radios on your network. ID 2015 2015 Defines the network that a radio will attach to. This must be the same for all radios on your network. MY 1234 — Defines the XBee's short address. AP — API enabled  Enables API mode. D0 DI  — Sets the DIO0/AD0 pin as digital input in the game controller. This pin is connected to a button. D1 DI  — Sets the DIO1/AD1 pin as digital input in the game controller. This pin is connected to a button. D2 DI  — Sets the DIO2/AD2 pin as digital input in the game controller. This pin is connected to a button. D3 DI  — Sets the DIO3/AD3 pin as digital input in the game controller. This pin is connected to a button. IC 0F — Configure the game controller XBee to transmit an IO sample when pin DIO0/AD0, DIO1/AD1, DIO2/AD2, or DIO3/AD3 changes.
00001111 (binary) = 0F (hexadecimal)
— keep the default value.
- Write the settings of all XBees with the Write radio settings button at the top of the Radio Configuration section.
4. Connect the components
Create the following circuit with the hardware components. Add the buttons in the following order: Blue, Red, Green, Yellow with the yellow being furthest to the right.
Ensure that each wire is connected to the same column on the breadboard as the pin of the XBee breadboard adapter footprint. This will ensure that the signals to the XBee are correct.
Click to expand diagram
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.
Insert the Race Game Controller 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 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
5. Put it all together
You are now ready to run the racing game:
- Apply power to the Race Game Controller XBee using the included 9V battery and battery clip.
- 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
racegamefolder from the extracted archive, and select the
racegame.pdefile. Click Open.
In the Processing IDE, change line 13 of the code to match your 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
Here the cars are sitting 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: