Silence of the Lambs

I’ve spent WAY too many hours working on ILI9340 display updates for my ESP8266  kitchen sink C code but at least now I'm getting somewhere - that is - fast, easy serial or MQTT access to the display with multiple fonts. Display I got sick of trying to find decent fonts in bitmap mode (most of them look like something out of the 1990s) and decided the only way was to go GCLD – which is a relatively simple format with the advantage that there is a free Windows convertor/editor which takes in any old TTF font – of which there are millions – and converts them. Little did I know how many hours I'd need to put into making it work.


Well, getting my code to parse the data and put lines of characters up in that format took me a lot longer than I expected.

You see the results above of the work I’ve done. The little 32-pixel high displays are a way nicer colour than this photo depicts and I can get 3 perfectly readable lines with the Python code.

In the case of the bigger display which has a WEMOS D1 glued to it’s underside and uses my normal home control C code (which is on Bitbucket),  now I’ve added an extension to the high speed VT100 terminal part of the code to introduce landscape and portrait not-so-high speed text and rectangles etc… It’s very nice and after a lot of head-scratching is now fast enough for general use.

Anyway the point of this effort was to be able to make really cheap WIFI displays (the whole lot comes to around a fiver or so) to stick all over the place. I’ve still never found nice bezels for those 320*240 displays – if anyone has a source do let me know.

So right now it is all working – I already have some fonts  in the FLASH and I have totally abandoning support for the old ESP-01 boards with 512K of Flash as I need the FLASH space for the extra fonts. The GLCD Font Creator software is completely free, runs under Windows (I'm using it on Windows 10) and can output C code which I've then dropped straight into my project. The only change I've made is to take the micriC output of the  "Export for GLCD" output, add in 2 bytes at the start which represent the width and height of the font and change the actual array declaration... i.e. typical start....

static const uint8_t IRA  calibri16x17[] = {static const uint8_t IRA  calibri16x17[] = { 16,17,
0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00... etc

Note I've added in 16,17 at the start. The format of these files incidentally is relatively simple - one long line for each character, the first byte is the width should you choose to use it (usually yes)... then the vertical bits DOWN rounded up to the nearest byte, repeated for every column in a character (exact).

The image you see at the top with the weather icons - that output can be realised in my code from serial or as MQTT as simply as this..

{ili_gcldstring:40,10,6,0,"Control panel"}
{ili_gcldstring:30,50,5,0,"Testing 1 2 3"}
{ili_gcldstring:30,80,4,0,"This is the smaller of the fonts\nand I think it will work pretty well.\nI have set a 200 character limit\nfor one string and that works."}

So assuming the board is in terminal mode- the first line clears the screen completely, second line rotates it to landscape mode, then the text colour is sent and then text is sent - the format is as such:

ili_gcldstring needs the following parameters...

x starting position
y starting position
font - (currently 0-5 as I fill out the FLASH with useful stuff like the weather font (3).
0 OR 1  - 0 means use the spacing info in the font, 1 means use the font width which is wasteful of space but is good for clocks etc (monospacing).

The only formatting I've added to strings is to handle \n for carriage return which takes the cursor down one line and to the starting X position. The line buffer is 200 characters max.

What is interesting to C coders – I only now, after using the Espressif SDK (currently 2.1.0) for what seems like years, discovered a #define that shoves normal fixed strings into Flash memory – so that got me a bit of RAM back – the other thing I’m doing is accessing the font material from FLASH using a function to get 8 bits out (you can’t read 8 bits from Flash – you have to read 32 bits) and I’d been having trouble with the odd read setup crashing boards – WELL – I found another trick – in the #defines for IFA and IRA you can add in a pragma that forces all your arrays onto 32 bit boundaries!!!

On other subjects: I have a new twin A/D converter board (I2c) from China to add to my code and a current/voltage monitor but having made a success of my little i2c Nano peripheral, I'm thinking it might make sense to make a motherboard for that Nano which includes divider resistors to make that A/D actually useful in the outside world (i.e. voltage above 1.1v).  I was meaning to write here to gripe as SEEED have a special offer on PCBs but refuse to be drawn into a conversation about postage - and you can't get to that without putting in a complete project - only to find out that your $4.99 special offer PCB costs many times more than that. I note that ITEAD do something similar but with quite reasonable postage. More on that when I give them a go.


27 thoughts on “Silence of the Lambs

    1. Thank you Chris for the feedback - well, the service provider was half-convinced it was the size of my site - images etc, I didn't agree - but what I did do was reduce the number of blog entries you see on the HOME PAGE from 10 to 2. This made no difference whatsoever. So they offered to move me to a quieter server and after some hassle with emails disappearing due to the changeover, all does INDEED seem better - not only page loading but admin which was getting to be awful (and is why I didn't agree it was page content as the admin area is completely different). Long may it last.

      1. Pete, good to hear the hassle you went through made the site faster. Please consider bumping the number of blog entries up to 4-5 at least. Sometimes you post in rapid succession and it would be nice to see more than the last 2 posts.

    1. Thank you Ion - I would love to host my own site but I have several blogs and I'm not sure I have the time for the maintenance/support angle of that.

      I was liking that link - nice and inexpensive - until I saw how much they want to add cpanel? I get that thrown in!


    1. Yes thanks - there is also this commercial font with all the weather symbols

      And here's another way (free for non-commercial) - some of the fonts out there claim to have fantastic weather items in them and with CSS and on web pages they work great but most often I can never actually find the imagery in the fonts..

      However, take the above TTF as an example - import it into GLCD font creator - pulling in characters 32 to 90 at whatever size you like... and they work - not tested other than checking on my PC but they look good!

  1. Ubiquitous displays! I like!! The ITEADs are nice but not really cheap (when you want a reasonable size). So your approach looks fantastic. Alas, I can't find "ILI8340" anywhere. There are neat ILI9341, ILI9327 and ILI9325 from China.
    Will they work, too?

    1. Sorry - fixed - the driver software is 9340.

      This is the exact models I have.. looking at the photos - sadly the advert does not specify the chip - and that price is way too expensive.

      I am assuming this is the same - but the connector side that isn't used has one more connector...

      This all stems from my original VT100 terminal project here..

      which used these - which it seems are no longer available

      According to THIS article - it seems they both work with the same drivers.

  2. I somehow missed the {ili_set:1} command... Suddenly it all comes to life!!
    I have generated some code for my CNC machine and routed out a small pocket in a piece of 12mm plywood to house my 2.4 display. A back panel to hold it in and a coat of varnish.... look good. I have ordered some micro usb sockets and will try to set one into the frame to provide 5V.

Leave a Reply

Your email address will not be published. Required fields are marked *