I assume it has something to do with the Leonardo not using serial by default and you have to use Serial1 or something, but I don't know what code to change to fix this. Can anyone help?
That worked, thanks. In the \libraries\ folder I created a new directory called \XBee_Leo and copied XBee.h and XBee.cpp in there and renamed them to XBeeLeo.h and XBeeLeo.cpp. In the XBeeLeo.cpp I made the serial1 change and changed #include XBee.h to #include XBeeLeo.h. In my sketch I just changed the include from <XBee.h> to <XbeeLeo.h> and all is good.
It would be nice if one library could compile both Leonardo boards and non-Leonardo boards. I tried some stuff with #ifdef, but it didn't work. Here's what I tried:
First I changed added a #define to my sketch:
This does not work because the defines and includes are rearranged before fed to the compiler.
But you can change your library this way and you don't have to do anything special. If you choose the Leonardo as the board type automatically the correct code is generated.
I made the change and made sure I closed then re-opened the Arduino IDE, but my sketch didn't compile when I selected the Leonardo board. I got this error:
/Volumes/srg/Arduino Sketches/libraries/XBee/XBee.cpp: In constructor 'XBee::XBee()':
/Volumes/srg/Arduino Sketches/libraries/XBee/XBee.cpp:774: error: cannot convert 'Serial_' to 'HardwareSerial' in assignment