XBee Wireless

Overview

This is the 2.4GHz XBee module from Digi (formally Maxstream). These modules take the 802.15.4 stack and wrap it into a simple to use serial command set. These modules allow a very reliable and simple communication between microcontrollers, computers, systems, really anything with a serial port! Point to point and multi-point networks are supported.

The XBee allows you to communicate with your laptop, iPhone or a USB Playstation controller. You simply need Processing (download below) to convert the input into something that the Arduino can receive.

YOU NEED TO USE A USB CABLE TO UPLOAD YOUR PROGRAM – YOU CANNOT USE XBEE TO UPLOAD PROGRAMS TO THE BOARD. YOU ALSO NEED TO DISCONNECT THE XBEE FROM THE ARDUINO BOARD WHILE YOU UPLOAD. -XBee Explorer Dongle -XBee 1mW Chip Antenna-Data sheetParts

-Arduino microcontroller and carrier board

-LiPo battery

-XBee pair with USB dongle

-Laptop

Prepare the breadboard

Not needed.

Program the Microcontroller

/**
 * @file: Arduino control led via XBee
 * @author Daniela Faas (dfaas@mit.edu)
 * @date: 3/31/2011
 *
 * @section DESCRIPTION
 * This code allows control of an LED via XBee module
 *
 */
 
// global variables
int message = 0;           // variable to receive data from the serial port
#define ledpin 13            // LED connected to pin 13 (on-board LED)
//--- Function: Setup ()
void setup()
{
  pinMode(ledpin, OUTPUT);     // pin 48 (on-board LED) as OUTPUT
  Serial.begin(9600);          // start serial communication at 9600bps
}
//--- Function: loop ()
void loop()
{
  if( Serial.available() > 0 )        // if data is available to read
  {
    message = Serial.read();          // read it and store it in 'val'
    if( message == 'R' )              // if 'R' was received
    {
      digitalWrite(ledpin, HIGH);     // turn ON the LED
    }
    else if (message == 'r')
    {
      digitalWrite(ledpin, LOW);       // otherwise turn it OFF
    }
  }
  delay(100);                         // wait 100ms for next reading
}

Processing Sketch

Download Processing. The values from the laptop are sent to Processing. Processing also includes graphical tools. Processing is a simple way to create drawings, animations and interactive graphics. Visualization of data coming from an Arduino is fairly straightforward. Check out the Processing reference page to get more details on mouse and keyboard inputs.

Code tested with Processing 1.2.1.

/**
 * @file: Processing control led via XBee
 * @author Daniela Faas (dfaas@mit.edu)
 * @date: 3/31/2011
 *
 * @section DESCRIPTION
 * This code allows control of an LED via XBee
 * Similar to bluetooth tutorial!
 * Modified by DF.
 *
 */
//import class to set up serial connection with wiring board
import processing.serial.*;     //  Load serial library
Serial arduinoPort;             //  Set arduinoPort as serial connection
//--- Function: setup
void setup()
{
  //set up window
  size(200, 200);
  noStroke();
 
  // List all the available serial ports in the output pane.
  // You will need to choose the port that the Wiring board is
  // connected to from this list. The first port in the list is
  // port #0 and the third port in the list is port #2.
  println(Serial.list());
 
  // Open the port that the Wiring board is connected to (in this case 1
  // which is the second open port in the array)
  // Make sure to open the port at the same speed Wiring is using (9600bps)
  arduinoPort = new Serial(this, Serial.list()[4], 9600);
}
//--- Function: draws background and rectangles
void draw()
{
  background(255);
  //Turn LED on and off if buttons pressed where
  //R = on (high) and r = off (low)
  if(keyPressed == true)
  {
     arduinoPort.write('R');
     println("on");
     fill(0);
  }
  else
  {
     arduinoPort.write('r');
     println("off");
     fill(255);
  }
  rect(25, 25, 50, 50);
}