How to write to the second line of a display? 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:

set(0,0,1,1,0,0,0,0,0,0);


The general timing and control is correct, as I can get text on the display, and also a function like "shift" works fine.
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.



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