Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

In this activity, you create a scalable car racing game using three XBees.

Multiexcerpt include
nopaneltrue
MultiExcerptNameonlyTroubleshootingInfo
DisableCachingtrue
PageWithExcerptRFKitsCommon:More excerpts

Numbered Headings
start-numbering-ath2
Section
Column

Requirements

Panel
borderColor#efefef
bgColorwhite
titleBGColor#efefef
borderWidth0
titleHardware

Three XBee 802.15.4 modules

Two XBee breadboard adapters

One XBee USB adapter


Two solderless breadboards

Two push-buttons


Blue and Red

Jumper wires
 

Two 9V battery clips


Two 9V batteries


Two breadboards power supplies

One mini USB cable

Column
width325px
Panel
borderColorwhite
bgColor#efefef
titleColorwhite
titleBGColor#4f5454
borderWidth2
borderStylesolid
titleSteps

Table of Contents
minLevel2
stylenone
classtoc

Panel
borderColor#efefef
bgColorwhite
titleBGColor#efefef
borderWidth0
titleSoftware
Multiexcerpt include
nopaneltrue
MultiExcerptNameprocessingSoftwareRequirements
DisableCachingtrue
PageWithExcerptMore excerpts

Multiexcerpt include
nopaneltrue
MultiExcerptNameXCTUWalktroughTip
DisableCachingtrue
PageWithExcerptRFKitsCommon:More excerpts

Add the XBees to XCTU

Include Page
Add the XBees to XCTU
Add the XBees to XCTU

Note

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.

Configure the XBees

  1. Multiexcerpt include
    nopaneltrue
    MultiExcerptNamerestoreDefaultsInfo
    DisableCachingtrue
    PageWithExcerptRFKitsCommon:More excerpts

  2. Use XCTU to configure the following parameters:

    ParamRace Game Controller 1Race Game Controller 2Receiver - XBee connected to PCEffect
    CHCCCDefines the frequency to use to communicate. This must be the same for all radios on your network.
    ID201520152015Defines the network that a radio will attach to. This must be the same for all radios on your network.
    MY00010002Defines the XBee's short address.
    APAP enabled [1]Enables API mode.
    D1DI [3]DI [3]Sets the DIO1/AD1 pin as digital input in the game controllers. This pin is connected to a button.
    IC0202

    Configures the game controller XBees to transmit an IO sample when pin DIO1/AD1 changes.
    00000010 (binary) = 02 (hexadecimal)

  3. Multiexcerpt include
    nopaneltrue
    MultiExcerptNamewriteSettingsInfo
    DisableCachingtrue
    PageWithExcerptRFKitsCommon:More excerpts

Connect the components

Follow the instructions below for both controllers:

  1. Create the following circuit using the hardware components. Use a blue button for controller #1 and a red button for controller #2.

    Note

    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 to ensure it is seated properly on the breadboard. Do not be afraid to use a little force.

  3. Insert the 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 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

Put it all together

You are now ready to run the racing game.

  1. Apply power to both Race Game Controllers using the 9V battery clips and batteries.

  2. Exit XCTU.

  3. Download and extract the latest zip archive from the
    Digi external link macro
    nameXBee/Arduino Compatible Coding Platform release
    hrefhttps://github.com/digidotcom/XBeeArduinoCodingPlatform/releases
    page.

  4. Open the Processing application.

  5. From the File menu select Open.

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

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

    Multiexcerpt include
    nopaneltrue
    MultiExcerptNamefindPort
    DisableCachingtrue
    PageWithExcerptRFKitsCommon:Troubleshooting

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

  9. The cars are 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:

Include Page
Troubleshooting
Troubleshooting

Learn more

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

  • Digi external link macro
    nameUsing XCTU to configure an XBee
    href../XCTU/Configure+your+modules
  • Digi external link macro
    nameMore about 802.15.4 networks
    hrefhttp://en.wikipedia.org/wiki/IEEE_802.15.4
  • Digi external link macro
    nameMore about XBee digital I/O
    href../WirelessConnectivityKit/Ins+and+Outs
  • Digi external link macro
    nameXBee pin pairing
    href../WirelessConnectivityKit/Pin+pairing
  • Digi external link macro
    nameMore about breadboards
    hrefhttps://learn.sparkfun.com/tutorials/how-to-use-a-breadboard
  • Digi external link macro
    nameConnecting power
    hrefhttps://learn.sparkfun.com/tutorials/how-to-power-a-project
  • Digi external link macro
    nameWiring a switch
    hrefhttps://learn.sparkfun.com/tutorials/switch-basics
  • Digi external link macro
    nameWiring an LED
    hrefhttps://learn.sparkfun.com/tutorials/light-emitting-diodes-leds