user33167: For a project, I was asked to design a presentation on Arduino. I now have run into the problem of my code suddenly stopping. It worked fine one day, I entered a new item in the array, it stopped working. It looked like I was being returned all newlines insteaed of debug info. Can anyone help?
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

int slide = 0;
const int slideNum = 13;
const String data[] = {
  "What is Arduino?\nArduino is a board\nthat can be used to\neasily program", 
  "that can be used to\neasily program\ncomplex behaviors.", 
  "Purpose\nMoney\nEase of Use",
  "How are they\ncontrolled?\nIDE, C++, Library\n", 
  "Commonly Used\nCommands\ndiditalWrite();\ndidgitalRead();",
  "Commands\ndiditalWrite();\ndidgitalRead();\npinMode();",
  "diditalWrite();\ndidgitalRead();\npinMode();\nanalogWrite();",
  "didgitalRead();\npinMode();\nanalogWrite();\nanalogRead();",
  "Arduino Types\nUno\nMega 2560\nLeonardo",
  "Uno\nMega 2560\nLeonardo\nNano",
  "Mega 2560\nLeonardo\nNano\nMini",
  "Leonardo\nNano\nMini\nEthernet",
  "Nano\nMini\nEthernet\nBluetooth",
  "THE END"};

//Addr: 0x3F, 20 chars & 4 lines
LiquidCrystal_I2C lcd(0x27,20,4); 

void setup()
{
  lcd.init(); 
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Send Newlne to start");
  Serial.begin(9600);
}
void loop()
{
  while (Serial.available() <= 0){
  }
  Serial.println("Current: " + String(slide));
  while (Serial.available() != 0){
    Serial.read();
  }
  next();
  if (slide == slideNum){
    for(;;){
    }
  }
}

void next(){
  String local = data[slide];
  String current[4];
  for (int i = 0; i != 4; i++){
    current[i] = local.substring(0, local.indexOf("\n"));
    local.replace(local.substring(0, local.indexOf("\n")), "");
    current[i].trim();
    local.trim();
    Serial.print("i=" + String(i) + ", current=" + current[i]);
    Serial.println(", local="+local);
  }
  lcd.clear();
  for (int i = 0; i != 4; i++){
    Serial.println(current[i]);
    lcd.setCursor(0,i);
    lcd.print(current[i]);
  }
  //lcd.print(data[slide]);
  slide += 1;
  Serial.println("New: " + String(slide));
}


user11763: Since you haven't provided all of your code, I can't say for sure exactly what caused your problem except that Arduino String operations employ dynamic allocation a lot. This will cause heap fragmentation, which is especially bad on a chip like the ATmega328 with little RAM and subsequently cause weird issues like you're getting. I would guess that initializing the String members of the array takes up a lot of heap space while fragmenting it and when you added one more string, you ended up with a stack-meets-heap situation at some point in loop(). 
You're a lot better off with an array of compact strings using an array of pointers to char i.e. const char * array[] = ... since the strings are literals and so already known at compile time.

33167: <p>For a project, I was asked to design a presentation on Arduino. I now have run into the problem of my code suddenly stopping. It worked fine one day, I entered a new item in the array, it stopped working. It looked like I was being returned all newlines insteaed of debug info. Can anyone help?</p>

<pre><code>#include &lt;Wire.h&gt; 
#include &lt;LiquidCrystal_I2C.h&gt;

int slide = 0;
const int slideNum = 13;
const String data[] = {
  "What is Arduino?\nArduino is a board\nthat can be used to\neasily program", 
  "that can be used to\neasily program\ncomplex behaviors.", 
  "Purpose\nMoney\nEase of Use",
  "How are they\ncontrolled?\nIDE, C++, Library\n", 
  "Commonly Used\nCommands\ndiditalWrite();\ndidgitalRead();",
  "Commands\ndiditalWrite();\ndidgitalRead();\npinMode();",
  "diditalWrite();\ndidgitalRead();\npinMode();\nanalogWrite();",
  "didgitalRead();\npinMode();\nanalogWrite();\nanalogRead();",
  "Arduino Types\nUno\nMega 2560\nLeonardo",
  "Uno\nMega 2560\nLeonardo\nNano",
  "Mega 2560\nLeonardo\nNano\nMini",
  "Leonardo\nNano\nMini\nEthernet",
  "Nano\nMini\nEthernet\nBluetooth",
  "THE END"};

//Addr: 0x3F, 20 chars &amp; 4 lines
LiquidCrystal_I2C lcd(0x27,20,4); 

void setup()
{
  lcd.init(); 
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Send Newlne to start");
  Serial.begin(9600);
}
void loop()
{
  while (Serial.available() &lt;= 0){
  }
  Serial.println("Current: " + String(slide));
  while (Serial.available() != 0){
    Serial.read();
  }
  next();
  if (slide == slideNum){
    for(;;){
    }
  }
}

void next(){
  String local = data[slide];
  String current[4];
  for (int i = 0; i != 4; i++){
    current[i] = local.substring(0, local.indexOf("\n"));
    local.replace(local.substring(0, local.indexOf("\n")), "");
    current[i].trim();
    local.trim();
    Serial.print("i=" + String(i) + ", current=" + current[i]);
    Serial.println(", local="+local);
  }
  lcd.clear();
  for (int i = 0; i != 4; i++){
    Serial.println(current[i]);
    lcd.setCursor(0,i);
    lcd.print(current[i]);
  }
  //lcd.print(data[slide]);
  slide += 1;
  Serial.println("New: " + String(slide));
}
</code></pre>
 11763: <p>Since you haven't provided all of your code, I can't say for sure exactly what caused your problem except that Arduino String operations employ dynamic allocation a lot. This will cause heap fragmentation, which is especially bad on a chip like the ATmega328 with little RAM and subsequently cause weird issues like you're getting. I would guess that initializing the String members of the array takes up a lot of heap space while fragmenting it and when you added one more string, you ended up with a stack-meets-heap situation at some point in <code>loop()</code>. </p>

<p>You're a lot better off with an array of compact strings using an array of pointers to <code>char</code> i.e. <code>const char * array[] = ...</code> since the strings are literals and so already known at compile time.</p>
