Question

I'm using serial communication to display the the data to my 4x20 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 a serial monitor. So is there any possible solution to clear the display or delete a single character from the LCD?

Was it helpful?

Solution 2

I found a quick solution for my problem

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

if you have larger display just increase the value of the loop. As my observation in the serial monitor The cursor pushes forward until the line is clear (based on your loop). but this will not allow you to delete a single character in your display.

OTHER TIPS

Did you try lcd.clear()? It says in the documentation here that this command does the following:

Clears the LCD screen and positions the cursor in the upper-left corner.

Obviously, you'll need the lcd variable (known as a LiquidCrystal object) to use this method. See how to create that here and a basic implementation below. Perhaps you can add a time delay after lcd.print("hello, world!"); and then add lcd.clear(); (just as a basic proof-of-concept.)

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);

void setup()
{
  lcd.begin(16,1);
  lcd.print("hello, world!");
}

void loop() {}

Review the full LiquidCrystal reference for all its methods and additional examples.

The best way I find is to simply add the following line to your sketch:

     lcd.clear();

This will make the lcd display clear out.

Did you try sending 12 (0x0C) as detailed in this Arduino Playground 0 SerialLCD posting

void setup()
{
  Serial.begin(19200); // era beginSerial

void loop()
{ 
  //backlightOn(0);  // turn the backlight on all the time

  clearLCD();
  Serial.write(" Hello");  // print text to the current cursor position
  newLine();              // start a new line
  Serial.write("Arduino");
  delay(1000);
}

//  LCD  FUNCTIONS-- keep the ones you need. 

// clear the LCD
void clearLCD(){
  Serial.write(12);
}


// start a new line
void newLine() { 
  Serial.write(10); 
}

see above link for other commands.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top