delete a character in a lcd

i m new in lcd......i like to delete a word which i misstyped in an lcd.....lcd is 16*2.......help me out

Move the cursor to the incorrect character. Print the correct character over the top of it. If you are trying to erase a character back to blank, then print a space.

sir,
how to move to the incoorect position.....as posotion is unknown to me......pls help me out

It may come as a a surprise to you, but we can't see your code.
Use code tags.

It is your job to keep track of your cursor position.
A library could keep track of the current print position. I don't think that any common Arduino libraries do this.

As far as I know, there is no way to ask the HD44780 controller.

So the simple answer is: do it yourself.

If I position the cursor at (1, 3) and print "Davix" instead of "David", I need to lcd.setCursor(1, 7) and print("d")
This will rub out the "x" and replace it with "d"

If you have an interactive application, you might want to implement a "rub out" by lcd.setCursor(1, 7), printing a " ", and goto(1,7) again, ready for printing a new character.

This all sounds quite straightforward. But you have to worry about whether you have got legal x,y positions. What happens if you are at the edge of the screen?

Likewise, you could use lcd.rightToLeft(), print a space, then go back to regular lcd.leftToRight() printing.
Try it. I think you will encounter more difficulties.

In practice, a 16x2 screen is so small that you might just as well re-draw the whole thing if you want to make a correction.

David.

david_prentice:
As far as I know, there is no way to ask the HD44780 controller.

You need to read the hd44780 datasheet a bit closer.
You can ask the hd44780 the memory location of the next write.

See bottom of page 24 of the datasheet.
When you read the “BUSY” status you also get the memory address counter.
This counter is the memory location of where the next data write will be written to memory.

Most libraries don’t use the BUSY status and other than my hd44780 library I’ve not seen any other library that provides a way to read from the LCD.
My hd44780 library has a read() and a status() function that allows reading from the LCD.
read() reads data and status() will read the busy/address counter.
See here for details on the hd44780 API:

This requires that the library be able to control the r/w line.
The address can be read using status() on PCF8574 based backpacks ( since they all seem to hook up the r/w line) or when using direct arduino pin control if you wire up an arduino pin to the r/w line and tell the library to use it.

So if you want to back up the text position and are not backing up to a previous line, all you have to do is read the address using status() and decrement the address returned by status() by the amount you want to back up and use setCursor(address, 0) to set the new address.
It is more complicated if you are backing up to a previous line since the memory addresses for lines are not contiguous.

Eventually, I’ll be providing a full “terminal mode” in hd44780 which will make the LCD work just like a mini display terminal so things like , and and line wrapping will work. But that isn’t’ there yet.

— bill

Oops. My mistake.

All the same, it is not difficult to keep track of your display. Then setCursor() to overwrite.
This will work with write-only displays or the official LiquidCrystal library that comes with your IDE.

David.

david_prentice:
Oops. My mistake.

All the same, it is not difficult to keep track of your display. Then setCursor() to overwrite.
This will work with write-only displays or the official LiquidCrystal library that comes with your IDE.

David.

While it sounds easy, in reality it isn’t always that easy since there are so many little things that have to be dealt with.
There are many usage cases that make things complicated.
Consider what the OP originally said:

i like to delete a word which i misstyped in an lcd

If we are talking about a word and not a character, things start to get complicated and messy very quickly to make something that works for all cases.
For example, the word could have been input and stored as a C string then sent to the display.
In this case the actual length of the string may not be known by the code that printed the “word” and then how will the code that erases the word ever get it?
There are many different possibilities of things that start to create complexities when the code is wanting the LCD to work like a mini terminal.
Line wrapping and words spanning lines makes the erasing of words or even characters much more difficult since the memory is not contiguous.
Just doing line wrapping in the application gets messy as the code will have to send each character individually to the LCD library to be able to count characters for the line wrap. This means that the code can no longer do even simple things like print numbers using the functions in the Print class since the amount of characters to be printed is not known in advance.

Believe it or not, it is actually much easer to handle line wrapping and backspace support in the library than in the application.
Doing it in the application is actually pretty tough since it means that it can no longer use any of the output formatting functions in order to be able to see all the characters being printed so that it can do all the necessary character counting to track the positions on the display to be able to handle line wrapping and backspacing.

— bill

One way to deal with this, is basically not to deal with it.
By that I mean change the way the application works to not expect to be able to backspace over existing text.
Change the application to always draw the full text to the display or at least the fields that have changed.

Depending on what is done it will likely affect how the user interacts with the application.

If that isn't possible, then another type of LCD (one that supports a terminal mode like the ones from ByVac) or another library that supports line disciplines (like the LiquidCrystalFast library here: LiquidCrystal Arduino Library, using small character LCD modules with Teensy) will have to be used.

--- bill

#include<LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
int i=0;
//int m=0;
int thisCol=0;
int thisRow=0;
int m;

void setup()
{
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
Serial.begin(9600);
lcd.begin(16,2);
}

void loop()
{

digitalWrite(8, HIGH);
digitalWrite(9, LOW);
if(Serial.available()>0)
{
lcd.write(Serial.read());

if(Serial.find(“0D”)) //0D displayes when i press enter in xctu
{
lcd.setCursor(thisCol, thisRow);
thisCol=thisCol-1;
lcd.setCursor(thisCol, thisRow);
lcd.print(‘0’);
}
}
}

this is my code…i m using xbee for doing serial communication(my all connection are right when i interface with xbee)…as i have typed wrong in an lcd while i m doing chatting(XCTU software)…now i have to delete a word…what changes i have to made in a code

as i pressed enter in an xctu it deletes a word in an lcd

this is i want…so help me out in a code

The code you posted is not doing what you want, but I don't understand what your XCTU s/w is sending and I don't understand what you are wanting to do.

The code has errors in it. loop() reads a serial character and sends it to the display, it then waits for "OD" to show up and then attempts to back up one character. But since thisCol and thisRow are not being maintained, they will always be zero, which means that setCursor() will set to column -1

What data is coming in on the serial port and what is it that you are wanting to do?
Or what would you do differently if the output was to a real terminal?

--- bill

@alankar20141

You’ve got the right idea about keeping track of the cursor, but there are quite a few issues with the code as written…

This following code can be used as a starting point to move forward with code development, it assumes that a carriage return code means “go to the next line” and that your terminal program will send backspace characters (ASCII code 0x08).

This code needs further elaboration to do what you want, for example it does not handle conditions where the cursor runs off either end of the screen (thisCol <0 or > 15. Nor does it handle more than the first carriage return (ASCII code 0x0d), but you should be able to make these additions yourself.

void loop()
{
  while (Serial.available() > 0)
  {
    rxChar = Serial.read();
    if (rxChar < 0x20)
    {
      // ASCII control code
      switch (rxChar) {
        case 0x08:  // Backspace ASCII code
          thisCol--;
          lcd.setCursor(thisCol, thisRow);
          lcd.write(' ');
          lcd.setCursor(thisCol, thisRow);
          break;
        case 0x0d:  // Carraige return
          thisCol = 0;
          thisRow = 1;
          lcd.setCursor(thisCol, thisRow);
          break;
      }
    }
    else
    {
      // ASCII printable character
      lcd.write(rxChar);
      thisCol++;
      lcd.setCursor(thisCol, thisRow); // This is not needed as the cursor will have moved anyway
    }
  }
}