Arduino UNO stops working

Hi,

I am using an Arduino UNO where i have an xbee S2B module and an em406a GPS connected on it.

I am receiving the GPS strings and transmitting them to another xbee which is connected on my pc. This is working fine.
But a couple of minutes later the Arduino just stops working.

I have connected the pins properly:
GPS pins: pin1+5 = GND, pin2 = +5V, pin3 = Rx, pin4 = Tx

Arduino pins GPS pins
GND pin1+5
+5V pin2
pin9 pin3
pin8 pin4

Here is my code:

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

// Define SoftwareSerial TX/RX pins
#define xbeeRX 2
#define xbeeTX 3
//create xbee connection
SoftwareSerial xbeess = SoftwareSerial(xbeeRX, xbeeTX);
//create gps connection
AltSoftSerial gpsss;

//Create an XBee object
XBee xbee = XBee();

char gpsstr[256] = "";
char c;

//Define the Destination address of the packets
XBeeAddress64 destaddress = XBeeAddress64(0x0013A200, 0x406F1997);

char Hello[] = "Hello World\n\r";

void setup()  
{
  Serial.begin(9600);  //connect serial
  gpsss.begin(4800);  //connect gps
  xbeess.begin(9600);   //connect xbee
  //We hook the XBee into the Software Serial
  xbee.setSerial(xbeess);
  
  Serial.println("Goodnight moon!");
}

void loop() // run over and over
{

  while (gpsss.available()>0){
    c = gpsss.read();
    if (c == '

I was also wondering if it is normal for the Arduino to execute the setup() from time to time because as far as i know, it is executed only once.

Happy Easter!!

Regards,
gabys){
     break;
   }
   else{
     strncat(gpsstr, &c, 1);
   }
 }
 Serial.println(gpsstr);
 delay(1000);
 ZBTxRequest zbtx = ZBTxRequest(destaddress, (uint8_t *)gpsstr, strlen(gpsstr));
 xbee.send(zbtx);
 delay(2000);
 *gpsstr = c;
 Serial.print(gpsstr);
}


I was also wondering if it is normal for the Arduino to execute the setup() from time to time because as far as i know, it is executed only once.

Happy Easter!!

Regards,
gabys

Sounds like something is causing a reset to occur.

Is the Xbee expecting 3.3V Vcc and 3.3V levels? If so, might be causing overheating.

Easter? Wasn't that a while ago?

Please clarify, why is pin two connected to VIN? The EM406A module only uses 5V. What do you expect when you connect that pin to VIN? What is hooked up to the power barrel?

Is the Xbee expecting 3.3V Vcc and 3.3V levels? If so, might be causing overheating.

I am a rookie on these things so since I am using the xbee shield of sparkfun I assume it uses the correct pin to provide power to the xbee which is the 3.3V.

Easter? Wasn't that a while ago?

In Cyprus is Easter holidays next week.

Please clarify, why is pin two connected to VIN?

It is not connected to VIN. As I have indicated in the table above, it is connected to the +5V pin.

OK, you indicated conflicting information so I asked. Remove the wrong information from your OP then.

What is AltSoftSerial? I don't know anything about it and whether it will clash with SoftwareSerial.

Code below is making a lot of assumptions. Are you sure that any string is less than 256 in length?

strncat(gpsstr, &c, 1);

Where is the code that resets the gpsstr string after it's sent and printed to serial?

OK, you indicated conflicting information so I asked. Remove the wrong information from your OP then.

I corrected the GPS pin 2. pin 2 = +5V

What is AltSoftSerial? I don’t know anything about it and whether it will clash with SoftwareSerial.

It is a new library for software serial. Since I need 2 hardware serials, 1 for the xbee and 1 for the GPS, Arduino Uno only has 1 hardware serial which is already used by the Serial. SoftwareSerial can only support 1 instance of it so I used AltSoftSerial in order to operate with the GPS. You can check it out here: http://www.pjrc.com/teensy/td_libs_AltSoftSerial.html

Code below is making a lot of assumptions. Are you sure that any string is less than 256 in length?

strncat(gpsstr, &c, 1);

