Making custom fonts for GLCD library

Update: I’ve been working on a little Qt based tool called glcd-utils which does makes creating fonts and bitmaps on GLCDs a lot easier than the process below. It is open source, but no binaries available or even much documentation. You can visit the Github page here. Otherwise, back to the tutorial below.

Here’s a quick guide on how to make your own custom fonts for my GLCD library, using the free MikroElectronika GLCD Font Creator. You can download this tool here and install it to your computer. You can download this software here:

http://www.mikroe.com/eng/products/view/683/glcd-font-creator/

This free tool was designed for use with MikroElektronika’s line of compilers, but it also works well with my library.

Install the software and start it up

Go to File -> New Font -> Important an Existing System Font

Select a font you would like to convert.

Choose the range of characters you would like converted. e.g just numbers, or alpha numeric numbers, etc.  32 to 127 covers most characters everyone needs to use. Refer to an ASCII table if you need to find out what number refers to which character.

Now click OK and the font should start to get imported in the program. A screen like below should show. You can click on each character see what the character is and how the pixelation will be set. You can also edit the fonts as well if needed to.

Go to File -> Export for GLCD

You should now see a screen like below. Change your font name to something descriptive. I like to put the start and end characters in it, and also the font size which may already pre filled for you. The font size is the dimensions in pixels of the generated font. In this example it is 31 by 27.

Choose X-GLCD Lib (only option for fonts with height over 8 bits) and KS0108 format.

Click on MikroC tab, and then make two edits to the source.

Change the type to “const char”, and add PROGMEM to just before the ‘=’ character.

This code is now ready. So we need to make a new font file, in our application. Here we’ll make a new file in CooCox editor, but you can use whatever method you like to create a new file.

I like to call the filename the same as the font description we made earlier. It will make it easier later when you’re using it. Copy and paste the code you previously generated into this new file.

We now need to add some #ifdef statements to the start and end of the header file. Like above. Make the symbol name nice and descriptive as well. Here we add to the start of the file:

#ifndef TAHOMA_32_TO_127_32X27_H_
#define TAHOMA_32_TO_127_32X27_H_

And then also add to the end of the file:

#endif

Now we’re done, to use the font, include the header file in your source code

#include "Tahoma_32_to_127_31x27.h"

Set your font like this (this is why it I mentioned to call the filename and font array the same name):

glcd_set_font(Tahoma_32_to_127_31x2,31,27,32,127);

Note we need to set the width, height, start char and end char as parameters to the glcd_set_font() function.

Now we’re ready to use it!

12 thoughts to “Making custom fonts for GLCD library”

  1. Thanks for these detailed instructions. But I have a problem that I’m hoping you can help me solve – the MikroEl GLCD Font Creator 1.2.0 software won’t save my work. I’m able to go through the save routine, but it doesn’t actually write the file on my PC. Have you encountered this problem and figured out how to solve it? [This bug is documented in the MicroEl forum, but there’s no solution posted.]

    Thanks!

    1. Hi Shalom.

      Sorry I’m afraid I can’t help you there. I’ve never had this issue with the MikroE software nor do I remember ever trying to save anything. I usually just copy the code and close it down. Thanks.

      Andy

  2. The solution to save your work with the GLCD Font Creator 1.2.0 is to run the application in Xp mode.

    Right click on the app icon:
    1 – then properties,
    2 – then go to tab “compatibility”
    3 – then click “Run this program in the compatibility mode for”
    4 – select “Windows XP SP3”

    Now you can save!

    good luck

    Jerome

  3. I need a larger font and have found one to try before I start having a go at one of my own. Where ever I put the glcd_set_font(Tahoma_32_to_127_31x2,31,27,32,127); line I get an error. Should it go in the loop, setup or elsewhere or should I be adding say a glcd. in front so it becomes:
    glcd.glcd_set_font(Tahoma_32_to_127_31x2,31,27,32,127);

    I am an arduino novice and am finding the code flow hard and any help will be gratefully received.

    Anthony

    P.S. I had a lot of problems getting past a spam filter with my email addresses

    1. Hi Anthony,

      Sorry for the late reply. This library isn’t designed for Arduino and not compatible. Although with some minor changes it probably could be made to work, I wouldn’t recommend doing it if you’re a novice. This code is best used in software like Atmel Studio (if using Atmel AVR chips). Thanks.

  4. Just to let you know the ranges for ASCII characters in glcd_set_font are off, should be:
    Numbers – 46,57
    Alpha (capital) – 46,57
    Took me half an hour to figure out why I was getting garbage on my LCD 😉
    Also there is a typo in the above tutorial in line:
    glcd_set_font(Tahoma_32_to_127_31x2,31,27,32,127);
    Pretty sure it should be glcd_set_font(Tahoma_32_to_127_31x27 or even (…)_27x31,(…)

  5. Thank you for this.

    Had to make a little change because of the Bluetooth App I used but got it working in a few hours.

    I am using it to replace my old LED numbers on my mailbox to something much nicer.

    Awesome

  6. Well, I am compltely stymied.

    I used a TTF font – to create an “export for Mikroelectronica compilters” – C format.

    So the font says it is 32×37..

    that means 32 bits wide – rounding to the nearest that is 4 bytes in a row – by 37 high.

    Now I did get this working – 4*37 id 148… plus the first character in the line which is a width specifier. that’s 149 bytes per character.

    And that worked a treat – indeed it worked a treat for 2 fonts of varying sizes….

    But then I found a weather TTF font – super – I made the characters 32 *37 – the compiler says 32 * 37… the grid shows 32 bits…

    But when I add up all the byes in each line of C output – I should get (32/8=4) * 37 + 1 – which is 149 .

    Sadly and I’ve checked this over and over – I’m getting 161.

    Where on EARTH are the extra 12 bytes coming from?

Leave a Reply

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