1st print only is mislocated and setcursor have no impact - LiquidCrystal - 20x4

Hi, I am using a 20x4 LCD with the liquidCrystal Library.

I’ve been searching for a while and can’t find the reason of this:

Everything work perfect except for the first print!

1st print only is always offset by -2, so the first 2 character are missing, and whatever SetCursor I do will have no impact until a first print was done.

Obviously, I simply patch by adding this for now:

 lcd.begin(20,4);
 lcd.setCursor(0,2);  // this has no impact no matter the value 
 lcd.print("bug Optrex?"); // The first print is not position properly (x-2)
 lcd.setCursor(0,0);
 lcd.print("Hello!     ");

I do however feel this is not very clean… any idea what would be causing that?

Thanks for your insights.

Try

lcd.begin(20,4) ; lcd.clear() ; . . .

it worked indeed. I still don't get the why but at least this is cleaner! :)

Thanks

You shouldn’t have to do a clear() as the library code calls it in begin() to clear the display set the cursor to 0,0 as part of the begin() code.
If it isn’t, then something is not working correctly.
It could be a timing issue between the library and the LCD that may show up doing other things.
Perhaps the LCD is just a bit slower than the timing in the library.

I would be curious if you have the same issue using my hd44780 library.
The hd44780 library can be installed using the library manger.
You can read more about here: GitHub - duinoWitchery/hd44780: Extensible hd44780 LCD library

The i/o class you will use is hd44780_pinIO
So instead of using

#include <LiquidCrystal.h>
LiquidCrystal lcd(.....);

You will use

#include <hd44780.h>
#include <hd44780ioClass/hd44780_pinIO.h>
hd44780_pinIO lcd(....);

Everything else will be the same.

See if the same issue happens with the hd44780 library.
If it does, then your LCD might be slower than the delays used in the libraries.
hd44780 has an API call to tell it to use longer delays if this turns out to be case.
In order to increase the delays in LiquidCrystal you have to go in and modify the library code.

— bill

Windrider.

If you use I2C adapter, you can try this code.

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,20,4);   // 20, 4 OR 16, 2

void setup()
{
  lcd.init();  
  lcd.clear();           // clear the screen
  lcd.backlight();
}

void loop ()
{
lcd.setCursor(5, 1);
lcd.print("HELLO !");
}

If you use I2C adapter, you can try this code.

Only if he has a an I2C adapter just like yours and only if he has a I2C library just like yours. But he doesn't.

On the other hand the displays using a native parallel interface have hardly changed in decades. My genuine Hitachi 1980s vintage devices perform virtually identically to the modern far-eastern imports. Advice based on what happens with one device will almost always be applicable to another.

Bill has pointed out that some devices are 'slower' than others which may be directly related to their extremely low price. They may have 'fallen off a truck' as it left the factory on it's way to the dump or recycling plant.

Don