All the return strings that are displayed on the Serial Monitor are around 70 bytes long. This is the furthest i could get to display and transmit the strings. I also believe that you are right and a string of longer than 256 in length is returned, but I have no idea how to do it using char*. I have tried several examples that I have found in the internet, but all in vain.

Here’s an example:

#include <cstring>
char *append_char ( const char *s, const char c )
{
std::size_t len = std::strlen ( s );
char *ret = new char[len + 2];
std::strcpy ( ret, s );
ret[len] = c;
ret[len + 1] = '\0';
return ret;

where s=gpsstr and c=c in my code.

The “char *ret = new char[len + 2];” command is giving me an error saying: undefined reference to `operator new(unsigned int)’
so I used the command “char ret = (char)malloc(len + 2);” instead.

Here’s the whole code of that part in the else{} statement in the loop() function:

else{
  len = strlen(gpsstr);
  ret = new char[len + 2];
  strcpy(ret, gpsstr);
  ret[len] = c;
  ret[len + 1] = '\0';
}

Where is the code that resets the gpsstr string after it’s sent and printed to serial?

Since every new valid GPS string that is returned starts with ‘$’, if you check my code, I overwrite the whole value of gpsstr with ‘$’.

I hope I have covered everything so far to have a clearer view of my situation.
I am a rookie on these stuff so if you could please keep everything as simple as possible, it would be most appreciated.
Thank you!

Regards,
gabys

gabys,

Thanks for modifying the OP for the information. I can give you an example of how to handle strings in a future post but the most important thing is the gpsstr.

You start from an empty gpsstr and you keep adding character to it using strncat, one character at a time. There is no code that clears the gpsstr so it keeps growing until it's overflown. Can you post your xbee outputs? I bet it reads like

Green Green Egg Green Egg with Green Egg with Ham ... garbled.

Add gpsstr[0]='\0'; after these two lines will be recommended:

*gpsstr = c; Serial.print(gpsstr);

Can you post your xbee outputs?

Actually I have made quite a lot of modifications to the code so I can not show you the output you are expecting to see, but even before I was displaying the correct GPS string because i put some validations in the code. I understand what you are saying, but as I said, I can not get that output right now.

Here is my whole code:

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

// Define SoftwareSerial TX/RX pins
#define xbeeRX 2
#define xbeeTX 3
//create xbee connection
SoftwareSerial xbeess = SoftwareSerial(xbeeRX, xbeeTX);
//create gps connection
AltSoftSerial gpsss;

//Create an XBee object
XBee xbee = XBee();

char gpsstr[256] = "";
char c;

//Define the Destination address of the packets
XBeeAddress64 destaddress = XBeeAddress64(0x0013A200, 0x406F1997);

void setup()  
{
  Serial.begin(9600);  //connect serial
  gpsss.begin(4800);  //connect gps
  xbeess.begin(9600);   //connect xbee
  //We hook the XBee into the Software Serial
  xbee.setSerial(xbeess);
  
  Serial.println("Goodnight moon!");
}

void loop() // run over and over
{

  while (gpsss.available()>0){
    c = gpsss.read();
    if (c == '

I took under consideration what you have told me, but i have made some modifications myself, as you can see, and now it is working perfectly i can say.

Thank you very much for your help.

Regards,
gabys){
     break;
   }
   else{
     strncat(gpsstr, &c, 1);  //concatenate a character to the string
   }
 }
 Serial.println(gpsstr);
 delay(2000);
 ZBTxRequest zbtx = ZBTxRequest(destaddress, (uint8_t *)gpsstr, strlen(gpsstr));
 xbee.send(zbtx);
 gpsstr[0] = ‘\0’;  //resets the value
 strncat(gpsstr, &c, 1);  //concatenate a character to the string  
}


I took under consideration what you have told me, but i have made some modifications myself, as you can see, and now it is working perfectly i can say.

Thank you very much for your help.

Regards,
gabys

Awesome! Please follow the forum rule and replace the quote with code tags instead:

See the difference:

This is quote. We don't use this tag for code.

This is code. We use this tag for code.