arduino randomly resets


hello

i in progress of creating own present box , since person present see topic hope can me without me telling name problem in code arduino resets after 1 or more loops of main loop :s
i dont know why tried implementing more delays didnt maybe overloading memory buffer clears dont know
i think code pretty commented , pretty simple
the servo code disabled , not cause problem (i think)
any welcome , sorry if in wrong category

i thinking maybe power problem
i have connected pc more sufficient power
i have gps module using 40ma , lcd 4x16 display , uv led between 13 , ground there no servo connected.
i dont think but.. maybe if guys dont have problems it


code: [select]


#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 serial port
 serial.begin(115200);

 // print info , ego boost
 serial.println(gps.getlibversion());
 
 // setup gps module
 serial.print("setting gps...");
 
 // gps warm-up time
 delay(1000);
 
 
 
 // command initializing gps, default preconfigured
 // weather station @ central malmo, sweden, april 8th, 2009, 6:56am
 gps.init();    

 // configure own time , 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; <= 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 raw data string arriving gps
 serial.println(gps.getraw(100));

 // @ point, gps.inbuffer contains data sent the
 // gps, , can parse gpsstringexplode( string, separator)  
 gps.gpsstringexplode(gps.inbuffer,',');
 
 // configure nmea sentences show gga sentence
 // anyway action default
 delay(80);  
if (gps.arguments[0][3] == 'g'){
   
 // action separate arguments coming in string
 // looking ',' separator. can print them separately see
 // how like. since don't wanna overload memory, there
 // limit on 15 arguments of 11 characters each (modified me 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, 1 thing, writing past end of arguments array.  your loop in argclear() should use '<' instead of '<='.  there more elegant way it, using nested loops:
code: [select]
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


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > arduino randomly resets


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums