arduino randomly resets

hello

i am in progress of creating my own present box and since the person for who the present is probably will also see this topic i hope you can help me without me telling you the name so my problem is that in my code my arduino resets after one or more loops of the main loop :S
i dont know why i tried implementing more delays but it didnt help maybe i am overloading the memory with my buffer clears but i dont know
i think the code is pretty well commented and pretty simple too
the servo code is disabled and does not cause the problem (i think)
any help is welcome and sorry if i am in the wrong category

i was thinking maybe it is a power problem
i have it connected to a pc with more than sufficient power
i have a gps module using 40ma and an lcd 4x16 display and the is a uv led between 13 and ground there is no servo connected.
i dont think this could be it but… maybe if you guys dont have any problems with it

#include "LB_GPS.h"
#include <LiquidCrystal.h>
#include <Servo.h>


LiquidCrystal lcd(5, 6, 7, 10, 11, 12);
Servo myservo;

int buffclear();
int agrclear();
int servo(int x);
int lcdprint(char* x, int y);
char arguments[15][11];
int ledpin = 13;
char* nosats;
char inBuffer[100];

// setup
void setup(){
  lcd.begin(16, 4);
  myservo.attach(4);
  GPS.setSentences(GPGGA); 
  //setup for Serial port
  Serial.begin(115200);

  // print some info and ego boost
  Serial.println(GPS.getLibVersion());
  
  // setup the GPS module
  Serial.print("Setting up GPS...");
  
  // GPS warm-up time
  delay(1000);
  
  
  
  // command initializing the GPS, by default it is preconfigured to be the 
  // weather station at central Malmo, Sweden, April 8th, 2009, 6:56AM
  GPS.init();    

  // configure your own time and date
  //GPS.setDate("18,04,2009");
  //GPS.setTime("19,55,00");
  
  // done!
  Serial.println(" done!");
}

// functions
// servo en led
int servo(int x)
  {
    if (x == 1){
  digitalWrite(ledpin,HIGH);
  myservo.write(150);
  digitalWrite(ledpin,LOW);
  delay(230);
  digitalWrite(ledpin,HIGH);
  myservo.write(30);
  delay(230);
  digitalWrite(ledpin,LOW);
    }
  }

// buffer clear
int buffclear(){
  Serial.println("buffer cleared!");
  int i;
for(i= 0; i <= 100; i++)
{
     inBuffer[i] = NULL;
     //Serial.print("X "); Serial.print(i);
     delay(2);
}
}

// argument clear
int argclear(){
int j;
int h;
for(j=0;j<=11;j++)
{ //[15][11] GPS.arguments writing NULL
  GPS.arguments[h][j] = NULL;//0
  h++;
  GPS.arguments[h][j] = NULL;//1
  h++;
  GPS.arguments[h][j] = NULL;//2
  h++;
  GPS.arguments[h][j] = NULL;//3
  h++;
  GPS.arguments[h][j] = NULL;//4
  h++;
  GPS.arguments[h][j] = NULL;//5
  h++;
  GPS.arguments[h][j] = NULL;//6
  h++;
  GPS.arguments[h][j] = NULL;//7
  h++;
  GPS.arguments[h][j] = NULL;//8
  h++;
  GPS.arguments[h][j] = NULL;//9
  h++;
  GPS.arguments[h][j] = NULL;//10
  h++;
  GPS.arguments[h][j] = NULL;//11
  h++;
  GPS.arguments[h][j] = NULL;//12
  h++;
  GPS.arguments[h][j] = NULL;//13
  h++;
  GPS.arguments[h][j] = NULL;//14
  h++;
  GPS.arguments[h][j] = NULL;//15
  h=0;
}
Serial.println("arguments cleared!");
}

