How to free up more memory

Hi!
I am creating an Arduino based smart watch, and I am having problems with memory.
The majority of my code is fine and doesn't take up that much space, however the timing sequence that reads the time from a Sparkfun DS1307 and projects the time on a Freetronics OLED board is taking up a huge chunk of my memory (around 30%). I was wondering if anyone had any tips on how to cut down some space. Any help/advice would be greatly appreciated :slight_smile:

Below is the timing sequence code:

  DateTime now = RTC.now();
  String writeString;
  time.setForegroundColour(WHITE);
  writeString = "";
  writeString += String(now.hour());
  writeString += ":";
  writeString += String(now.minute());
  oled.selectFont(Droid_Sans_36);
  time.print(writeString);
  time.reset();

  writeString = "";
  writeString += String(now.day());
  writeString += "/";
  writeString += String(now.month());
  writeString += "/";
  writeString += String(now.year());
  date.setForegroundColour(WHITE);
  oled.selectFont(SystemFont5x7);
  date.print(writeString);
  date.reset();

You could try not using the String class.

AWOL has given you some good advice. This program (I don't have a RTC) is based on your use of the String class:

#define GOOD      // Comment this line out to get bad version

#ifdef GOOD
char writeString[20];
#else
String writeString;
#endif

#ifdef GOOD
void UseCharArray()
{
  writeString[0] = '\0';
  strcat(writeString, "10");
  strcat(writeString, ":");
  strcat(writeString, "59");

  Serial.println(writeString);

  writeString[0] = '\0';
  strcat(writeString, "Saturday");
  strcat(writeString, "/");
  strcat(writeString, "April");
  strcat(writeString, "/");
  strcat(writeString, "2017");
  Serial.println(writeString);
}
#else
void UseStringClass()
{
  writeString = "";
  writeString += "10";
  writeString += ":";
  writeString += "59";

  Serial.println(writeString);

  writeString = "";
  writeString += "Saturday";
  writeString += "/";
  writeString += "April";
  writeString += "/";
  writeString += "2017";
  Serial.println(writeString);
}
#endif

void setup() {
  Serial.begin(9600);

#ifdef GOOD
  UseCharArray();     // Use C strings
#else
  UseStringClass();   // Use String class
#endif
}

void loop() {
}

It uses 3298 bytes of flash memory and 232 bytes of SRAM. If you uncomment the #define at the top, the code using C strings (i.e., lower case 's' using character arrays) compiles to 1918 bytes of flash and 235 bytes of SRAM.

...And you could maybe Improve on that by better use of flash memory

Thankyou for the quick responses! I'll give it a try

Will using std c string library instead of String class to manipulate strings usually save memory ?

noweare:
Will using std c string library instead of String class to manipulate strings usually save memory ?

Yes.