XBee hangs... why?

Hi! Here is my problem…

I have connected one XBee to an Arduino Uno R3. Coordinator connected to PC, executing a python process that reads the messeages sent from the Arduino, related to sensort (temperature, humidity…)

In the Arduino side, I’m trying to adjust the time between readings, using Time library (the first command i send from the arduino is requesting the time to the Coordinator). I also use TimeAlarms library.

My problem: when I increase the time between readings (sending values to Coordinator), when arduino restarts after uploading code (the only mofification is the ’ Alarm.timerRepeat(XX,repeats);’) the Arduino crash, the led in the XBee shield starts blinking (5 times a second) and no request detected in the controller… With 3 seconds, it works…

I tried modifying SoftwareSerial PINS, Using typicall millis() instead of Time library, but same results… More than 3 seconds… CRASH!!

Any help? :slight_smile:

Thank youuuuu!

#include <SoftwareSerial.h>
#include <XBee.h>

#include <Time.h>
#include <TimeAlarms.h>

#define PIN_PWR 4
#define DHT22_PIN 5

# define PIN_RX 10
# define PIN_TX 9

#include <DHT22.h>
DHT22 myDHT22(DHT22_PIN);

char verNum[] = "Version 0";
XBee xbee = XBee();
SoftwareSerial XbeeSerial(PIN_RX, PIN_TX);
char Dbuf[100]; 
char Dbuf_in[100]; 

// SH + SL Address of receiving XBee
//XBeeAddress64 addr64 = XBeeAddress64(0x00000000, 0x00000000);
//XBeeAddress64 addr64 = XBeeAddress64(0x00000000, 0x0000ffff);

XBeeAddress64 addr64 = XBeeAddress64(0x0013A200, 0x40ABC308);
ZBTxStatusResponse txStatus = ZBTxStatusResponse();
ZBRxResponse rx = ZBRxResponse();

int pin5 = 0; //Next Moisture Sensor

unsigned long previousMillis = 0; 
unsigned long currentMillis = 0;
//long interval = 10000; 

void setup() {


//  previousMillis =millis();
  Alarm.timerRepeat(3,repeats); //THIS IS THE ONLY CHANGE I DO

void loop() { 
  currentMillis = millis();
  if(currentMillis - previousMillis > interval) {
    previousMillis = currentMillis;

void actualiza_hora(){
  if (xbee.getResponse().isAvailable()) {
      if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE){
        char txt_time[]="TIME:";
        if (strstr((char*)rx.getData(),txt_time)==NULL){
        String timeString((char*)rx.getData());   
        int firstColon = timeString.indexOf(":");
        setTime ((time_t)timeString.toInt());

void enviaDatos(const char* Dbuf){
  if (xbee.readPacket(500)) {
    // got a response!
    // should be a znet tx status      
    if (xbee.getResponse().getApiId() == ZB_TX_STATUS_RESPONSE) {
      // get the delivery status, the fifth byte
      if (txStatus.getDeliveryStatus() == SUCCESS) {
      } else {
        // the remote XBee did not receive our packet. is it powered on?
  } else if (xbee.getResponse().isError()) {
    //nss.print("Error reading packet.  Error code: ");  
  } else {
    // local XBee did not provide a timely TX Status Response -- should not happen
    Serial.println("Sin ACK");

void sendXbee(const char* command){
  ZBTxRequest zbtx = ZBTxRequest(addr64, (uint8_t *)command, strlen(command));
void repeats(){
  pin5 = analogRead(5);
  DHT22_ERROR_t errorCode;
  errorCode = myDHT22.readData();
  if (errorCode == DHT_ERROR_NONE){
    float temperature=myDHT22.getTemperatureC();
    float humidity= myDHT22.getHumidity();
      myDHT22.getTemperatureCInt()/10, abs(myDHT22.getTemperatureCInt()%10),
      myDHT22.getHumidityInt()/10, myDHT22.getHumidityInt()%10,pin5);