Color LCD Shield corrupting Serial comms

I wasn’t able to find anything helpful doing a search of the forum.

My setup is an Arduino Uno with a Color LCD Shield on top and nothing else. Eventually I’m trying to send HTML to a WiFly RN-XV, but for now I’m trying to just get the Color LCD Shield to display stuff and be able to also use the UART to send out lots of stuff over the serial communications. The problem I’m having is that when I am using lcd.setStr() the stuff I’m trying to send over the UART gets garbled up. Commenting out the function call for the function I’ve written (refreshLCD()) that contains lcd.setStr() fixes the UART problem.

Any help solving this problem is very much appreciated.

My code is below:

#include <ColorLCDShield.h>
#include <string.h>

#define B BLACK
#define F WHITE

LCDShield lcd;

char str1[17] = "0101010101010101";
char str2[17] = "1010101010101010";
char str3[17] = "    Sunrise";
char str4[17] = "1010101010101010";
char str5[17] = "0101010101010101";
char str6[17] = "1010101010101010";
char str7[17] = "0101010101010101";
char str8[17] = "1010101010101010";
char str9[17] = "0101010101010101";

char tmp;

void setup()
{
  lcd.init(EPSON); // This should only be init(EPSON) or init(PHILLIPS)
  lcd.contrast(44);
  lcd.clear(RED);
  delay(500);
  Serial.begin(9600);
}  //void setup()
  
void loop()
{
  refreshLCD();
  ServePage();
  delay(1000);
}  //void loop()

void refreshLCD(void) {
  lcd.clear(B);
  delay(100);
  lcd.setStr(str1,0,2,F,B);
  lcd.setStr(str2,13,2,F,B);
  lcd.setStr(str3,26,2,F,B);
  lcd.setStr(str4,39,2,F,B);
  lcd.setStr(str5,52,2,F,B);
  lcd.setStr(str6,65,2,F,B);
  lcd.setStr(str7,78,2,F,B);
  lcd.setStr(str8,91,2,F,B);
  lcd.setStr(str9,104,2,F,B);
  delay(50);
}  //void refreshLCD(void)

void HTML_print(char *data) {
  Serial.println(data);
  delay(30);
}  //void HTML_print(char *data)

void ServePage(void) {
  HTML_print("<html>");
  HTML_print("<title>Rising Sun</title>");
  HTML_print("<table>");
  HTML_print("<tr>");
  HTML_print("<td>");
  HTML_print("<form action=\"\" method=\"post\">");
  HTML_print("<fieldset>");
  HTML_print("<p>Select Current Day:
");
  HTML_print("<input type=\"radio\" name=\"#\" value=\"0\" /> Monday
");
  HTML_print("<input type=\"radio\" name=\"#\" value=\"1\" /> Tuesday
");
  HTML_print("<input type=\"radio\" name=\"#\" value=\"2\" /> Wednesday
");
  HTML_print("<input type=\"radio\" name=\"#\"  value=\"3\" /> Thursday
");
  HTML_print("<input type=\"radio\" name=\"#\"  value=\"4\" /> Friday
");
  HTML_print("<input type=\"radio\" name=\"#\"  value=\"5\" /> Saturday
");
  HTML_print("<input type=\"radio\" name=\"#\"  value=\"6\" /> Sunday</p>");
  HTML_print("<p>Enter Current Time (HHMMSS):");
  HTML_print("<input type=\"text\" name=\"%\" size=\"6\" /></p>");
  HTML_print("<p>Select Alarm:");
  HTML_print("<select name=\"~\">");
  HTML_print("<option value=\"1\">1</option>");
  HTML_print("<option value=\"2\">2</option>");
  HTML_print("<option value=\"3\">3</option>");
  HTML_print("<option value=\"4\">4</option>");
  HTML_print("</select></p>");
  HTML_print("<input type=\"radio\" name=\"^\" value=\"1\" checked/>Enable
");
  HTML_print("<input type=\"radio\" name=\"^\" value=\"0\" />Disable</p>");
  HTML_print("<p>Enter Alarm Time (HHMMSS): ");
  HTML_print("<input type=\"text\" name=\"@\" size=\"6\" /></p>");
  HTML_print("<p>Select Alarm Day(s):
");
  HTML_print("<input type=\"checkbox\" name=\"!\" value=\"0\" /> Monday
");
  HTML_print("<input type=\"checkbox\" name=\"!\" value=\"1\" /> Tuesday
");
  HTML_print("<input type=\"checkbox\" name=\"!\" value=\"2\" /> Wednesday
");
  HTML_print("<input type=\"checkbox\" name=\"!\" value=\"3\" /> Thursday
");
  HTML_print("<input type=\"checkbox\" name=\"!\" value=\"4\" /> Friday
");
  HTML_print("<input type=\"checkbox\" name=\"!\" value=\"5\" /> Saturday
");
  HTML_print("<input type=\"checkbox\" name=\"!\" value=\"6\" /> Sunday</p>");
  HTML_print("<input type=\"submit\" value=\"Go!!!\" />");
  HTML_print("</fieldset>");
  HTML_print("</form>");
  HTML_print("</td>");
  HTML_print("<td>");
  HTML_print("<table>");
  HTML_print("<tr><td><p>");
  HTML_print("Time when page was loaded: ");
  //display the time
  HTML_print("</p></td></tr>");
  for (int i = 1;i<=4;i++) {
    HTML_print("<tr><td>");
    //alarm info
    HTML_print("<p>Alarm ");
    Serial.print(i);
    delay(30);
    HTML_print("
");
    //if( )  //if the alarm is enabled
      HTML_print("Alarm Enabled
");
    //else  //if the alarm is not enabled
      HTML_print("Alarm Disabled
");
    HTML_print("Alarm Time: ");
    
    HTML_print("</p></td></tr>");
  }  //for (int i = 1;i<=4;i++)
  HTML_print("</td>");
  HTML_print("</tr>");
  HTML_print("</table>");
  HTML_print("</html>");
  delay(300);
  Serial.print("$$");
  delay(200);
  HTML_print("close");
  delay(30);
  HTML_print("exit");
}  //void ServePage(void)

I am having this exact same problem, and upon further examination the SetChar command also causes this same problem so i think the issue may be coming from there. I can’t pinpoint what the problem is however. Have you found a solution to this anywhere yet?

I’m having this problem as well, I’m also having problem using the color lcd shield together with the OneWire library. It seems that the arduino starts up and then reboot over and over again. if I leave the Setstring command out then it seems to work and if I don’t use the One wire library then the lcd runs normally.

Any thoughts?

PS I’m from sweden so you have to excuse my english DS

It sounds to me like you are running out of RAM. The Arduino Uno only has a small amound of Ram (2k I think? or is it 1k), and when it runs low literal strings can get overwritten by other variables (hence the garbage) or the stack can overflow causing a reset.

ug01x, all that html code is stored in the ram aswell as the program memory, which will be why you are running out of Ram. Try storing all those strings in the HTML_print() calls in the program memory (Lookup how to use PROGMEM, I can give you some hints if you need) and have a small char array in which to recover each string one by one as you print it.

bearframe, without some code, I cant help you further. But check for where might be using lots of ram - Can you reduce the number of strings (or use PROGMEM), can you reduce the size of variables - use byte or char instead of int or long. Reduce the size of arrays if possible.

You could try using my LCD shield library (https://github.com/TCWORLD/gLCD-Library/downloads) as I have tried to make it use as little memory as I can. If you go down that route, have a look at the example sketches that come with it, it is quite simple to use.