The hd44780 library for LCD2004 still does not handle properly cursor shifts

@bperrybap

I use the LCD2004 with the I2C backpack, and I slightly modified the HelloWorld test sketch from folder hd44780_I2Cexp:

hd44780_I2Cexp lcd2(0x27);
// LCD geometry
const int LCD_COLS = 20;
const int LCD_ROWS = 4;
....
void loop() {
  int r = lcd.moveCursorLeft();
  int s = lcd.status();
  Serial.print("AC "); Serial.println(s & 0x7F);
  delay(1000);
}

The sketch outputs "Hello, World!" to the screen, then starts moving the cursor to the left. After reaching the left-most position of line 1, it jumps to the right-most position of line 4, goes through it to the left, jumps to line 2, then to line 3, then back to line 1.

The debug output is (AC is supposed to be the cursor address):

04:16:45.486 -> AC 10
04:16:46.488 -> AC 9
...
04:16:53.491 -> AC 2
04:16:54.509 -> AC 1
04:16:55.521 -> AC 0
04:16:56.484 -> AC 103
04:16:57.484 -> AC 102
...
04:17:34.562 -> AC 65
04:17:35.554 -> AC 64
04:17:36.583 -> AC 39
04:17:37.596 -> AC 38
...
04:18:03.612 -> AC 12
04:18:04.636 -> AC 11
04:18:05.644 -> AC 10

Then it repeats.

I am aware of the weird row offsets set by the HD44780 controller, and everybody refers to link http://web.alfredstate.edu/weimandn/lcd/lcd_addressing/lcd_addressing_index.html, which unfortunately is dead. I will appreciate a live link.

Am I missing anything? If this library does not support properly cursor shifts, which one does?

You can enable "line wrap" in the hd44780 library. Perhaps that will do as you wish. Consult the documentation.

1 Like

Thank you for your prompt reply! I have added

lcd.lineWrap();

as the last line of setup(). Unfortunately, nothing has changed.

I'm surprised the link lasted as long as it did since I retired from Alfred State College in 1997. Send me a message with your email address and I'll reply with a PDF version of that web page.

Don

2 Likes

Well it is, but it likely isn't what you are expecting/wanting.

The hd44780 library status() returns the raw hd44780 "busy status & address" directly from the chip.
The "AC" bits are the DDRAM Address Counter.
It is essentially the ram address where the characters are stored.
The odd looking movements of the cursor to discontinuous locations on a 20x4 display is due to the way the DDRAM memory locations are mapped to the physical display.

Here is live link that explains hd44780 memory mapping:

Column and Row are an invention by the LiquidCrystal API.
These are not part of the hd44780 chipset.
The chipset is simplistic and simply uses a DDRAM address to set a cursor position.
When you call setCursor(col, row) the library converts the col and row to a DDRAM address to give to the chipset.

I'd also recommend reading the datasheeet:

As it has additional information about this.

Unfortunately, at this point in time the hd44780 library lineWrap() only works for printing (output).
It does not do any mappings for shifts, or things like cursorLeft / cursorRight.
Note:
I'll add updating moveCursorRight() and moveCursorLeft() to support lineWrap() in the next release.

--- bill

1 Like

Thank you, I've sent you my email.

Thanks, I am not sure whether you've been notified about my post #3 addressed to you.

Sorry that i coudnt help.

1 Like

Glad to see that it is actually still alive. I'm not sure when they moved things around and changed the URL.

Don

1 Like

I appreciate very much your detailed explanations, the links and the hope, which you gave, to enjoy your library in its entirety!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.