Have a Question?

XBee Rock, Paper, Scissors

Would you like to be able to play automated Rock, Paper, Scissors electronically and wirelessly? Then this is the project for you! This project uses two Mbed microcontroller and a couple of Digi XBee radios to enable two people to choose a button representing either Rock, Paper, or Scissors and determines the winner on your own LCD screen.


rps1
Player 1 is ready to play

rps2
Player 2 is ready to play

rps3
Player 1 chooses Rock

rps4
Player 2 chooses Rock

rps5
Player 1 chooses Paper

rps6
Player 2 chooses Scissors

rps7
Player 1 resets

rps8
Player 2 resets


Parts:

  • Four solderless breadboards (MS MKKN2, AF 64, DK 438-1045-ND, SFE PRT-09567)
  • One XBee radio (Series 2/ZB firmware) configured as a Zigbee Coordinator AT mode (Digi: XB24-27WIT-004, DK 602-1098-ND)
  • One XBee radio (Series 2/ZB firmware) configured as a Zigbee Router AT mode (Digi: XB24-27WIT-004, DK 602-1098-ND)
  • Hookup wire or jumper wire kit (MS MKSEEED3, AF 153, DK 923351-ND, SFE PRT-00124)
  • XBee USB serial adapter (XBee Explorer or Digi Evaluation board) (AF 247, SFE WRL-08687)
  • Two XBee shields (Seeed Studio SLD01103P, Arduino A000065, SF WRL-10854)
  • Wire strippers (AF 147, DK PAL70057-ND, SFE TOL-08696)
  • Two 16x2 character LCD displays (with HD44780 parallel interface) (AF 181, DK 67-1758-ND, SFE LCD-00255)
  • Two 2.4K ohm resistors
  • Eight 200 ohm resistors (DK P200BACT-ND)
  • Two 16-pin single-row male header (DK S1012E-36-ND, SFE PRT-00116)
  • Eight momentary pushbutton switches (SPE COM-09190)
  • Two Mbed Freedom boards (Freescale FRDM-KL25Z)
  • Two USB cables for the Mbed boards
  • Soldering tools (any hardware store)
  • An adventurous mind

 

Using the Mbed Online Compiler

This project used the Mbed software, known as the online compiler, in order to program the Mbed microcontroller. You can sign up for a free account to access the online compiler at www.mbed.org. There are many versions of the Mbed, so make sure you select the correct platform. A basic guide to how to use it can be found at the same Mbed website.

 

Prepare and Configure your Coordinator Radio

  1. Use X-CTU to set the designated coordinator radio in AT mode.
  2. Configure the coordinator radio with a PAN ID (between 0x0 and 0xFFFFFFFFFFFFFFFF). Make sure you note this ID so that you can set up your router radio with the same one.
  3. Enter in the High and Low destination addresses of your router radio.

 

Prepare and Configure your Router Radio

  1. Use X-CTU to set the designated router radio in AT mode.
  2. Configure the router radio with the PAN ID you set the coordinator radio with.
  3. Set JV to 1 to ensure that your router attempts to rejoin the coordinator on startup.
  4. Enter in the High and Low destination addresses of your coordinator radio.

 

Construct the Rock, Paper Scissors Game

*These are the instructions for building one. They are the exact same, so just repeat the process. It does not matter which board holds the coordinator and which board holds the router radio.*

