In this activity, you will build a rock-paper-scissors game using XBees and an Arduino.
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.
3. Configure the XBees
Select two of the XBee modules to be the remote modules. The third and final module will be connected to the Arduino, and will be referred to as the local XBee.
- Restore the default settings of all XBees with the Load default firmware settings
Use XCTU to configure the following parameters:
Param 110px|Local XBee 110px|Remote XBee 1 110px|Remote XBee 2 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. DH — 0 0 DH and DL combined form the destination address. This is where the notifications are sent when the button value changes. The address being configured here is known as a short address. A short address is assigned during configuration. An XBee also has a long address (SH and SL combined) which is assigned permanently when the unit is manufactured. DL — 1234 1234 MY 1234 1235 1236 Defines the XBee's short address. AP API enabled w/PPP  — — Enables API mode with escaping. D1 — DI  DI  Sets the DIO1/AD1 pin as digital intput in the remote XBees. This pin is connected to a button. D2 — DI  DI  Sets the DIO2/AD2 pin as digital intput in the remote XBees. This pin is connected to a button. D3 DI  DI  Sets the DIO3/AD3 pin as digital intput in the remote XBees. This pin is connected to a button. IC — 0E 0E Configures the remote XBees to transmit an I/O sample when pin DIO1/AD1, DIO2/AD2, or DIO3/AD3 change.
00001110 (binary) = 0E (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 each of the XBee breadboard adapters.
Ensure that each wire is connected to the same column on the breadboard as the indicated 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 each adapter board to ensure they are seated properly on the breadboards.
- Insert the remote XBees into the breadboard adapters. Push down firmly on each XBee to ensure they are seated properly on the adapter boards.
Double check that the breadboard adapters and XBees 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
Create the following circuit with the Arduino and XBee Shield, using the remaining breadboard.
Click to expand diagram
- Insert the local XBee into the XBee Shield.
5. Put it all together
- Apply power to the remote XBees using the 9V battery clips and batteries.
- Connect the Arduino Leonardo to your computer using the micro USB cable.
- Download and extract the latest zip archive from the XBee/Arduino Compatible Coding Platform release page.
- Open the Arduino IDE.
- From the File menu select Open.
- Browse to the
rockpaperscissorsfolder in the extracted zip archive, and select the
rockpaperscissors.inofile. Click Open.
Find the following section at the top of the file and modify it to include the MY values for your remote nodes, and to specify the pins you are using, if they differ from the diagrams.
Click Upload to upload and run the sketch on the Arduino Leonardo.
6. Play the game
- The Arduino "counts down" by flashing each of the three pairs of LEDs in succession, then lighting them all up.
- Both players press one of the three digital-input buttons on their board. (In the code provided, DIO1 = Rock, DIO2 = Paper, DIO3 = Scissors.)
- Once both inputs have been registered, all the LEDs go off except those corresponding to the player inputs.
- One, or both, of the LEDs will flash on and off, to indicate the winner. If both flash, then it was a tie.
- The game starts again.
7. Exercises for the reader
Add scoring to the Arduino application. For example, you might connect some additional LEDs to the Arduino and use those to indicate each player's score.
Rearrange the components connected to the Arduino so that the rows of LEDs are parallel with each other rather than in-line with each other.
If you are encountering problems, these suggestions may help:
For more information about the hardware and software you use in this activity, see: