Go Down

Topic: Getting an error with Xbee Lib (Read 735 times) previous topic - next topic

33chen

Hi Everyone,

I have put Xbee and another examples in the liberaries under My Document. I tried to verify the code of Xbee "Series1_IoSamples". The error messages show as follows. I have searched about for the solution. I have followed the advice to have Xbee liberary installed under liberaries from The folder of Documents. However, the error is still there. A little bit frustrating. By the way, I use Windows 7 and 64 bit OS. My IDE software is Arduino 1.0.3 version.


Series1_IoSamples:41: error: 'SoftwareSerial' does not name a type
Series1_IoSamples:43: error: 'XBee' does not name a type
Series1_IoSamples:45: error: 'Rx16IoSampleResponse' does not name a type
Series1_IoSamples.pde: In function 'void setup()':
Series1_IoSamples:51: error: 'xbee' was not declared in this scope
Series1_IoSamples:53: error: 'nss' was not declared in this scope
Series1_IoSamples.pde: In function 'void loop()':
Series1_IoSamples:58: error: 'xbee' was not declared in this scope
Series1_IoSamples:63: error: 'RX_16_IO_RESPONSE' was not declared in this scope
Series1_IoSamples:64: error: 'ioSample' was not declared in this scope
Series1_IoSamples:66: error: 'nss' was not declared in this scope
Series1_IoSamples:105: error: 'nss' was not declared in this scope
Series1_IoSamples:110: error: 'nss' was not declared in this scope

Code: [Select]
#include <XBee.h>
#include <SoftwareSerial.h>

/*
This example is for Series 1 XBee Radios only
Receives I/O samples from a remote radio with 16-bit addressing.
The remote radio must have IR > 0, at least one digital or analog input enabled
and DL set to the 16-bit address of the receiving XBee (the one connected to the Arduino).

This example uses the SoftSerial library to view the XBee communication.  I am using a
Modern Device USB BUB board (http://moderndevice.com/connect) and viewing the output
with the Arduino Serial Monitor.   
*/

// Define NewSoftSerial TX/RX pins
// Connect Arduino pin 8 to TX of usb-serial device
uint8_t ssRX = 8;
// Connect Arduino pin 9 to RX of usb-serial device
uint8_t ssTX = 9;
// Remember to connect all devices to a common Ground: XBee, Arduino and USB-Serial device
SoftwareSerial nss(ssRX, ssTX);

XBee xbee = XBee();

Rx16IoSampleResponse ioSample = Rx16IoSampleResponse();
// 64-bit response is same except api id equals RX_64_IO_RESPONSE and returns a 64-bit address
//Rx64IoSampleResponse ioSample = Rx64IoSampleResponse();

void setup() {
  Serial.begin(9600);
  xbee.setSerial(Serial);
  // start soft serial
  nss.begin(9600);
}

void loop() {
  //attempt to read a packet   
  xbee.readPacket();

  if (xbee.getResponse().isAvailable()) {
    // got something

    if (xbee.getResponse().getApiId() == RX_16_IO_RESPONSE) {
      xbee.getResponse().getRx16IoSampleResponse(ioSample);

      nss.print("Received I/O Sample from: ");
      nss.println(ioSample.getRemoteAddress16(), HEX); 

      nss.print("Sample size is ");
      nss.println(ioSample.getSampleSize(), DEC);

      if (ioSample.containsAnalog()) {
        nss.println("Sample contains analog data");
      }

      if (ioSample.containsDigital()) {
        nss.println("Sample contains digtal data");
      }
     
      for (int k = 0; k < ioSample.getSampleSize(); k++) {
        nss.print("Sample ");
        nss.print(k + 1, DEC);   
        nss.println(":");   
       
        for (int i = 0; i <= 5; i++) {
          if (ioSample.isAnalogEnabled(i)) {
            nss.print("Analog (AI");
            nss.print(i, DEC);
            nss.print(") is ");
            nss.println(ioSample.getAnalog(i, k)); 
          }
        }
       
        for (int i = 0; i <= 8; i++) {
           if (ioSample.isDigitalEnabled(i)) {
            nss.print("Digtal (DI");
            nss.print(i, DEC);
            nss.print(") is ");
            nss.println(ioSample.isDigitalOn(i, k));
          }
        }
      }
    }
    else {
      nss.print("Expected I/O Sample, but got ");
      nss.print(xbee.getResponse().getApiId(), HEX);
    }   
  }
  else if (xbee.getResponse().isError()) {
    nss.print("Error reading packet.  Error code: "); 
    nss.println(xbee.getResponse().getErrorCode());
  }
}

PaulS

Quote
I have put Xbee and another examples in the liberaries under My Document.

Are your Arduino sketches stored in My Documents, too? Unlikely, so it appears as though libraries is in the wrong place.

A screen show of the Windows Explorer window showing where the sketches and libraries are would be helpful.

I have an Arduino folder in My Documents that contains all my sketch folders and the libraries folder where the XBee folder is.

Go Up