#Blog 3: XBEES Recitation

1. PROGRAMMING THE XBEES–Simple

2. COMMUNICATION FROM LILYPAD A TO LILYPAD B

2.1. PROGRAMMING THE LILYPAD A


2.2. CONNECTING THE LILYPAD A TO THE XBEE A

*The battery is the computer, and we need to connect the +&- of XBEE and LILYPAD together to complete the circuit.

*The “Port” in Arduino needs to be constantly checked for connection.


2.3. PROGRAMMING THE LILYPAD B

*The destination for XBEE B should be B


3. COMMUNICATION FROM ONE LILYPAD TO PROCESSING

*This code should be operated on B’s computer so that it can successfully receive the signal.

import processing.serial.*;
int NUM_OF_VALUES_FROM_XBEE = 1;   /** YOU MUST CHANGE THIS ACCORDING TO YOUR PROJECT **/
int sensorValues[];      /** this array stores values from the Lilypad1 **/
String myString = null;
Serial myPort;
void setup() {
  size(500,500)
  setupSerial();
}
void setupSerial() {
  printArray(Serial.list());
  myPort = new Serial(this, Serial.list()[ 8 ], 9600);
  // WARNING!
  // You will definitely get an error here.
  // Change the PORT_INDEX to 0 and try running it again.
  // And then, check the list of the ports,
  // find the port "/dev/cu.usbmodem----" or "/dev/tty.usbmodem----" 
  // and replace PORT_INDEX above with the index number of the port.

  myPort.clear();
  // Throw out the first reading,
  // in case we started reading in the middle of a string from the sender.
  myString = myPort.readStringUntil( 10 );  // 10 = '\n'  Linefeed in ASCII
  myString = null;

  sensorValues = new int[NUM_OF_VALUES_FROM_XBEE];
}
void draw() {
  getSerialData();
  printArray(sensorValues);

  circle(width/2, height/2, sensorValues[0]);
}
void getSerialData() {
  while (myPort.available() > 0) {
    myString = myPort.readStringUntil( 10 ); // 10 = '\n'  Linefeed in ASCII
    if (myString != null) {
      String[] serialInArray = split(trim(myString), ",");
      if (serialInArray.length == NUM_OF_VALUES_FROM_XBEE) {
        for (int i=0; i<serialInArray.length; i++) {
          sensorValues[i] = int(serialInArray[i]);
        }
      }
    }
  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *