In this activity, you will create a car racing game using two XBees.

Requirements

Two XBee 802.15.4 modules 

One XBee breadboard adapter 

One XBee USB adapter


One solderless breadboard

Four push-buttons


Blue, Red, Green, and Yellow

Jumper wires
 
 

One 9V battery clip



One 9V battery


One breadboard power supply

One mini USB cable

Add the XBees to XCTU

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.

Configure the XBees



  1. Use XCTU to configure the following parameters:

    ParamRace Game Controller XBeeReceiver - XBee connected to PCEffect
    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.
    MY1234Defines the XBee's short address.
    APAPI enabled [1]Enables API mode.
    D0DI [3]Sets the DIO0/AD0 pin as digital input in the game controller. This pin is connected to a button.
    D1DI [3]Sets the DIO1/AD1 pin as digital input in the game controller. This pin is connected to a button.
    D2DI [3]Sets the DIO2/AD2 pin as digital input in the game controller. This pin is connected to a button.
    D3DI [3]Sets the DIO3/AD3 pin as digital input in the game controller. This pin is connected to a button.
    IC0FConfigure 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.

Connect the components

  1. 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

  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 Race Game Controller XBee into the breadboard adapter. Push down firmly on the XBee to ensure it is seated properly on the breadboard adapter.

  4. 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

Put it all together

You are now ready to run the racing game:

  1. Apply power to the Race Game Controller XBee using the included 9V battery and battery clip.

  2. Exit XCTU.

  3. Download and extract the latest zip archive from the page.

  4. Open the Processing application.

  5. From the File menu select Open.

  6. Browse to the racegame folder from the extracted archive, and select the racegame.pde file. Click Open.

  7. In the Processing IDE, change line 13 of the code to match your serial port setting that you noted above.

    final String XBEE_PORT = "COM23";
  8. Click Run  to start the game.

  9. Here the cars are sitting at the starting line ready to race.

Play the game

  1. Press the button to your car as fast as you can. The speed of button presses determines the velocity of the car (rectangle).

  2. The first car to the top of the window wins. Race the cars to the top of the screen with a friend.

Troubleshooting

If you are encountering problems, these suggestions may help:

Learn more

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