background image

  while (XBee.available() < 4)
    ; // Wait for pin and three value numbers to be received
  char pin = XBee.read(); // Read in the pin number
  int value = ASCIItoInt(XBee.read()) * 100; // Convert next three
  value += ASCIItoInt(XBee.read()) * 10;     // chars to a 3-digit
  value += ASCIItoInt(XBee.read());          // number.
  value = constrain(value, 0, 255); // Constrain that number.

  // Print a message to let the control know of our intentions:
  XBee.print("Setting pin ");
  XBee.print(pin);
  XBee.print(" to ");
  XBee.println(value);

  pin = ASCIItoInt(pin); // Convert ASCCI to a 0-13 value
  pinMode(pin, OUTPUT); // Set pin as an OUTPUT
  analogWrite(pin, value); // Write pin accordingly
}

// Read Digital Pin
// Send 'r' or 'R' to enter
// Then send a digital pin # to be read
// The Arduino will print the digital reading of the pin to XBee.
void readDPin()
{
  while (XBee.available() < 1)
    ; // Wait for pin # to be available.
  char pin = XBee.read(); // Read in the pin value

  // Print beggining of message
  XBee.print("Pin ");
  XBee.print(pin);

  pin = ASCIItoInt(pin); // Convert pin to 0-13 value
  pinMode(pin, INPUT); // Set as input
  // Print the rest of the message:
  XBee.print(" = "); 
  XBee.println(digitalRead(pin));
}

// Read Analog Pin
// Send 'a' or 'A' to enter
// Then send an analog pin # to be read.
// The Arduino will print the analog reading of the pin to XBee.
void readAPin()
{
  while (XBee.available() < 1)
    ; // Wait for pin # to be available
  char pin = XBee.read(); // read in the pin value

  // Print beginning of message
  XBee.print("Pin A");
  XBee.print(pin);

  pin = ASCIItoInt(pin); // Convert pin to 0-6 value
  // Printthe rest of the message:

Page 19 of 24

Summary of Contents for Shield

Page 1: ...municate in transparency mode However this can apply to the XBee Series 3 module as long as you configure the firmware to the legacy 802 15 4 protocol For more information check out the Exploring XBee...

Page 2: ...SparkFun XBee Shield WRL 12847 16 95 26 Favorited Favorite 25 Wish List Page 2 of 24...

Page 3: ...SparkFun XBee 3 Wireless Kit KIT 15936 78 95 2 Favorited Favorite 13 Wish List Page 3 of 24...

Page 4: ...h we explain in a separate tutorial Covered In This Tutorial The goal of this tutorial is to set up wireless XBee communication between a computer and an Arduino XBee Shield combo Then using a termina...

Page 5: ...her with atrace antenna wire antenna or u fl connector For more help picking an XBee check out ourXBee Buying Guide Heads up While this tutorial was written for XBee Series 1 you can still follow alon...

Page 6: ...lain how to configure XBee networks and addresses In addition to that tutorial we also recommend checking these guides out Serial Communication Serial communication is critical to controlling and mana...

Page 7: ...s What they are and how to assemble them Favorited Favorite 5 Hardware Overview Here s a quick overview of the most components of the XBee Shield Below we ll go more in depth on the most important com...

Page 8: ...to any device attached to the Arduino s hardware UART So to avoid any problems that might arise from connecting the XBee to the Arduino s hardware UART we usually take advantage of the Software Serial...

Page 9: ...xplaining the operation of each LED LED Label LED Color XBee Pin Connection Default Operation Notes PWR Red 3 3V Indicates power is present DIO5 Green Associate DIO5 Associated indicator blinks when t...

Page 10: ...re is some white silkscreen on the Shield PCB to help orient your XBee as you re plugging it in Make sure to match up the XBee s two diagonal edges with the two diagonal lines on the PCB With everythi...

Page 11: ...is example assumes you haveXCTU installed and two compatibly configured XBees one connected to your computer via a USB Explorer or Dongle or Serial Explorer and another plugged into the Shield Arduino...

Page 12: ...reSerial XBee 2 3 RX TX For Atmega2560 ATmega32U4 etc XBee s DOUT TX is connected to pin 10 Arduino s Software RX XBee s DIN RX is connected to pin 11 Arduino s Software TX SoftwareSerial XBee 10 11 R...

Page 13: ...ge for the Software Serial library Arduino Software Serial Library Pin Definitions To use re define the software serial pins on an Arduino Mega 2560 or Arduino Leonardo you would just need to comment...

Page 14: ...cate with the XBee because the Arduino is rebooting Hardware Serial Passthrough This example is for those trying to use the hardware UART on an ATmega32U4 based Arduino Copy and upload the sketch belo...

Page 15: ...ad XBee UART1 pins 0 and 1 if Serial1 available XBee UART1 pins 0 and 1 If data comes in from XBee send it out to serial monitor Serial write Serial1 read Serial port Note If you are using an Arduino...

Page 16: ...xploring XBee tutorial Example Remote Control Arduino Setting up a chat system is fun but where XBees and the XBee Shield really shine is in passing data to and from an Arduino so you can remotely con...

Page 17: ...fics IDE Arduino 1 0 5 Hardware Platform SparkFun RedBoard XBee Shield XBee Series 1 1mW w whip antenna XBee USB Explorer connected to computer with another XBee Series 1 1mW connected to that This co...

Page 18: ...le XBee available 2 Wait for pin and value to become available char pin XBee read char hl ASCIItoHL XBee read Print a message to let the control know of our intentions XBee print Setting pin XBee prin...

Page 19: ...enter Then send a digital pin to be read The Arduino will print the digital reading of the pin to XBee void readDPin while XBee available 1 Wait for pin to be available char pin XBee read Read in the...

Page 20: ...prints that print a usage menu over to the other XBee void printMenu Everything is F d which stores the strings in flash That ll free up SRAM for more importanat stuff XBee println XBee println F Ardu...

Page 21: ...he Arduino sketch first starts up it will print a helpful usage menu After that s printed follow the directions to send commands to your Arduino To control pins 10 11 12 and 13 send the hexadecimal eq...

Page 22: ...ing to a single computer The power of XBees comes from their simplicity they make your projects wireless by simply serial printing Resources and Going Further That should be enough to get you started...

Page 23: ...p further by controlling it with an XBee Simon Splosion Wireless This is a tutorial demonstrating one of many techniques to hack the Simon Says We will highlight the technique to take your Simon Says...

Page 24: ...Page 24 of 24...

Reviews: