Text pulled to the right on the 16x4 I2c LCD

My LCD cursor is not working normally.
I'm using a 16x4 LCD.

The problem is that the first and second lines are well written, but the third and fourth lines
has a blank space on the left.

Im write my code based on correcting this third and fourth line using the lcd.setCursor (-4,2); lcd.setCursor (-4.3) and everything was going fine, until I needed to use the lcd.scrollDisplayRight() function. That's when I saw I was in trouble.

This is the problem with LCD. The third and fourth line using the lcd.setCursor (0,2); lcd.setCursor (0.3) but is writing like lcd.setCursor (4,2); lcd.setCursor (4.3)

For Correct this im using (-4,*) that create a other issue.
the third and fourth lines go around the screen faster than the first and second

this ends up misaligning the text

#include <LiquidCrystal_I2C.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x27, 16, 4);

void setup() {
  // put your setup code here, to run once:
lcd.print ("drawline");
lcd.setCursor (0,1);
lcd.print ("drawline");
lcd.setCursor (0,2);
lcd.print ("drawline");
lcd.setCursor (0,3);
lcd.print ("drawline");

void loop() {
  // put your main code here, to run repeatedly:


Have you tried using a different library, it looks almost like the LCD controller is set for a 20 x 4 display instead of 16 x 4.


I didn't try, as we have more than 1000 libraries available for LCD. I don't know which ones it is. I can't say which driver for my LCD either. I just know my driver is HD44780 because I saw it in the datasheet.
Have you tips for finding a library?

This library hd44780 - Arduino Reference has a good reputation in the forum


Well, that is the almost universal driver IC for these character displays.

Not to be confused with Bill Perry's HD44780 library installed from the IDE Library Manager which is recommended.

please do a simple sketch


and make a picture what YOUR display with YOUR library is showing on the display.

If you are using the LiquidCrystal I2C the root cause might be following:

LiquidCrystal I2C calculates the line offsets like following:

void LiquidCrystal_I2C::setCursor(uint8_t col, uint8_t row){
	int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };
	if (row > _rows) {
		row = _rows-1;    // we count rows starting w/0
	command(LCD_SETDDRAMADDR | (col + row_offsets[row]));

but your 16x4 might have offset
0 ... 0x00 - 0x0f
1 ... 0x40 - 0x4F
2 ... 0x10 - 0x1F
3 ... 0x50 - 0x5F

therefore row 2 and 3 appear shifted by 4 digits.

you could open the LiquidCrystal_I2C.cpp with an editor and modify around row 106 the last two offsets to 0x10 and 0x50.

Here is some background information on cursor positions:

This was a common problem with the Arduino LiquidCrystal library several several years ago but has long since been resolved.

The I2C library that you are using is probably based on one of those ancient versions of the Arduino library. You should really consider switching to Bill Perry's HD44780 library as mentioned previously.


1 Like

Yes, the LiquidCrystal_I2C library (at least the one in the IDE library manager) is broken for 16x4 displays. There is no way to work around this without fixing the library code.
The hd44780 library does not have this issue.
I will also mention that scrollDisplayRight() may not work the way you think it does.
All this function does is offset the location where lines on the display map to memory so everything on the display (all lines) will shift
It is all but useless on anything but a 1 line display.

I would recommend that you switch to the hd44780 library and use the hd44780_I2Cexp i/o class.
The hd44780 library is actively maintained, is faster and some additional capabilities not found any any other hd44780 type library.
It is available in the IDE library manager, and includes lots of documenation.
If you want to read about it before you install you can start on the hd44780 github page.

--- bill

For the gory details:

Background of LIquidCrystal_I2C library.
The history of the "LiquidCrystal_I2C" library goes back more 10 years to about Sept of 2009.
It was original created by Mario H from the LiquidCrystal library at that point in time.
Remember, back then there was no IDE library manager. You could not even import a library in zip format so the LiquidCrystal_I2C library was copied and posted on many places around the net. And some of those copies have since been modified with updates and minor bug fixes so there are now many "silent" forks out there all with the same name.
6 years ago a guy named Marco Schwartz put a copy he obtained that was last touched by a guy named Frank de Brabander on github to set it up for using the new networked based IDE library manager.
It was definitely an improvement to have it available in the IDE library manager.
Unfortunately Marco didn't have the technical skills to maintain it.
There have been a few updates done since Marco created the github repository but there have also been and are still some issues with the repository - like incorrect tagging for the IDE library manager get some of the fixes. And the code is behind in some updates related to cursor positioning.
The LiquidCrystal_I2C library became such a mess along with what I felt was a need for a "plug and play" solution for these types of LCDs that I created the hd44780 library back in 2016
In late 2018 Marco wanted to re-assign the LiquidCrystal_I2C repository to someone that could properly maintain it.
Marco asked if I would do it, I didn't want to take it on.
Eventually a guy named John Rickman took it over. Which I originally thought would be a good thing as I thought some needed fixes (that were pretty trivial to get resolved) could finally get fixed.
However, that's when, IMO, things went downhill and became much worse for this library.
John, has made a wreck of the library. He first moved the "active" repository over to gitlab and changed the name. This was a deal breaker since it would mean that that the IDE library manager would not longer be able to have access to it.
Then he tried to change the license from LGPL to Apachie.
I stepped in an called him out on it. He finally agreed that he couldn't change the license but his solution was to delete the repository from gitlab.
Unfortunately, Marco ended up handing the github repository over to a person that hijacked it then abandoned it.
At this point Rickman no longer responds to my emails.
So as of right now, there is a LiquidCrystal_I2C library in the IDE library manager but it has issues, is no longer supported, and there is no way to get it updated.

--- bill


Guys, today I tested this hd44780 library needed above. In fact I no longer need to use
** lcd.SetCursor (-4.2); (-4.3) ** to fix the space problem. But this library has the same error as the previous with the scroll function.

I don't know if is my configuration is the correct, but is working.

#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h> 

hd44780_I2Cexp lcd; 
hd44780_I2Cexp lcd1(0x27);

const int LCD_COLS = 16;
const int LCD_ROWS = 4;

void setup(){

int status;
	status = lcd.begin(LCD_COLS, LCD_ROWS);

	lcd.print("hello, World!");
  lcd.setCursor (0,1);
  lcd.print("hello, World!");
  lcd.setCursor (0,2);
  lcd.print("hello, World!");
  lcd.setCursor (0,3);
  lcd.print("hello, World!");
  delay (3000);

void loop() {lcd.scrollDisplayRight(); delay (500);}

Follow the images below in Time Lapse.

Really, now i know.

It is not an error.

Scrolling does not work.

It cannot work. Simple as that. This is not a video monitor, it is a basic LCD display. Accept that. :face_with_raised_eyebrow:

So what is it? Because in my opinion if the 4 lines are equal, they need to scroll equal and reach the left of the screen together.

I've already accepted that current libraries are limited with this little problem. But I recommend that you read the datasheet.

I have never complained about anything here, I just stated that it is a problem, and in fact it is.

If you think the display as shown in the 3rd photo is incorrect then there is a misunderstanding how the limited LCD memory is mapped to the LCD display particularly when combined with the right/left shift instructions.

BTW, I think noasca's sample sketch code is pretty goofy.
I think it makes things even more confusing when certain numbers/characters as skipped.
i.e. why leave out '3's ?

The display shown in the 3 images where you did two shifts is as to be expected given the way the LCD memory is mapped to the display on a 16x4 display.
Like I said the shift right/left instruction capabilities of a hd44780 display are not that useful on displays larger than 1 line.

I would recommend having a read on how the LCD memory addressing/mapping works.
You can find a link to a web page with detailed information on this in the documentation included in the hd44780 library.
Bring up the Documentation sketch in the hd44780 library examples, and in the comments of the sketch, click on the link referenced by:
hd44780 internal RAM addressing:
It will link to a web pages that explains how the hd44780 internal memory is mapped to the physical LCD display for various geometries.

--- bill

You are free to have your own opinion and believe anything you want; however, in this case, it isn't how the LCD h/w actually works.

Hang on their partner.
I think if YOU read the datasheet, and fully understood it, then you would realize that this is not a library issue/problem but rather an expected behavior given the limitations in the hd44780 chipset h/w.
i.e. the way it is working is exactly as expected given the way the hd44780 h/w works when combined with the hd44780 shift right/left instructions on a 16x4 display.

But the real problem is expecting the LCD to work in a way that is not the way the hardware actually works.
These chipsets were designed more than 40 years ago and have very limited RAM so they can't do what you wanting given that limited RAM.
It isn't so much a problem but rather a misunderstanding as to how the LCD h/w works.
Like I've said a few times, the shift right/left instructions are pretty much unusable on anything but a 1 line display.

--- bill

I'm Reading the Datasheet to learn how this work.

I'm trying to make a screen animation program. It's actually a kind of oscilloscope with this type of 16x4 screen.

I tried to use the Scroll tool, but seeing that it doesn't work, I abandoned the idea.

Let me tell you. When I used <LiquidCrystal_I2C.h> The spacing between each lap on the screen was the ratio of 4 empty spaces on the third and fourth lines. In the library "hd44780-master" you indicated for download the number goes up to 6 empty spaces after the first scroll, after the second lap the text goes back to normal and so on.

But I don't deny that this library is much more efficient in relation to not having to use (-4,*) in Set.Cursor, besides being faster than the IDE's native one.

I'm not criticizing the Library, in fact, I would never do that. It's like someone complaining because someone else is helping you, it doesn't make sense

I'm reading the Datasheet and getting an idea of ​​how to solve my specific problem.

You dont need Stress...
By the way, when I mentioned:

It's because I had already trusted your word and left the idea aside.


Dont understand that when i said ERROR is a Error of MY Project and dont need

you don't need to highlight the "CANNOT", because I get it when i said

Your 16x4 display only needs 64 bytes of SRAM memory if you want to keep a copy of the image in a buffer.

You can scroll, rotate, or otherwise manipulate the buffer very easily. Then blit the 64 bytes to the LCD in one go.

Controllers like ST7920 can display graphics as well as text.
You can produce more professional images, graphs, text than with a HD44780 character display.


Wow... This is great! I will research how to do this.

That (hd44780-master) isn't anything anyone recommended.
You should be installing the hd44780 library using the IDE library manager network install capabilities.
I highly recommend that you DO NOT download a zip of the repository and then install it manually or use the zip image install capabiality in the IDE.
There are github zip image structure issues with the Arduino IDE.

Not only is it more work to do your own download but unless you take a few additional steps you will end up with an improperly named directory in your IDE libraries directory which can cause problems when doing updates in the future.
Use the IDE library manager to locate the library and then to automatically do the download and install.
The instructions on the hd44780 github page explain how to install the library using the IDE library manager and even warns against using zip installs unless using a VERY old version of the IDE.

If you end up with a directory name hd44780-master, you did something wrong.

--- bill

Okay, I get it. Thank you!

Only For Close This topic.

What is Learned.

1 LCD SRAM Doesn't work as I thought

2 ROLL Does not work perfectly in some cases

3 The hd44780-master library is more efficient than arduino's native <LiquidCrystal_I2C.h> and fixes the bug of writing 4 columns ahead of the third and fourth lines.

  1. Is possible manipulate the text directly from arduino

Thanks for everything. Don't stress, you're good people but I'm Brazilian and it's difficult to translate because sometimes the text comes out as offensive. I apologize to everyone, I'm new here and I don't want to be arrogant with you who always help me