Xbee-Proccesing Rx-Tx API package

Hi, I would lije to know if can anyone can helpme I'm trying to conect my xbee and procces the data using proccesin. I have a problem reading the incoming data. so far this is the code that I've written

// used for communication via xbee api
import processing.serial.*; 

// xbee api libraries available at http://code.google.com/p/xbee-api/
// Download the zip file, extract it, and copy the xbee-api jar file 
// and the log4j.jar file (located in the lib folder) inside a "code" 
// folder under this Processing sketch’s folder (save this sketch, then 
// click the Sketch menu and choose Show Sketch Folder).
import java.util.Queue;
import org.apache.log4j.PropertyConfigurator;
import java.util.concurrent.ConcurrentLinkedQueue;
import com.rapplogic.xbee.api.ApiId;
import com.rapplogic.xbee.api.PacketListener;
import com.rapplogic.xbee.api.XBee;
import com.rapplogic.xbee.api.XBeeResponse;
import com.rapplogic.xbee.api.zigbee.ZNetRxIoSampleResponse;

XBee xbee;
Queue<XBeeResponse> queue = new ConcurrentLinkedQueue<XBeeResponse>();
boolean message;
XBeeResponse response;

void setup() {
  try { 
    //optional.  set up logging
    xbee = new XBee();
    // replace with your COM port
    xbee.open("COM20", 115200);

    xbee.addPacketListener(new PacketListener() {
      public void processResponse(XBeeResponse response) {
  catch (Exception e) {
    System.out.println("XBee failed to initialize");

void draw() {
  try {
  catch (Exception e) {

void readPackets() throws Exception {

  while ((response = queue.poll()) != null) {
    // we got something!
    try {
      RxResponseIoSample ioSample = (RxResponseIoSample) response;

      println("We received a sample from " + ioSample.getSourceAddress());

      if (ioSample.containsAnalog()) {
        println("10-bit temp reading (pin 19) is " +
    catch (ClassCastException e) {
      // not an IO Sample



Sign In or Register to comment.