Any sample code out there for driving a 4 x 40 character LCD display?

I have a pretty standard 4 x 40 character LCD display that I'm trying
to use from my BBB.

I already got the BBB working OK with a 4 x 20 character display using
the connections and Python code described here:-

An excellent article and I found it quite easy to follow and make it
all work.

However getting my 4 x 40 character display to work is proving
difficult. The 4 x 40 display is essentially two of the display
controllers in the 4 x 20 display working together. The hardware
interface is the same except that there are two 'Enable' lines, one
for each of the two controllers.

When I try to use my 4 x 40 display (initially with just 'Enable 1'
connected and the other tied to ground) I just get the first eight
characters and then a line of faded/ghost splodges. Try as I may I
can only get to display on the first line of the display and the first
8 characters.

If I ask for 5x10 bit characters instead of 5x8 then I get nothing at
all. If I set two-line mode I just get a few faded/ghost characters.
If I toggle the enable2 bit instead of enable1 leaving everything else
the same then I get nothing.

My 4 x 40 character display is like this one:-

There is documentation at the bottom of the page including some sample
code. The sample code is for an 8-bit microprocessor connected direct
to the LCD but, in the main, looks as if it does basically what my
code does except for some very odd loops but I think they may just be
'left overs'.

The manual for the 4 x 40 display itself doesn't say anything about
software for it or how the two enable bits need to be used. The
manual for the LCD controller is, of course, just for a single
controller, so doesn't deal with the dual-controller.

I think either:-
    I have a faulty display or there is some subtle hardware
    requirement that I'm not fulfilling.

    There are some software requirements or extra command sequences
    required to manage the two display drivers.

Does anyone know of any BBB code specifically for a 4 x 40 display?
Or even code for other SBCs for this sort of display. I can find
various references to such things but they're nearly always "how do I
adapt the 4 x 20 code to work with the 4 x 40 display" without any
actual code/changes.

Any/all ideas would be much appreciated.


My LCD driver should be able to handle display with more than one
Enable line. Please take a look the code from the git repo:
You will find a simple example driving 4x20 characters display in
examples/TestLCD.cpp. Modification for 4x40 characters should be
simple: add one more Enable line and increase number of characters in
the line when you instantiate HD44780 object


Thanks Jacek, I'll take a look, I'd quite like a C/C++ way of driving
the LCD anyway.