Software serial stop working after running for several days

I'm using software serial for the communication between arduino pro mini and a GPS module. It worked fine at first, but sometimes after the system being running for several days, the arduino suddenly cannot get any data from GPS module. I checked the pins of arduino that are used for softwareserial by connecting them to PC, and it shows that the serial communication is on. So it seems like something went wrong with the software serial libraries. Does anyone met the same problems before?

BTW, we have like 7 same devices running in the same time, and only 1 of them suffers from this problem.

Can you swap GPS units & confirm the GPS is still good? Maybe bad GPS, maybe wiring issue?

The GPS module was working fine, as the wiring. I'm using pin2 and pin3 as software serial, and I connected the PC directly to the pins of pro mini and can get the correct data. The system was working fine at first but failed after several days, and when I reset the arduino pro mini, it works fine again... Also when software serial was not working, the other parts of the sketch is good, I know this because the sketch is continuing print correct log through one debug serial.

If it fails after a few days, that's a sign that either the software is getting hosed, or it's hosing itself by corrupting SRAM by exceeding the bounds of an array for example.
You can add watchdog functionality to the sketch - if the sketch gets hosed and stops resetting the watchdog during normal operations, then the watch interrupt kicks in and resets the uC.

Thanks for your advise. Yeah actually I do have a watchdog up and running, as I said, everything else seems working fine (as observed from a debug serial which is printing all kinds of log to PC) except that each time I tried to get data from software serial returns empty... It's pretty wired. My current solution (or workaround) is NOT feed the watchdog unless the correct data is received from GPS. I'm pretty sure it can work. Just wondering if anyone has the same experience and maybe knows the root cause, like maybe the software serial get out of sync of the baud rate...

Does the GPS module have a reset pin? If you stop getting serial data then try resetting the GPS module from within the code and see if it all starts working again. If it does start working then the Arduino serial is fine and the GPS firmware may be at fault. If it does not sort out the serial problem then maybe the Arduino serial is at fault.

No the there's no reset pin in the GPS module. But I think the GPS module is working fine because I tried to use PC to monitor the serial at the INPUT of arduino pro mini and PC can get correct GPS data. I think that means the GPS module and the wiring are all good right? And also after reset pro mini, everything is back to normal. So I'm pretty sure the issue is on arduino.

jjjarod:
And also after reset pro mini, everything is back to normal. So I'm pretty sure the issue is on arduino.

Show us your code then as it seems you may have a memory leak that corrupts after a time or your using Strings and fragmenting memory to much.

The

jjjarod:
No the there's no reset pin in the GPS module. But I think the GPS module is working fine because I tried to use PC to monitor the serial at the INPUT of arduino pro mini and PC can get correct GPS data. I think that means the GPS module and the wiring are all good right? And also after reset pro mini, everything is back to normal. So I'm pretty sure the issue is on arduino.

JJJarod,

It could be that the pinMode's on the Software Serial ports are being corrupted. If you already have a watch dog function, when it detects a loss of comm with the GPS just destroy the Software Serial object and initialize a new instance.

// Software Serial Recovery
// Chuck Todd <ctodd@cableone.net>

#include <SoftwareSerial.h>

SoftwareSerial mySerial = SoftwareSerial(10,11);

void initSerial(){
  mySerial.begin(9600);
  // code to configure GPS
}

void setup(){
  initSerial();
  
}

void recover_GPS(){
  mySerial.~SoftwareSerial(); // destroy current instance
  mySerial = SoftwareSerial(10,11); // recreate new instance, reconfigure all hardware.
  initSerial();
}

void loop(){
  // if no comms with GPS Call recover_GPS();
}

Chuck.


Check out my Kickstarter Project Memory Panes an expansion RAM Shield for Mega2560's. It adds 1MB of RAM for those projects where 8KB is not enough.

Sounds like a valid option, thanks for the advise!

chucktodd:
The
JJJarod,

It could be that the pinMode's on the Software Serial ports are being corrupted. If you already have a watch dog function, when it detects a loss of comm with the GPS just destroy the Software Serial object and initialize a new instance.

// Software Serial Recovery

// Chuck Todd ctodd@cableone.net

#include <SoftwareSerial.h>

SoftwareSerial mySerial = SoftwareSerial(10,11);

void initSerial(){
  mySerial.begin(9600);
  // code to configure GPS
}

void setup(){
  initSerial();
 
}

void recover_GPS(){
  mySerial.~SoftwareSerial(); // destroy current instance
  mySerial = SoftwareSerial(10,11); // recreate new instance, reconfigure all hardware.
  initSerial();
}

void loop(){
  // if no comms with GPS Call recover_GPS();
}






---


Chuck.


---


Check out my Kickstarter Project [Memory Panes](https://www.kickstarter.com/projects/1052400055/mega2560-expansion-ram-arduino-compatible-xmem) an expansion RAM Shield for Mega2560's. It adds 1MB of RAM for those projects where 8KB is not enough.