Making Fonts for a Clock

Okay, so this is an area I've had some luck in before (I created a few bitmaps and things like that for a previous project for use with a touchscreen GLCD), but I am tearing my hair out this time. All I want, is to make a font for the ASCII characters 48-58 (i.e.: 0 1 2 3 4 5 6 7 8 9 : ) so that I can use a large font for display on the GLCD as a clock face. I've generated a code using MikroElektronika GLCD Font Creator, which I then modified to work with Arduino (i.e. changing the precursor information to reflect uint8_t, #include <avr/pgmspace.h>, and storing in PROGMEM) as well as added the code that lists the font height, width, starting point, and length, as I've seen with all other fonts and tutorials that I've been able to find. I've been following, generally, the instructions here for creating fonts, and it has worked out for me so far, but I just cannot get this font to work. I have managed to get it to display on the screen, but the characters just appear as what appears to be static in the space they should occupy. Any ideas? I've attached ClockFont.c, the font file I've created. I wanted to add it as code to the post, but it's far too long.

ClockFont.c (43.1 KB)

Hello,

I'm not sure if that is the problem, but the array size is not 7271 but 7275. Not sure how you managed to compile this without an error :S

Also it is not necessary to manually write the size of the array, you can just do

uint8_t ClockFont[] PROGMEM =

Hassurunous:
I have managed to get it to display on the screen, but the characters just appear as what appears to be static in the space they should occupy.

The "static" (a.k.a. "snow") means that the code is picking up random data from somewhere. When you use the font do you subtract '0' from the character code so it uses the 0th character in the table for the '0'character?

The issue is going to be with the data format.
There is no standard for how embedded font data is stored so the data format needed
much match what the library is expecting.
Some expect the data store as bytes and some as 16 or 32 bit "words".
Some expect the pixel data sored horizontally by rows and some vertically by columns.
Some map pixels to bytes msb to lsb and some lsb to msb.
Some font data formats have a header before the font data and some don't,
Some font data formats support variable character widths and have encoded with information,
which also can be encoded in different ways.
Complicating matters is many of the font tools also allow saving the data in multiple ways
so you must make sure to save the data in the proper format for the library being used.

What library are you using?
Does your font file look like the other font files that came with the library?

My library (openGLCD) comes with several fonts like you are wanting, and
also includes a java based font tool to create new fonts but it may not support
the glcd module you are using.

--- bill

Fixed the issue with the wrong size listed on the array. Still not working right, but one step closer!

The static isn't random data, I think, as it's always the same for each character. It just appears that the data for the characters is not in the correct place, if that makes sense. The number of pixels appears to be correct, but their configuration is totally wrong. I ran into a similar issue a few months back making my bitmaps when I didn't declare their size properly in the code, but once I fixed that they snapped into the proper configuration.

I forgot to list the code that I'm using to test the font! Doh! Here it is:

//Touchscreen libraries
#include <UTFT.h>
#include <UTouch.h>
#include <avr/pgmspace.h>

// Declare the touchscreen and parameters
UTFT myGLCD(SSD1289,38,39,40,41);
UTouch myTouch(6,5,4,3,2);

extern uint8_t ClockFont[];

void setup()
{
    //GLCD activation
  myGLCD.InitLCD(LANDSCAPE);
  myGLCD.clrScr();
  myGLCD.fillScr(255, 255, 255);

  //Touch screen activation
  myTouch.InitTouch(LANDSCAPE);
  myTouch.setPrecision(PREC_MEDIUM);
  
  myGLCD.setFont(ClockFont);
  myGLCD.setColor(0, 0, 0);
  myGLCD.setBackColor(255, 255, 255);
  myGLCD.print("0", 50, 100);
}

void loop()
{
}

There we go. Sorry about that. Now you can see the libraries that I'm using and everything. The screen I'm using is an ITEAD screen with a Mega 2560 board. At this point, I'm just trying to get the font working. I followed the instructions here for making font files, combined with the program I found from MikroElektronika to pull system fonts so I wouldn't have to start from scratch. I suppose I could just create the fonts from scratch, but I need to numbers to be extremely large (64 pixels wide and as tall as I can get them without looking bad) so I was hoping to use the MikroElektronika program to aid.

guix:
Hello,

I'm not sure if that is the problem, but the array size is not 7271 but 7275. Not sure how you managed to compile this without an error :S

It doesn't compile:

In file included from sketch_nov12a.ino:1:
clock.c:18: error: too many initializers for ‘uint8_t [7271]’

So we aren't going to get snow if it doesn't compile, eh?

I updated the file on my end and even before I did it compiled though the arduino ide without any errors, which struck me as odd, too, once it was pointed out. I've since changed the array size (I've changed that line to uint8_t ClockFont[] PROGMEM) and it still gives the exact same configuration on screen, which is also odd.

  myGLCD.setFont(ClockFont);

Does myGLCD expect the font in PROGMEM?

I've tried, and indeed, your font is broken.

Something weird: each character of your font takes 661 bytes, that is 5288 bits. But that should be 8660 = 5160. The closest is 8860 = 5280. The first byte of each character looks strange, so I tried removing it. No great changes, still a mess, so I tried to invert width and height, like so:

uint8_t ClockFont[] PROGMEM= {
        88, 60, '0', 11,

Now it appear to draw something that looks like parts of characters, like if it was rotated by 90°.

So as bperrybap said, most likely a problem with your converter that doesn't output the correct format used by UTFT.

You can generate a working font array for UTFT, with The Dot Factory, it works almost "out of the box", here is two fonts I've just generated:

http://pastebin.com/raw.php?i=buv9ZZvu
http://pastebin.com/raw.php?i=sNJQQEmM

There are some options for the generation in The Dot Factory (the little wrench near the Generate button), that you may need to modify. One important setting is to set Height and Width to be Fixed. Also the dimensions are not always exactly the ones reported, so what I do is, I copy the first character in a new document in NP++, see how much lines it takes and that will be the height of the font. The width is the number of bytes in one line, * 8. If you need help with it, just tell me :wink:

I tried out The Dot Factory and the results are brilliant! This is why I love this community! Thank you so much guix! That makes everything I've been trying to do so much simpler!