My sketch STOPS after a few iterations.

Hi All,

I have a sketch where I use several devices:

GPS:
#include <SoftwareSerial.h>
#include <nmea.h>
SoftwareSerial nmeaSourceA(13, 12);
NMEA nmeaDecoder(ALL);

LCD:
#include <serialGLCD.h>
serialGLCD lcd;

COMPASS:
#include <Wire.h>
#include <HMC5883L.h>

On a first version I only had the GPS and the LCD and everything works fine.
With the time I verified that GPS Heading was not update correctly and I thought join it a COMPASS.
In a new sketch I made several experiences with the Compass: Calibrating (matrix and Bias) and made a lot of tests etc, etc. Works fine.

Later I joined the two sketches and it works but the this new sketch I noticed an erratic behavior:
sometimes works several iterations, sometimes works One iteration. After a few times the program stops.

Perhaps I have any Library incompatibility?
Must I Begin and End library’s each time I need them? (Wire.h has a Serial.begin but no Serial.end)
Do I need another Arduino and separate the Compass from the rest?

Please give me your opinion

Regards,

Rabadak

Perhaps I have any Library incompatibility?

More likely that you are running out of memory.

Wire.h has a Serial.begin but no Serial.end

No, it doesn't. It has a begin() method, but ending the hardware doesn't make sense.

Do I need another Arduino and separate the Compass from the rest?

Probably not.

Please give me your opinion

It is my considered opinion that you should have read the "How to post in this forum" threads before you posted, and that you should have posted your code.

Hi PaulS,

Thank you for your reply.

About running out of memory, I don't know (I'm a new for Arduino and it's programming). I can say that, after compile the feedback is that I am using: 19.114 bytes (59%) for sketch and 1.307 bytes (63%) of dynamic memory. I will try to use the Serial.print(F()).

About the idea of Begin/End the hardware was just because i have a lot of serials open and the Arduino may become confused from where must expect data (GPS or Compass). The GPS is connected to 12 and 13 pin and the Compass to 4 and 5.

About to use another Arduino, the idea comes from other guys in a similar project that use a Mega just for GPS NMEAS Sentences readings and other for processing info and read compass. Please see: http://forum.arduino.cc/index.php?topic=91750.0 (you already participate in this topic). See this: https://www.youtube.com/watch?v=-nA6wo9PXls

About posting the code: Yes I know but I have 970 instructions in my code and its very heavy to analise all the code if you don't know all the objectives project. Please see http://forum.arduino.cc/index.php?topic=91750.msg2227178#msg2227178

Waiting for your new post,

Thank you again.

Rabadak

Rabadak: About posting the code: Yes I know but I have 970 instructions in my code and its very heavy to analise all the code if you don't know all the objectives project. Please see http://forum.arduino.cc/index.php?topic=91750.msg2227178#msg2227178

So at least check the actual free RAM while the sketch is executing. Copy this function into your sketch:

int freeRam() {
  extern int __heap_start, *__brkval; 
  int v; 
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval); 
}

Then from your loop(), or better from some deeply nested function with maximum RAM usage (local variables, temporary string buffers etc.) call the function and print available RAM to the serial monitor:

Serial.print(F("Free RAM: "));
Serial.println(freeRam());

Under normal circumstances for me a program works fine if the resulting value is always 250 bytes or more of free RAM.

About posting the code: Yes I know but I have 970 instructions in my code and its very heavy to analise all the code if you don't know all the objectives project

It's even harder to guess what the problem is without seeing the code. The code should have enough comments in it to make reading it easy.

PaulS: It's even harder to guess what the problem is without seeing the code. The code should have enough comments in it to make reading it easy.

PaulS,

Yes my code is very well commented but in Portuguese. Trust me, it's hard.

The issue is: Arduino lost connection in ports 12&13 (GPS). If I don't move the compass, everything goes fine for a long time, once the compass is moved and get a new value, the sketch stops.

Trust me, it's hard.

It's even harder working in the dark.

Do you want me to move this to the Portuguese section?

Hi jurs,

I will try it on UNO. Thanks a lot.

At this moment I'm considering replace the UNO by a Mega or add a Nano just for the compass.

Thanks again, regards,

Rabadak

POST THE CODE

AWOL: It's even harder working in the dark.

Do you want me to move this to the Portuguese section?

Hi AWOL,

Thank you but, no for the moment.

Regards,

Rabadak

Read reply #8

Thank you but, no for the moment.

So, what you are saying is that we've been wasting our time trying to help you, because you are happy with the way that the code works. OK. Fine, I've added you to my list.

AWOL: POST THE CODE

Hi AWOL,

Let me tell why didn't I post the code: I'm preparing for a private contest for boat autopilot automation which will take place next September/2015 (11 teams) and I don't know if the other teams are around here. Although we are all friends, nobody talks true until the big day and all wants to know the others are doing. All teams made an introductory presentation. Even the presentations, nobody knows if are true.

The idea behind this topic was only lessen opinions and check if they are in my mind.

Anyway thank you for your effort.

Regards,

Rabadak

Thanks for wasting our time. This is the Programming section. It's kind-of a given that you post code here.

You chose not to.

Try here