I got this 4 line display from Mouser: https://www.gravitech.us/20chbllcd.html, and I get it to work fine for lines 1 and 3 (as line 3 is just the 21st character of line 1). But I am struggling to get lines 2 and 4 working. If I understand correctly, these are "line 2" for the HD44780 controller, and I should set the DDRAM address to 0x40 before I write there.

But, when I try that, nothing happens.

I tried writing 0x04 to the DDRAM address counter, and I can see the cursor jumping there, but when I write to that address, no text shows up. If I omit the command, text pops up correctly.

Also, when changing the contrast of the display (using the potentiometer on the Vdd and Vo pins), only lines 1 and 3 change contrast.

My code:

This method I use for convenience:

void set(int _rs, int _rw, int _d7, int _d6, int _d5, int _d4, int _d3, int _d2, int _d1, int _d0) { ... }

To set the DDRAM address to 0x40:


The general timing and control is correct, as I can get text on the display, and also a function like "shift" works fine.

  • 1
    You're not using the standard LiquidCrystal.h library?
    – Majenko
    Jun 8 '20 at 22:12
  • @Majenko no, not yet. If I cannot get this to work myself, I'll try and see if that can work. I looked at the LiquidCrystal source code though, and I didn't see anything I could use. Jun 10 '20 at 12:57
  • 1
    Personally I would start with the known working, well tested, and properly supported LiquidCrystal.h library, and then pare it down to just the code I needed (if code size were an issue). As it is we can't really help you since we don't know your code or setup.
    – Majenko
    Jun 10 '20 at 13:05
  • Line 1 starts at address 0x00 | 0x80 0b10000000 and ends at 0x13 | 0x80 0b10010011
  • Line 2 starts at address 0x40 | 0x80 0b11000000 and ends at 0x53 | 0x80 0b11010011
  • Line 3 starts at address 0x14 | 0x80 0b10010100 and ends at 0x27 | 0x80 0b10100111
  • Line 4 starts at address 0x54 | 0x80 0b11010100 and ends at 0x67 | 0x80 0b11100111

That 0x80 0b10000000 is the HD44780 command for set DDRAM address. The other bits 0b1xxxxxx define the address.

20x4 HD44780 addressing

You'll find more details at Arduino with HD44780 based Character LCDs


You need to setup the HD44780 in 2-line mode. The command is | 0 | 0 | 1 | DL | N | F | X | X | with:

  • DL: 0 = 4-bit / 1 = 8-bit interface
  • N: 0 = 1 line / 1 = 2 lines (this is the bit to set)
  • F: 0 = 5x7 / 1 = 5x10 font size

Most probably you have that command already in your program to set the width of the interface, but with N = 0.

Note: The common algorithm is to send the command 0x33 three times to make sure to be in 8-bit mode. The first can be the second part of a half-done 4-bit command, possibly not changing the interface width. Then the second and third will switch into 8-bit mode. If the device is already in 8-bit mode, or gets into it in the course, it makes no harm to repeat.

Since in 4-bit mode only D7 to D4 are used, you can change 0x33 into 0x38 to enable the 2-lines mode.

Not the answer you're looking for? Browse other questions tagged or ask your own question.