Clearing display of lcd

lcdmicrocontrollerserial

I'm using serial communication to display the the data to my 4×20 lcd display. When I filled up all the lines of course I need to clear it. I've search over the net and found something like
Serial.write(27); // ESC command
Serial.print("[2J"); // clear screen command
Serial.write(27);
Serial.print("[H"); // cursor to home command
But it doesn't work. I also found a solution like Serial.println(); but that solution(cheat as they called it) will only work on serial monitor. So is there any possible solution to clear the display or delete a single character from it?

Best Answer

The only relevant info I managed to find is this discussion

According to the last comment from the owner of the board

I tried to print the ascii table from 0 to 255. CR, LF, BS, TAB works. other non printable characters are a no go. other characters are perfect though (well the extended characters are limited).

So I wonder if a CR+LF (carriage return, line feed) sequence has an effect of pushing the printed characters out of the screen, that is

for (int i=0; i < 4; i++) 
{
  Serial.print(13);  // carriage return (CR)
  Serial.print(10);  // line feed (LF)
}

or maybe

for (int i=0; i < 4; i++) 
{
  Serial.write(13);  // carriage return (CR)
  Serial.write(10);  // line feed (LF)
}

If these don't work then the alternative I see is to apply the solution that is described in the start of the linked discussion and send 40 backspace commands:

for (int i=0; i < 80; i++) 
{
  Serial.print(8);  // print 40 times backspace (BS)
}

or you may need

for (int i=0; i < 80; i++) 
{
  Serial.write(8);  // print 40 times backspace (BS)
}