Code longer doesn't work right in my Arduino One (Uno)

Hi all,

Well, my Arduino is ONE(Uno) model. I'm becoming crazy. The longer is my code the worst works. I'm doing my program little by little and I'm cheking each function I make.

For example, I did a clock function which return the date in display, it worked perfectly but if I increase more functions in my code some function stops working right or not work directly.

My question is, did I exceeded the capacity from my Arduino?

I'm using pointers in severals functions with byte, String, byte-Array and Typedef-Array. I tested them and they worked well. I don't know if it's right to use pointers in Arduino, it isn't exactly as in C++ and it's a little bit strange its writing, perhaps this is my mistake, but I'm not sure.

Anyway, if it's necesary I can upload my code so that you can see

Regards

macamba:
Anyway, if it's necesary I can upload my code so that you can see

No need, I'm sure we can pretty much guess what it's doing.

Have you checked how much RAM it is using?

How can I check the amount RAM I'm using?

You could let someone else take a look at it.

macamba:
Anyway, if it's necesary I can upload my code so that you can see

It is pretty rare someone responds to a post with:

"Well I was going to help you, but since you posted your code I can't."

LMAO @ James, you are so right in that statement. @OP We all make mistakes, look like fools from time to time, but no matter how bad of a botchery we make of our creation people still hang in there to lend assistance.

Hi again,

And thank you for your help.

Ok, I've uploaded the code here => http://www.megaupload.com/?d=A2XDTQ2J

There are a lot of thing.

If you see something strange let me know

Thanks :slight_smile:

Your EEprom is only guaranteed to at or around 10000 writes. Beyond that locations may no longer take values, that does not mean it will give you an error message either, you will go through the motions of writing, but the contents will be garbage, eventually becoming all 0's or 1's depending on the EEProm's cell failure mode. If you wrote to a location on average of 1 per ms in 10 Seconds your EEPROM is shot in those addresses written to. Dynamic data needs to remain in RAM, static data such as bitmasks, constants, character data tables can be placed in EEPROM space to free RAM.

Your EEprom is only guaranteed to at or around 10000 writes.

That should be 100,000 writes.

macamba:
If you see something strange let me know

The Watch tab is using Strings quite a bit. The String implementation before 1.0 was a serious memory issue. For example you do a lot of concatenation "Date[0] += String(IntToString(*second,10));". This actually creates two copies of the original buffer, with the original deallocated. Instead of just adding to the existing buffer. With only 2K of RAM and a small heap, this can cause many problems on at the ATmega328.

Consider not using the String class and instead using known length char arrays.

macamba:
How can I check the amount RAM I'm using?

If you put this code in your sketch and call the function, it will return the amount of RAM free at the point of your call. Obviously RAM use isn't constant and you can't assume that the value you get is the maximum memory use. But you can add calls in the places where you suspect peak RAM use would occur and see how close you are to running out of RAM.

// this function will return the number of bytes currently free in RAM      
extern int  __bss_end; 
extern int  *__brkval; 
int freemem()
{ 
 int free_memory; 
 if((int)__brkval == 0) 
   free_memory = ((int)&free_memory) - ((int)&__bss_end); 
 else 
   free_memory = ((int)&free_memory) - ((int)__brkval); 
 return free_memory; 
}

(Not my code; I was lucky enough to receive it from a helpful forum member when I posted a similar question.)

Flash rewrites is 10k, EEPROM 100k

Thank all of you

Well, I changed the function getDate like James C4S told me, I'm using char instead of String and with the PeterH's freemem() I can tell more free memory. Before my memory went down until 693 and now it's 1052, perfect!!

Regards

New Code:

void getDate(byte *second, byte *minute, byte *hour, byte *dayOfWeek, char *STRdayOfWeek, byte *dayOfMonth, byte *month, byte *year)
 {
 char Date[21];
 Date[0] = '\0';
 char aux[3];
 aux[0] = '\0';
 Wire.beginTransmission(DS1307_I2C_ADDRESS);
 Wire.send(0);
 Wire.endTransmission();
 Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
 *second = bcdToDec(Wire.receive() & 0x7f);
 *minute = bcdToDec(Wire.receive() & 0x7f); 
 *hour = bcdToDec(Wire.receive());
 *dayOfWeek = bcdToDec(Wire.receive() & 0x3f);
 *dayOfMonth = bcdToDec(Wire.receive());
 *month = bcdToDec(Wire.receive());
 *year = bcdToDec(Wire.receive());

 if(*hour < 10)
  strcat(Date, "0");
 itoa(*hour,aux,10);
 strcat(Date,aux);
 strcat(Date, ":");
 
 if(*minute < 10)
  strcat(Date, "0");
 itoa(*minute,aux,10);
 strcat(Date,aux);
 strcat(Date, ":");
 
 if(*second < 10)
  strcat(Date, "0");
 itoa(*second,aux,10);
 strcat(Date,aux);
 strcat(Date, " ");
 
 switch (*dayOfWeek) //dayOfWeek
  {
  case 1:
   strcat(STRdayOfWeek,"Lu");
   strcat(Date, "Lu");
   break;
 case 2:
   strcat(STRdayOfWeek,"Ma");
   strcat(Date, "Ma");
   break;
  case 3:
   strcat(STRdayOfWeek,"Mi");
   strcat(Date, "Mi");
   break;
  case 4:
   strcat(STRdayOfWeek,"Ju");
   strcat(Date, "Ju");
   break;
  case 5:
   strcat(STRdayOfWeek,"Vi");
   strcat(Date, "Vi");
   break;
  case 6:
   strcat(STRdayOfWeek,"Sa");
   strcat(Date, "Sa");
   break;
  case 7:
   strcat(STRdayOfWeek,"Do");
   strcat(Date, "Do");
   break;
  }
 
 strcat(Date, " ");
 if(*dayOfMonth < 10)
  strcat(Date, "0");
 itoa(*dayOfMonth,aux,10);
 strcat(Date,aux);
 strcat(Date, "/");

 if(*month < 10)
  strcat(Date, "0");
 itoa(*month,aux,10);
 strcat(Date,aux);
 strcat(Date, "/");

 if(*year < 10)
  strcat(Date, "0");
 itoa(*year,aux,10);
 strcat(Date,aux);
 
 lcd.print(Date);
 }