rps9
Figure 1.
  1. Insert your Coordinator/Router XBee Radio onto the XBee shield, and then insert the shield onto the Mbed board.
  2. Connect Mbed ground to both breadboards’ ground rails.
  3. Connect Mbed 3.3 volt power to the right breadboard power rail and Mbed 5 volt power to the left breadboard.
  4. Connect the power and ground on one side of the right breadboard to the other side using jumper wire or the metal leads cut off from resistors. This is not necessary on the left breadboard.
  5. Trim the male headers down to 16 pins and then solder the row of male headers into the LCD screen.
  6. Insert the LCD onto the edge of the left breadboard.
  7. Connect the LCD pin 1 to the ground rail on the breadboard.
  8. Connect the LCD pin 2 to the power rail on the breadboard.
  9. Attach the potentiometer to the breadboard next to the LCD screen. There are three pins: two terminals (the ends) and a wiper pin (the middle). Connect one terminal of the potentiometer to power and the other to ground (it doesn’t matter which). Connect the wiper (the center pin) to the LCD pin 3.
  10. Connect the LCD pin 4 to the ground rail on the breadboard.
  11. Connect the LCD pins 5, 6, 11, 12, 13, and 14 to Mbed pins PTA13, PTD5, PTD0, PTD2, PTD3, AND PTD1 (shield pins 8, 9, 10, 11, 12, and 13) respectively.
  12. Connect the LCD pin 15 to the power rail on the breadboard.
  13. Connect the LCD pin 16 to the ground rail on the breadboard.
  14. Insert a pushbutton onto the right breadboard towards the left end and centered. Ensure that the pushbutton connections are on different rails. If you are unsure, you can test this using an LED.
  15. Connect the breadboard power to one end of the push button.
  16. On the other end on the opposite side of the pushbutton, connect a wire to Mbed PTA4 (shield digital pin 4). On that same breadboard rail, connect a 200 ohm resistor to ground. As an optional enhancement, you can connect the ground pin of an LED to the breadboard ground rail and the power pin of the LED to the same connection on the pushbutton in order to be notified every time the button is pushed.
  17. Repeat the previous three steps for the other three pushbuttons, spacing them evenly towards the right. The second will connect to Mbed PTA5 (shield digital pin 5), the third will connect to Mbed PTC8 (shield pin 6), and the fourth will connect to Mbed PTC9 (shield pin 7).
  18. Refer to figure 1 for visual reference.
  19. Repeat.

 

Program the Mbed Microcontrollers

Upload the following program to the main.cpp of the Mbed microcontrollers. Be sure to include Text.h and mbed.h, which can both be found online.

#include "mbed.h"
#include "TextLCD.h"Serial xbee(USBTX, USBRX);
TextLCD lcd(PTA13, PTD5, PTD0, PTD2, PTD3, PTD1, TextLCD::LCD16x2);
DigitalIn enable1(PTA4);
DigitalIn enable2(PTA5);
DigitalIn enable3(PTC8);
DigitalIn enable4(PTC9);int main() {

char move;
lcd.locate(0,0);
lcd.printf("ROCK, PAPER,    ");
lcd.locate(0,1);
lcd.printf("SCISSORS        ");

while(1) {

if (enable1){

xbee.printf("R");
wait(.05);

if (xbee.readable()) {

move = xbee.getc();

if (move == 'R'){

lcd.locate(0,0);
lcd.printf("ROCK VS ROCK    ");
lcd.locate(0,1);
lcd.printf("YOU TIED        ");

}

if (move == 'P') {

lcd.locate(0,0);
lcd.printf("ROCK VS PAPER   ");
lcd.locate(0,1);
lcd.printf("YOU LOST:(      ");

}

if (move == 'S') {

lcd.locate(0,0);
lcd.printf("ROCK VS SCISSORS");
lcd.locate(0,1);
lcd.printf("YOU WON!:)      ");

}

if (move == 'E') {

lcd.locate(0,0);
lcd.printf("ROCK, PAPER,    ");
lcd.locate(0,1);
lcd.printf("SCISSORS        ");

}
}
}

if (enable2){

xbee.printf("P");
wait(.05);
if (xbee.readable()) {

move = xbee.getc();

if (move == 'R'){

lcd.locate(0,0);
lcd.printf("PAPER VS ROCK   ");
lcd.locate(0,1);
lcd.printf("YOU WON!:)      ");

}

if (move == 'P') {

lcd.locate(0,0);
lcd.printf("PAPER VS PAPER  ");
lcd.locate(0,1);
lcd.printf("YOU TIED        ");

}

if (move == 'S') {

lcd.locate(0,0);
lcd.printf("PAPER V SCISSORS");
lcd.locate(0,1);
lcd.printf("YOU LOST:(      ");

}

if (move == 'E') {

lcd.locate(0,0);
lcd.printf("ROCK, PAPER,    ");
lcd.locate(0,1);
lcd.printf("SCISSORS        ");

}
}
}

Tags: XBee
0