void loop(){
  // print the raw data string arriving from the GPS 
  Serial.println(GPS.getRaw(100));

  // at this point, GPS.inBuffer contains the data sent by the
  // GPS, and you can parse it yourself with GPSStringExplode( string, separator)  
  GPS.GPSStringExplode(GPS.inBuffer,',');
  
  // configure NMEA sentences to show only GGA sentence
  // this is anyway the action by default
  delay(80);  
if (GPS.arguments[0][3] == 'G'){ 
    
  // this action will separate all the arguments coming in the string
  // looking for ',' as separator. You can print them separately to see
  // how they look like. Since we don't wanna overload the memory, there
  // is a limit on 15 arguments of 11 characters each (modified by me to 20,11)
  Serial.print("type:"); Serial.println((char*)GPS.arguments[0]);
  Serial.print("time:"); Serial.println((char*)GPS.arguments[1]);
  Serial.print("deg : "); Serial.print((char*)GPS.arguments[2]); Serial.print(" "); Serial.println((char*)GPS.arguments[3]);
  //Serial.print("N/S: "); Serial.println((char*)GPS.arguments[3]);
  Serial.print("deg: "); Serial.print((char*)GPS.arguments[4]); Serial.print(" "); Serial.println((char*)GPS.arguments[5]);
  //Serial.print("E/W: "); Serial.println((char*)GPS.arguments[5]);
  Serial.print("fix type: "); Serial.println((char*)GPS.arguments[6]);
  Serial.print("# sats: "); Serial.println((char*)GPS.arguments[7]);
  Serial.print("horiz dilution: "); Serial.println((char*)GPS.arguments[8]);
  Serial.print("alt: "); Serial.print((char*)GPS.arguments[9]); Serial.print(" "); Serial.println((char*)GPS.arguments[10]);
 // Serial.print("M:  "); Serial.println((char*)GPS.arguments[10]);
  Serial.print("ellipsoid: "); Serial.print((char*)GPS.arguments[11]); Serial.print(" "); Serial.println((char*)GPS.arguments[12]);
  //Serial.print("type ellipsoid: "); Serial.println((char*)GPS.arguments[12]);
  Serial.print("secs last dgps update: "); Serial.println((char*)GPS.arguments[13]);
  Serial.print("dgps id #: "); Serial.println((char*)GPS.arguments[14]);
  Serial.print("checksum: "); Serial.println((char*)GPS.arguments[15]);
  
   nosats = ((char*)GPS.arguments[7]);
   lcd.clear();
   lcd.print(nosats);
   lcd.print(" sats");
   lcd.setCursor(9,0);
   lcd.print(((char*)GPS.arguments[6]));
   lcd.print(" type");
   lcd.setCursor(0,1);
   lcd.print((char*)GPS.arguments[9]); lcd.print(" "); lcd.print((char*)GPS.arguments[10]);
   lcd.setCursor(0,2);
   lcd.print("dgps id #: "); lcd.pr

Well, for one thing, you are writing past the end of your arguments array. Your for loop in argclear() should use ‘<’ instead of ‘<=’. There is also a more elegant way to do it, using nested for loops:

int argclear()
{
    int j;
    int h;

    for (j = 0; j < 11; j++)
      for (h = 0; h < 15; h++)
        GPS.arguments[h][j] = NULL;
}

Regards,

-Mike

thank you for the verry fast reply i knew there was a way to do it easier i just couldn't think it through but i implemented the code though i am still getting resets.. its half past 12 AM now so ill read your reaction later thank you verry much

ps. it has occurred to me that the resets are always occuring when it has displayed : checksum: after that it is just clearing the memory so maybe it is an overload of some kind :-/

ps2. if someone know a great formula to get my gpgga latlong output in degrees and decimal seconds to latitude and longitude .? thank you

diamantamtch,

When you posted your program the first time, it looks like it got cut off. If you can, repost the whole program, and maybe someone will be able to figure out the problem.

-Mike

i am sorry i see now it was indeed cut off :-/
this is the entire code:

#include "LB_GPS.h"
#include <LiquidCrystal.h>
#include <Servo.h>


LiquidCrystal lcd(5, 6, 7, 10, 11, 12);
Servo myservo;

int buffclear();
int agrclear();
int servo(int x);
int lcdprint(char* x, int y);
char arguments[15][11];
int ledpin = 13;
char* nosats;
char inBuffer[100];


// setup
void setup(){
  lcd.begin(16, 4);
  myservo.attach(4);
  GPS.setSentences(GPGGA); 
  //setup for Serial port
  Serial.begin(115200);

  // print some info and ego boost
  Serial.println(GPS.getLibVersion());
  
  // setup the GPS module
  Serial.print("Setting up GPS...");
  
  // GPS warm-up time
  delay(1000);
  
  
  
  // command initializing the GPS, by default it is preconfigured to be the 
  // weather station at central Malmo, Sweden, April 8th, 2009, 6:56AM
  GPS.init();    

  // configure your own time and date
  //GPS.setDate("18,04,2009");
  //GPS.setTime("19,55,00");
  
  // done!
  Serial.println(" done!");
}

// functions
// servo en led
int servo(int x)
  {
    if (x == 1){
  digitalWrite(ledpin,HIGH);
  myservo.write(150);
  digitalWrite(ledpin,LOW);
  delay(230);
  digitalWrite(ledpin,HIGH);
  myservo.write(30);
  delay(230);
  digitalWrite(ledpin,LOW);
    }
  }

// buffer clear
int buffclear(){
  Serial.println("buffer cleared!");
  int i;
for(i= 0; i <= 100; i++)
{
     inBuffer[i] = NULL;
     //Serial.print("X "); Serial.print(i);
     delay(2);
}
}

// argument clear
int argclear()
{
    int j;
    int h;

    for (j = 0; j < 11; j++)
      for (h = 0; h < 15; h++)
        GPS.arguments[h][j] = NULL;
        Serial.println("arguments cleared!");
} 

  




void loop(){
  // print the raw data string arriving from the GPS 
  Serial.println(GPS.getRaw(100));

  // at this point, GPS.inBuffer contains the data sent by the
  // GPS, and you can parse it yourself with GPSStringExplode( string, separator)  
  GPS.GPSStringExplode(GPS.inBuffer,',');
  
  // configure NMEA sentences to show only GGA sentence
  // this is anyway the action by default
  delay(80);  
if (GPS.arguments[0][3] == 'G'){ 
    
  // this action will separate all the arguments coming in the string
  // looking for ',' as separator. You can print them separately to see
  // how they look like. Since we don't wanna overload the memory, there
  // is a limit on 15 arguments of 11 characters each (modified by me to 20,11)
  Serial.print("type:"); Serial.println((char*)GPS.arguments[0]);
  Serial.print("time:"); Serial.println((char*)GPS.arguments[1]);
  Serial.print("deg : "); Serial.print((char*)GPS.arguments[2]); Serial.print(" "); Serial.println((char*)GPS.arguments[3]);
  //Serial.print("N/S: "); Serial.println((char*)GPS.arguments[3]);
  Serial.print("deg: "); Serial.print((char*)GPS.arguments[4]); Serial.print(" "); Serial.println((char*)GPS.arguments[5]);
  //Serial.print("E/W: "); Serial.println((char*)GPS.arguments[5]);
  Serial.print("fix type: "); Serial.println((char*)GPS.arguments[6]);
  Serial.print("# sats: "); Serial.println((char*)GPS.arguments[7]);
  Serial.print("horiz dilution: "); Serial.println((char*)GPS.arguments[8]);
  Serial.print("alt: "); Serial.print((char*)GPS.arguments[9]); Serial.print(" "); Serial.println((char*)GPS.arguments[10]);
 // Serial.print("M:  "); Serial.println((char*)GPS.arguments[10]);
  Serial.print("ellipsoid: "); Serial.print((char*)GPS.arguments[11]); Serial.print(" "); Serial.println((char*)GPS.arguments[12]);
  //Serial.print("type ellipsoid: "); Serial.println((char*)GPS.arguments[12]);
  Serial.print("secs last dgps update: "); Serial.println((char*)GPS.arguments[13]);
  Serial.print("dgps id #: "); Serial.println((char*)GPS.arguments[14]);
  Serial.print("checksum: "); Serial.println((char*)GPS.arguments[15]);
  
   nosats = ((char*)GPS.arguments[7]);
   lcd.clear();
   lcd.print(nosats);
   lcd.print(" sats");
   lcd.setCursor(9,0);
   lcd.print(((char*)GPS.arguments[6]));
   lcd.print(" type");
   lcd.setCursor(0,1);
   lcd.print((char*)GPS.arguments[9]); lcd.print(" "); lcd.print((char*)GPS.arguments[10]);
   lcd.setCursor(0,2);
   lcd.print("dgps id #: "); lcd.print((char*)GPS.arguments[14]);
   digitalWrite(ledpin,HIGH);
   delay(450);
   digitalWrite(ledpin,LOW);
}
else {
 Serial.println("not a GPGGA sentence");
 delay(500);
}
  buffclear();
  delay(50);
  argclear(); 
  delay(2000);
  
  //servo(0);


}

Well, your buffclear() function has the same problem that I pointed out for argclear(). It writes past the end of the buffer.

Regards,

-Mike

but when i try this:

 int buffclear()
{
    int i;
    for(i = 0; i <= 100; i++){
    inBuffer[i] = NULL; Serial.print(i); Serial.print("-");
    }
    Serial.println("buffer cleared!");
}

it prints 1 untill 100 and not 101 so does it really write past its limits?

i do not understand why == doesnt work? when i try == it does not execute the for loop >:(

The range of indexes for an array of size 100 is 0 through 99. So, when it prints 100, that is beyond the end of the array.

The middle clause on the for loop is a while clause. If you have == in there, you are saying loop with i starting at 1, incrementing by 1 after each pass, while i is 100. Obviously, it will not execute the loop at all.

One final point. String functions look at each position in the character array until one is found that contains a NULL. It is necessary, then, to put a NULL in the first position to end processing of the array of characters. In other words, it is not necessary to put a NULL in every position.

okay i think i start to understand it wierdly enough my arduino doesnt reset anymore XD so indeed it was writing past the array

though i have another question in my code some variables have a * after them what does that mean and why can't i store i.e. an char* in a char ?

i am now cracking my lat and lon and making from the degrees and decimal minutes , degrees using a /60 formula as stated here:http://home.online.no/~sigurdhu/Deg_formats.htm (scroll down a bit it is called (From Degrees decimal-minutes (D m) to decimal-degrees (d)) 8-)) though i can not seem to work it out verry well as i can not store a complete degrees and decimal ' in something like a double :'( it says : invalid cast from type 'char*' to type 'double' ( the array where my lat is in is a char* and my templorary buffer is a doubble

thank you verry much for everything :D all this is for a birthday present for my girlfriend ( like the reverse geocache)

edit:

this is the little bit of code i have written for it but i can not seem to extract the numbers verry well :S as 53 becomes 51 i think i can not write in an int like this and that is the problem but i wouldnt know how i should need to do it :-[ in the arrays are 5317.7607 00635.9736 in array 2 and 4

the code:

int latD;
int lonD;
double latX;
double lonX;
double latXX;
double lonXX;
double lat;
double lon;

 latD = (GPS.arguments[2][0,1]);
 lonD = (GPS.arguments[4][2]);
 latX = (double)GPS.arguments[2][2, 3, 5, 6, 7, 8];
 lonX = (double)GPS.arguments[4][3, 4, 6, 7, 8, 9];
 latXX = (latX / 60);
 lonXX = (lonX / 60);
 lat = (latD + latXX);
 lon = (lonD + lonXX);


 Serial.println("next are the latD-lonD-latX-lonX-latXX-lonXX");
 Serial.println(latD);
 Serial.println(lonD); 
 Serial.println(latX);
 Serial.println(lonX); 
 Serial.println(latXX);
 Serial.println(lonXX);