Pages: [1]   Go Down
Author Topic: [solved] XBee library crashes?  (Read 165 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello everyone,

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

Code:
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...
« Last Edit: November 26, 2013, 01:26:10 pm by memel182 » Logged

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 92
Posts: 3942
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

That code does not compile.
Please post the code you are actually running.
Copy-and-paste is a good approach.
Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

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

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

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

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!
Logged

Pages: [1]   Go Up
Jump to: