4

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?

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
NewInJava
  • 35
  • 1
  • 4
  • 12
  • You should include the Manufacture and Part Number of the Serial LCD module. We can only guess as to its command set. – mpflaga Jan 14 '14 at 19:58
  • @mpflaga This is the one I only have [E-term](http://www.e-gizmo.com/KIT/images/eterm/E-term.pdf) – NewInJava Jan 14 '14 at 20:07
  • You might want to look at their hard to find example code https://gist.github.com/egizmocodes/7819592 It is unclear if this is for the LCD you have. – Craig Jan 14 '14 at 21:32

5 Answers5

1

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.

gary
  • 4,227
  • 3
  • 31
  • 58
  • That may not work because I am using a serial communication in displaying. Liquid crystal library uses parallel communication I think. – NewInJava Jan 14 '14 at 19:19
  • A quick search yields an example of LiquidCrystalSerial: http://arduino.cc/en/Tutorial/LiquidCrystalSerial, which also uses the `lcd` object. – gary Jan 14 '14 at 19:21
  • But when i used the liquidcrystal library to display in my lcd it doesn't work – NewInJava Jan 14 '14 at 19:30
  • after testing your code and the code in the link you gave me, it doesn't give me a display on my lcd and even to the serial monitor – NewInJava Jan 14 '14 at 19:40
  • Did you change the values based on your setup? (The arguments to lcd are numbers that represent pins/connections. – gary Jan 14 '14 at 22:50
  • Actually that set-up uses 6-GPIO pin. while mine uses only 2. mean it will not work. but I'll also test that setup cause the solution i've come upon doesnt really delete the display or character. – NewInJava Jan 14 '14 at 23:02
1

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.

NewInJava
  • 35
  • 1
  • 4
  • 12
1

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.

Michael Mulvey
  • 131
  • 1
  • 9
0

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.

mpflaga
  • 2,807
  • 2
  • 15
  • 19
  • I tried one of it `void clearLCD(){ char keypressed = myKeypad.getKey(); if(keypressed == 'C'){ Serial.write(12); } }` but it doesn't clear the lcd but display the character "C" – NewInJava Jan 14 '14 at 20:05
  • Try Serial.write(chr(2) + chr(12) + chr(3)). If the terminal is the one I think it is, then enclosing the commands between STX and ETX should do the trick. – cup Jan 15 '14 at 08:40
0

Add this code to your script.

  void clr(int x) {
  lcd.setCursor(7, x-1);
  lcd.print("<--Remove");
  delay(2000);
  lcd.setCursor(0,x-1);
  lcd.print("                   ");
}

To use it use the following command.

clr(1); //clears the first line of the display

clr(2); //the second and so on.
Michael Mulvey
  • 131
  • 1
  • 9