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.  Note – that initial tests indicate this also applies to the ILI9341 –  just over £5 from Ebay at the time of writing (Aug 2017) – 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 microC output of the  “Export for GLCD” output, add in 3 bytes at the start which represent the width and height of the font and the offset from 0 for the first ascii character –  and then to change the actual array declaration… i.e. typical start….

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

Note I’ve added in 16,17 and 32 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).

You will see in the home control manual (WORD) available from BitBucket that I’ve standardised on a simple format for controlling several displays – essentially the $ followed by a character and optional arguments.

For example $S sets up the screen…. $C255,0,0 ; sets the colour to red. If the next character is a non-numeric character, the semicolon can be missed. Hence the display can be controlled including lines, rectangles, text and font change in one text message which typically might be sent by MQTT.

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 the latter a go.


28 thoughts on “Silence of the Lambs

  1. I am searching for the defintion which fonts are built in in the latest HC2017. There are 13 numbers to choose from. There is nothing in the .doc.
    What are those Icon sets in the appendix of the doc?
    Can you load another font if necessary?

  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.

  3. Struggling with this…
    Do I have to enable any of the outputs GP 13,14,15,16 before sending {ili_xxxxxxxxxxxx”} commands.

    1. No you don’t touch them – that is handled by the init code….

      You should be using the current version of the software.

  4. 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.

    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. 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. 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. Erm, well that is the only easy place where people can find old posts and I think it probably helps with Google.

      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. Erm yes, well as the site seems to be moving much more quickly I’ll knock it back up a bit. I should do more cross referencing but the blog takes up a LOT of my time…

          1. Right I’ve altered that AND recent posts…. I need a page with links to all posts now…

            1. Thanks. Not quite up to the same standards as Peter’s blog but I enjoy sharing information and it’s a handy place to keep stuff if I need it again. 🙂

Comments are closed.