Pages: [1]   Go Down
Author Topic: xbee.h will not compile with MICRO  (Read 1946 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am trying to use the MICRO with Xbee but I get the error

error: cannot convert 'Serial_*' to 'HardwareSerial*' in assignment

I read the post about a fix for the LEONARDO as shown in:


But I still get the error. Is there another code for the MICRO that is different from the LEONARDO or am I missing something else that I have to put in the code. This is the code I added to the beginning of xbee.cpp

Code:
#if defined(USBCON)
   _serial = &Serial1;
#else
   _serial = &Serial;
#endif

What is "USBCON", where is it defined/used??

Appreciate the help.

Bill
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The url for the LEONARDO post is
http://arduino.cc/forum/index.php/topic,111354.0.html

Bill
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I am trying to use the MICRO with Xbee but I get the error
"I'm trying to compile a sketch, but I won't show you what sketch, for the MICRO, and I'm having problems. Can you help?"

Did I summarize your post correctly?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry about that; I was assuming the problem was in the xbee.h or xbee.cpp library files; anyway heres the core of the code.

Appreciate quick response and the help.




Code:
#include <Keypad.h>
#include <Button.h>
#include <XBee.h>
#include <AltSoftSerial.h>
#include <SoftwareSerial.h>

uint8_t LCDTxPin = 13;
SoftwareSerial mySerial = SoftwareSerial(255, LCDTxPin);

const int launch_A = 10;
const int launch_B = 11;
int buttonstate_A = 0;
int buttonstate_B = 0;
uint8_t count = 0;
uint8_t ncount = 0;

// Define AltSoftSerial TX/RX pins
// Connect Arduino pin 8 to TX of usb-serial device
uint8_t ssRX;
// 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
AltSoftSerial nss(ssRX, ssTX);

XBee xbee = XBee();

unsigned long start = millis();

uint8_t hset = 0x01;
// set payload to launcher ID;i.e hand station 1 and Station 1 and launcher 1
        // set payload to launcher ID;i.e hand station 8 and Station 15 and launcher 5
uint8_t payload []= {hset,0x01,0x01};

// Set DIO0 (pin 20) to Analog Input
uint8_t d0Cmd[] = { 'D', '0' };
uint8_t d0Value[] = { 0x4 };

uint32_t xbee_SH = 0x0013a200;
uint32_t xbee_SL = 0x40923f1f;

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
  //MEMBRAIN KEYPAD
char keys[ROWS][COLS] =
{
  {1,2,3},
  {4,5,6},
  {7,8,9},
  {'*',0,'#'}
};
byte rowPins[ROWS] = {8, 7, 6, 5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {4, 3, 2}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

int attempt[2]={0,0}; // used for comparison for statioID

char P_PIN[6]={1,2,3,4,5,6}; // our secret (!) number
char P_attempt[6]={0,0,0,0,0,0}; // used for password comparison

int z=0;
uint8_t key1;
uint8_t key2;
uint8_t StationID = 0;
uint8_t nStationID = 0;
char gotolauncher;

void setup()
{
  pinMode(LCDTxPin, OUTPUT);
  digitalWrite(LCDTxPin, HIGH);
  pinMode(launch_A, INPUT);
  pinMode(launch_B, INPUT);
  digitalWrite(launch_A, HIGH);
  digitalWrite(launch_B, HIGH);
  Serial.begin(9600);          //MICRO USB serial
  //Serial1.begin(57600);        //xbee serialon pins 1,2
  xbee.setSerial(Serial1);
  // start soft serial for debugging
  nss.begin(9600);
  // start LCD serial
  mySerial.begin(9600); //start LCD serial
  mySerial.write(0x7c);
  mySerial.write(130);
 
 delay(1000);
}

void sendPacket()
{
     // SH + SL of your remote radio
  XBeeAddress64 remoteAddress = XBeeAddress64(xbee_SH, xbee_SL);
    // Create a remote AT request with the IR command
  RemoteAtCommandRequest remoteAtRequest = RemoteAtCommandRequest(remoteAddress, d0Cmd, d0Value, sizeof(d0Value));
    // Create a Remote AT response object
  RemoteAtCommandResponse remoteAtResponse = RemoteAtCommandResponse();

  sendRemoteAtCommand();
  nss.println("First Command");
 
 delay(100);
}

void sendRemoteAtCommand() {
  nss.println("Sending command to the XBee");
    // SH + SL of your remote radio
  XBeeAddress64 remoteAddress = XBeeAddress64(xbee_SH, xbee_SL);
    // Create a remote AT request with the IR command
  RemoteAtCommandRequest remoteAtRequest = RemoteAtCommandRequest(remoteAddress, d0Cmd, d0Value, sizeof(d0Value));
    // Create a Remote AT response object
  RemoteAtCommandResponse remoteAtResponse = RemoteAtCommandResponse();

  // send the command
  xbee.send(remoteAtRequest);

  // wait up to 5 seconds for the status response
  if (xbee.readPacket(5000)) {
    // got a response!

    // should be an AT command response
    if (xbee.getResponse().getApiId() == REMOTE_AT_COMMAND_RESPONSE) {
      xbee.getResponse().getRemoteAtCommandResponse(remoteAtResponse);

      if (remoteAtResponse.isOk()) {
        nss.print("Command [");
        nss.print(remoteAtResponse.getCommand()[0]);
        nss.print(remoteAtResponse.getCommand()[1]);
        nss.println("] was successful!");

        if (remoteAtResponse.getValueLength() > 0) {
          nss.print("Command value length is ");
          nss.println(remoteAtResponse.getValueLength(), DEC);

          nss.print("Command value: ");
         
          for (int i = 0; i < remoteAtResponse.getValueLength(); i++) {
            nss.print(remoteAtResponse.getValue()[i], HEX);
            nss.print(" ");
          }

          nss.println("");
        }
      } else {
        nss.print("Command returned error code: ");
        nss.println(remoteAtResponse.getStatus(), HEX);
      }
    } else {
      nss.print("Expected Remote AT response 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());
  } else {
    nss.print("No response from radio");
    return ;
  }
}


void getlauncher()
 {
  //nss.println("I'm Here");
  switch(StationID)
  {
    case 1:                              //Station #1 
           
      buttonstate_A = digitalRead(launch_A);  //A launcher button pushed
      buttonstate_B = digitalRead(launch_B);  //B launcher button pushed
     
      if (buttonstate_A == LOW)
      {
        nss.println("launch_A pressed");
        ncount = count + 1;
        d0Value[0] =  0x5 ;
        xbee_SH = 0x0013a200;
        xbee_SL = 0x40923f25;
        sendPacket();
        delay(10);
        payload[1] = 0x01;
        payload[2] = 0x01;

      }
      if (buttonstate_B == LOW)
      {
        nss.println("launch_B pressed");
        ncount = count + 1;
        d0Value[0] =  0x5 ;
        xbee_SH = 0x0013a200;
        xbee_SL = 0x40923f3d;
        sendPacket();
        delay(10);
        payload[1] = 0x01;
        payload[2] = 0x02;

      }
      break;

    case 2:                              //Station #2
   
       buttonstate_A = digitalRead(launch_A);  //A launcher button pushed
       buttonstate_B = digitalRead(launch_B);  //B launcher button pushed
     
      if (buttonstate_A == LOW)
      {
        nss.println("launch_A pressed");
        ncount = count + 1;
        d0Value[0] =  0x5 ;
        xbee_SH = 0x0013a200;
        xbee_SL = 0x40923f25;
        sendPacket();
        delay(10);
        payload[1] = 0x02;
        payload[2] = 0x01;

      }
      if (buttonstate_B == LOW)
      {
        nss.println("launch_B pressed");
        ncount = count + 1;
        d0Value[0] =  0x5 ;
        xbee_SH = 0x0013a200;
        xbee_SL = 0x40923f3d;
        sendPacket();
        delay(10);
        payload[1] = 0x02;
        payload[2] = 0x02;

      }
      break;
  }   
 }

void readcounts()
{
  mySerial.write(254);  //cursor to beginning of first line
  mySerial.write(128);
  mySerial.write("StationID=     ");
  mySerial.write(254);  //cursor to position 12 of first line
  mySerial.write(139);
  mySerial.print(nStationID);
  mySerial.write(254);  //cursor to beginning of second line
  mySerial.write(192);
  mySerial.write("#launches=     ");
  mySerial.write(254);  //cursor to position 12 of second line
  mySerial.write(203);
  mySerial.print(ncount);
}

void loop()
{
if (nStationID != StationID)
  {
    readcounts();
    StationID = nStationID;
  } 
if (StationID == 0)
  {
  }
if (gotolauncher = '#')
  {
    getlauncher();
  }
if (StationID != 0 && StationID != 18 && StationID != 21)
  {
  } 
if (StationID == 21)
  {
  }
if(StationID == 18)
  {
  }
if (ncount != count)
  {
   readcounts();
   count = ncount;
  }

Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
// Connect Arduino pin 8 to TX of usb-serial device
uint8_t ssRX;
// Connect Arduino pin 9 to RX of usb-serial device
uint8_t ssTX = 9;
You don't think the compiler is going to read your comment, do you?

Why isn't ssRX assigned a value?

Complete error messages are a good thing,
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am not using pin 8 for serial; I am only using Pin 9 for debugging.

This code works fine on PRO MICRO and FIO. It will not compile when MICRO is selected.

The error code I get when connected to MICRO is:

Quote
RemoteAtCommand_DIGIMESH_MICRO_xbee.ino: In function 'void setup()':
RemoteAtCommand_DIGIMESH_MICRO_xbee:79: error: no matching function for call to 'XBee::setSerial(Serial_&)'
C:\Documents and Settings\BILL\My Documents\ARDUINO_1_16_2013\arduino-1.0.3\libraries\XBee/XBee.h:779: note: candidates are: void XBee::setSerial(HardwareSerial&)

   
Bill

Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I am not using pin 8 for serial; I am only using Pin 9 for debugging.
I don't understand this. You should still assign a non-zero value to the ssRX pin.

Where did you get the XBee library you are using?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The Xbee library is xbee-arduino-0.4-softwareserial-beta.zip downloaded from here;

http://code.google.com/p/xbee-arduino/

The program runs fine with nothing assigned to the ssRX pin.

Bill
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

When I compile your code, for the Micro, using 1.0.3, I get a number of errors about AltSoftSerial not being configured for the Micro, but I get no errors about the XBee library. What version of the IDE are you using? How did you configure AltSoftSerial to recognize the Micro?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I let you to the wrong xbee.h file ; the one I am using I got from:

http://code.google.com/p/xbee-arduino/issues/detail?id=20

I am using the one from the March 9, 2012 post. This included the support for DIGIMESH.

Sorry.

I am using Arduino 1.0.3

Bill
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Paul:

Hold off spending any more time at the moment; I have screwed up my files and I have to straighten them out before I ask for more assistance.

I will repost when I can figure out what changes I made to xbee.h

Bill

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Paul

OK, back on track.

Attached are the xbee.h, xbee.cpp and error message., xbee.h and xbee.cpp were downloaded from

http://code.google.com/p/xbee-arduino/issues/detail?id=20 March 9 post.

The sketch runs OK with FIO or PRO MINI but gives the error message when using a MICRO.

Bill

* XBee.h (30.52 KB - downloaded 20 times.)
* XBee.cpp (37.76 KB - downloaded 21 times.)
* MICRO_XBEE.docx (9.93 KB - downloaded 25 times.)
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

In those files, the _serial member is a HardwareSerial pointer. In the XBee library at http://code.google.com/p/xbee-arduino/, the _serial member is a Stream.

Both HardwareSerial and Serial_ derive from Stream, but are not interchangeable. The XBee library does not rely on the parts of HardwareSerial or Serial_ that distinguish them from Stream. So, just use the library from the google link.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I cannot use this solution since I am using a Xbee DIGIMESH and it will not work with the beta XBee library downloaded from here
http://code.google.com/p/xbee-arduino/
This library works with Xbee series 1 and 2 but not all API packets for DIGIMESH

The Xbee library downloaded from here
http://code.google.com/p/xbee-arduino/issues/detail?id=20
works with DIGIMESH but not with ARDUINO MICRO.

I fixed my sketch by combining the two zbee libraries into a third which I call XBeeDM32u4 and this is now working with the MICRO and a Zbee DIGIMESH 2.4Mhz.

Attached is the new library; I do not know iof this will work for everyone but it fixed my sketch.

Bill

* readme32u4.txt (0.98 KB - downloaded 27 times.)
* XBeeDM32u4.cpp (39.67 KB - downloaded 49 times.)
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is the XBeeDM32u4.h file

Bill

* XBeeDM32u4.h (31.67 KB - downloaded 45 times.)
Logged

Pages: [1]   Go Up
Jump to: