Info on how to use 40x4 LCD

I bought a 40x4 big blue LCD on Amazon, and struggled a bit to get it working until I figured it out, so figured I’d share in case it’s useful to someone else!

Basically, it appears as two different 20x2 units and has tWo Enable (E) lines, one for each half. The RS and RW and D4-D7 are connected normally. At first I thought I could just selectively enable the E line for the one I wanted, but it’s not that simple:

To make it work, I declared two instances of the LiquidCrystal object but with the Enable lines defined differently:

const int rs = 12, enTop = 11, enBottom = 13, d4 = 5, d5 = 4, d6 = 3, d7 = 2;

LiquidCrystal lcdTop(rs,    enTop,    d4, d5, d6, d7);
LiquidCrystal lcdBottom(rs, enBottom, d4, d5, d6, d7);

This appears to work just fine.

        lcdTop.begin(40, 2);
 lcdBottom.begin(40, 2);

 lcdTop.setCursor(0, 1);
 lcdTop.print("Second Line");
 lcdBottom.setCursor(0, 0);
 lcdBottom.print("Third Line");
 lcdBottom.setCursor(0, 1);
 lcdBottom.print("Fourth Line");

Thanks for taking the time to post your solution.