Go Down

Topic: [solved] XBee library crashes? (Read 220 times) previous topic - next topic

memel182

Nov 26, 2013, 09:05 am Last Edit: Nov 26, 2013, 07:26 pm by memel182 Reason: 1
Hello everyone,

Here is the simple code I am trying to test, but seems to make my ATmega2560 stop executing :

Code: [Select]

include "XBee.h";

XBee xbee;

setup() {
xbee = XBee();
xbee.setSerial(Serial1);
xbee.begin(9600);
pinMode(31, OUTPUT);
}

loop {
xbee.readPacket();
digitalWrite(31,HIGH);
delay(500);
digitalWrite(31,LOW);
}


The main XBee (coordinator) is working great (tested with X-CTU) and directly wired to VCC/Ground of the board, with TX to the RX1 of the board (for Serial1), and communication with another XBee (router) is ok (associated and receiving).

So with this code, a LED wired to pin 31 of the mega is correctly blinking until I power up the router... As soon as the coordinator starts receiving datas, the code stops executing, the LED is not blinking anymore...

Any idea why this is happening?

Thanks...

Jack Christensen

That code does not compile.
Please post the code you are actually running.
Copy-and-paste is a good approach.
MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

PaulS

Code: [Select]
xbee = XBee();
You NEVER invoke the constructor directly. Get rid of this. You have already indirectly (correctly) invoked the constructor, here:
Code: [Select]
XBee xbee;

memel182

Awesome PaulS!

This seemed to cause the problem! I cleaned up my code starting from your suggestion and it worked!
I think I have to dive deeper in C++ syntax and leave some of my Java habits...

Anyway, great thanks!

Go Up