(edit sidebar)
Intro to Physical Computing Syllabus

Research & Learning

Other Class pages

Shop Admin

ITP Help Pages
Tom's pcomp site
DanO's pcomp site


X Bee Telephone Game

This is an exercise for four or more people. Each person needs:

  • Arduino
  • XBee Radio
  • XBee Breakout Board or Wireless shield
  • Sensor or actuator

The exercise is to make a Rube Goldberg machine made of pairs of simple devices, connected together wirelessly. The pairs are lined up in a chain. It starts with a radio message from a master device ("instructor device" below). The first device in the chain gets the message and does something physically. The second device senses that physical action and sends a wireless message (through the serial port). The third device gets the message and does something else physical. The fourth device senses that physical action and sends another message. And so on, ad infinitum

People work in pairs. Each pair gets a number, from 1 to however many pairs there are.

Each group will build two physical devices:

  • The first person makes an Arduino application that will listen for serial input. When the device receives its group number (ASCII-encoded) in the serial input (which is attached to its XBee radio), the device will generate a physical output. It will also echo the serial input to its serial output.
  • All other incoming serial messages will be ignored.
  • The person makes a device that will read the physical output from the first through an appropriate input sensor. When it receives an input, it will send (group number + 1) out the serial output to its XBee radio.

Each group will have two XBee radios, one on the input device and one on the output device.

Radios will be configured as follows:

  • Radio on the first device:
    • my address (ATMY) = group number + (group number -1)
    • destination address = 0
  • Radio on on the second device:
    • my address: (group number-1) * 2
    • destination address: group number * 2

Instructors will build a device that can receive from every group, and send to any chosen group:

  • Arduino attached to an XBee Radio, configured as follows:
  • my address: 0
  • transmit address: 0xFF
  • Arduino will have one pushbutton for every group in the class
  • If an ASCII-encoded number is received in the serial port, the Arduino will display it
  • If a group's pushbutton is pressed, the Arduino will send that group's number serially to the XBee radio.

The instructor device is designed so that it knows how far the chain of events has moved, and can signal any device to pick up the chain.

Once the devices are built, set them up so that each pair's devices trigger each other according to the diagram below:

The important part: Keep it Simple

The code for these devices is very simple, Below, you can see three flowcharts illustrating the code:

Input device

Code (simplest possible version)

int myGroupNumber = 2;     // change this to your group number
int lastReading = LOW;    // for the previous reading of the sensor

void setup() {
  // initialize serial communciation:
  Serial.begin(9600);
  pinMode(3, INPUT);
}

void loop() {
  // listen for physical input:
  int sensorReading = digitalRead(3);

  if (sensorReading != lastReading && sensorReading == HIGH) {
    // something important happened
    // (input changed from low to high),
    // so send (groupnumber+1) to serial out:
    Serial.println(myGroupNumber+1);
  }
  // save the current reading for comparison
  // next time through the loop:
  lastReading = sensorReading;
}

Output device

Code (simplest possible version)'

int myGroupNumber = 2;     // change this to your group number

void setup() {
  // initialize serial communiation:
  Serial.begin(9600);
  pinMode(3, OUTPUT);
}

void loop() {
  int serialValue = 0;
  // listen for Serial input. This line
  // expects an ASCII-encoded numeric string:
  if (Serial.available() > 0) {
    serialValue = Serial.parseInt();
  }

  // check to see if serial value is my group number:
  if (serialValue == myGroupNumber ) {
    // message was my group number
    // so generate physical output:
    digitalWrite(3, HIGH);
    Serial.print(myGroupNumber+1);
  }  
  else {
    // stop physical outut:
    digitalWrite(3, LOW);
  }
}

Instructor device

Your instructor will build this device, so you don't have to.

Note: the instructor device code below uses an LCD screen and the LiquitCrystal library to drive it. For more on this library, see the Arduino LiquidCrystal library documentation

Code (simplest possible version)'

// include the library code:
#include <LiquidCrystal.h>

int lastReading[8];         // set up an array of 8 buttons (1 per group)
int lastGroupNumber = 0;    // last group number received


// initialize the library with the numbers of the interface pins
// note: you're using the analog in pins as output pins here.
// you can do that:
LiquidCrystal lcd(12, 11, A0, A1, A2, A3);

void setup() {
  // initialize serial communiation:
  Serial.begin(9600);

  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // pushbuttons are on pins 2 through 9.
  // make them inputs:
  for (int buttonNum = 2; buttonNum < 9; buttonNum++) {
    pinMode(buttonNum, INPUT);
  }
}

void loop() {
  // an array for storing current states of the buttons:
  int currentReading[8];

  // loop over the buttons and check their current state
  // against their last state:
  for (int buttonNum = 2; buttonNum < 9; buttonNum++) {
    // array counts from 0 - 7, but buttons are
    // numbered 2-9:
    currentReading[buttonNum-2] = digitalRead(buttonNum);
    // if the button you're checking has changed,
    // and it's HIGH, then send the last group number out serially:
    if (currentReading[buttonNum-2] != lastReading[buttonNum-2] &&
      currentReading[buttonNum-2] == HIGH) {
      Serial.println(lastGroupNumber);
    }
    // save the current reading for comparison
    // next time through the loop:
    lastReading[buttonNum-2] = currentReading[buttonNum-2];
  }

  // listen for Serial input. This line
  // expects an ASCII-encoded numeric string:
  if (Serial.available() > 0) {
    int lastGroupNumber = Serial.parseInt();

  }

  // check to see if serial value is greater than 0:
  if (lastGroupNumber > 0) {
    // set the LCD cursor to column 0, line 1
    // (note: line 1 is the second row, since counting begins with 0):
    lcd.setCursor(0, 1);
    // Print a message to the LCD.
    lcd.print(lastGroupNumber);
  }  
}
  Edit | View | History | Print | Recent Changes | Search Page last modified on October 25, 2013, at 10:59 PM