Felipe Tavares' Avatar

Graphical Mode for the HD44780

May 29, '24

Set the Scene

What is HD44780 I speak of? Can we eat it? How will it help in the class struggle?

So many questions! But first, hello to you! In typical me fashion it has been a while since I last updated the blog, and even though writing is one of the most enjoyable human activities, here I stand (or more accurately, sit) again having done none of it for several months.

Now, to your first question, the HD44780 is a chip:

Potato chips with a huge “HD44780” splattered across

no no no, not of that kind, this kind of chip:

Computer chip showing “HD44780A00” markings

Now, can you eat it? I think you can eat any kind of chip if you are brave enough! Be free!

It was designed in the 80s, with the purpose of controlling small alphanumeric LCD displays, such as these:

20x04 alphanumeric display

But the most common form factor is the time-tested and fan-favourite 16x2 LCD display, which every hobbyist and engineer has done at least one project with, and most likely several.

Hackaday, the pit-stop for all things open hardware and hardware hacking, has even made a homage to the little dude for the amount it was featured in the website.

So picture this: me, one of these guys, intensely staring at each other.

The scene has been set.

The Bike

Now we must introduce the second character in this adventure. It is my recently acquired motorcycle:

A Super Soco TC-Max Electric Motorcycle

This is no regular death machine, instead, this is a worse-than-average death machine! With a twist: it’s electric.

But the reason this road killer comes into the play has nothing to do with its electrifying aura. No. It is just that where I am at, physically (and mentally since my head is firmly attached to my body), learner riders (and drivers) cannot use a phone to look at directions! You must buy a dedicated GPS unit, or just be a pigeon and have magnets in your brain to help you with directions.

Of course, me being me, I could not let this opportunity to complicate my own life pass me by! Instead of buying a used GPS for as low as 5 bucks, I, the president of over complicating things, must instead build my own GPS.

Do it Fast

If I know one thing about myself is that I must strike quickly on random ideas before the next idea comes and I leave a trail of unfinished projects in my wake.

One of the ways of doing so, beyond the obvious “do it”, is to reduce scope and focus on doing things in the simplest way possible.

So what is the simplest way of building a GPS? You just use a GPS! And you know what is a really good GPS? A phone!

Several people have done this before, and the idea is straightforward: you attach a micro controller to some kind of display, and you phone sends one way directions to the micro controller which then get displayed.

Back to the HD44780

I happened to get an ESP32 microcontroller and a HD44780-compatible 20x4 display since that’s what they had in store. Coding for an ESP32 is pretty simple: it’s Arduino IDE compatible and you can look up the several examples it comes with, including how to connect it to a phone via BLE.

You can get something working pretty quickly. In my case I wrote a Android app that uses the OsmAnd public API to get directions and just relays it over BLE to the ESP32 connected to the display.

After a day of bad soldering (if you can’t solder well, solder a lot), I had a working prototype:

A 20x4 display showing directions

Disaster Strikes

That’s when everything went south. I saw that with the HD44780 it was possible to create “custom characters”: patterns of pixels that can be displayed in place of a letter in the display, allowing the user to basically create arbitrary shapes and drawings.

In my mind, that meant I could just draw anything I wanted in the display, because I could just cover the whole display in custom characters! Oh such smart! Such innocence!

In my naive slumber, I designed a few custom and very cute screens with that assumption, with custom fonts, custom drawings and overall a weird layout for an alphanumeric display - basically using it as a graphical display instead.

In reality, you are limited to only 8 of such custom characters! My plans quickly crumbled and a frantically searched Kagi for a solution, but I only came across gems like these (I paraphrase):

RandomCuriousPerson: Hi people! Is there any possible way I could have more than 8 custom characters in a HD44780 display?

SeasonedIndustryVeteran: Get fucked and DIE! How could you possibly be so naive as to think you can use more than 8 custom characters? It is a HARD hardware limit and there is NO way around it. Get your dreams crushed, idiot!

Of course, after seeing several demonstrations of such sentiment, I was confronted with the most powerful human motivator: spite. I absolutely had to show these dream-crushing “gurus” that everything is possible and they are wrong by crushing people’s dreams and hopes!

Hope

After much ups and downs and days of intense search, I came across this:

https://github.com/MisterHW/44780HD

It is an absolute masterpiece that basically spells “you can do the impossible” and ends in a cliffhanger that leaves you wondering: can you really do the impossible? Are these the words of someone that has lost their mind? Where did such insight came from? Is this the power of gods? And you get no answers.

To break it down, the article basically indicates that there is the possibility of about three ingenious hacks that allow HD44780 displays to show anything you can dream! Two of them work by rapidly updating the internal memory of the chip while it’s constructing the output image so it instead generates a custom image, and one of them works by very slightly modifying the hardware so you can directly inject custom data.

First Steps

After playing around with the timing versions that work without any hardware modifications, I could not get them to work fast enough, so I turned my eyes to the invasive version that promised infinite power if only you sold your soul.

The problem is, I am bad at hardware. The instructions called for finding a specific trace in the display’s board, cutting it, and soldering a wire in one of the ends. That wire can then supposedly be used to inject custom pixels into the display.

By a strike of luck, I actually found the original author in the fediverse and turns out they are extremely helpful in clarifying how to execute such hardware shenanigans.

So here is how it works:

Image of an HD44780 board with wires attached

See where I labelled “VDD”? That’s the power of the main chip (which is an HD44780 clone) comes in. Right above that line is the “M” line, which is a frame clock output. Above that is the pixel data “D” output going from the main chip to all the other controllers that handle all but a 8x2 region of the display. Below the large VDD line is the “CLK2” signal, which is a pixel clock.

By cutting the “D” line, we make sure the HD44780 is not providing any pixel data to the other controllers on the board. Then, we solder a wire a bit further down the line and inject our own pixels! Of course, we must synchronise that somehow, which we can do by using the “CLK2” line: for each clock cycle there we output one pixel in “D”.

Does that sound like a one-directional SPI? Because it can be! The “CLK2” can be hooked to a SPI “SCLK”, and “D” to a “MISO” output - this enables most micro controllers with a DMA to output pixel data directly from memory to this display!

There is one final step involved, which is making sure the pixel stream is synchronised to the start of each frame (so you start writing on the top-left of the screen every time). This can be done by writing some known data to the HD44780-controlled area of the display and then reading it back from a wire soldered before the “D” cut, so you know where in the data stream you should being writing to match the known data.

Polishing the Software

And after going through the mods and tweaking the SPI driver of my ESP32, writing some code to blit sprites to memory and some design work, I can finally do custom fonts, graphics and icons! Note there is some misdirection, as this does not control a 8x2 area of the display under direct control of the HD44780 - but we can cover half of that using the native custom characteres, leaving only a 4x2 area where we must use the default fonts (or leave it blank as I did).

HD44780 being used as a graphical display


CC-BY-SA pictures yoinked in the making of this post:

https://en.wikipedia.org/wiki/File:HD44780.jpg https://en.wikipedia.org/wiki/File:DTV-LCD-MOD.jpg