In this activity, you will create a car racing game using two XBees.
Two XBee 802.15.4 modules
One XBee breadboard adapter
One XBee USB adapter
One solderless breadboard
Blue, Red, Green, and Yellow
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
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.
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
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 page.
- Open the Processing application.
- From the File menu select Open.
- Browse to the
racegame folder from the extracted archive, and select the
racegame.pde file. Click Open.
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";
- Click Run to start the game.
Here the cars are sitting at the starting line ready to race.
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: