10 years, 8 months ago.

how can I have big font on GLCD(ILI9320)

Hi all,

I want to have bigger font on graphic LCD(ILI9320)

I'm using a library which have some function to draw line,circle and rectangular .Also have a 8*16 font ,there is no problem with running GLCD. Now I want to have big font on GLCD. I find some code here: http://mbed.org/users/dreschpe/code/TFT_fonts/

but I can't use them anyone can help me? is it necessary to upload my library here?

Really big font: Use GIMP to create each character and export them to .BMP files. Then convert .BMP files to to C code with LCD Assintant (http://en.radzio.dxp.pl/bitmap_converter/). Put the C code to one .H file and copy text to the empty (= memset(picbuff, 0, sizeof(picbuff) ) picture buffer, picbuff[9600];. Then draw the whole TFT screen with this picture buffer.

posted by Compass Developer 02 Sep 2014

2 Answers

10 years, 8 months ago.

I use these font files for my ILI9320 display driver:

http://mbed.org/users/star297/code/HY-1_8TFT_fonts_ST7735/

Import the Font library to your program and add it as a Library (not program) then add the fonts you want to use by using the #include, something like below that includes all the fonts, the last two fonts are a bit different and quite interesting. The program below may not work for you as it depends on you your display and library, but is a typical example how to construct the initial part of your program.

Example using Font files

#include "mbed.h"

#include "SPI_TFT_ILI9320.h" // your display header file may be different here

#include "Arial8x8.h"
#include "Arial9x9.h"
#include "Arial11x11.h"
#include "Arial12x12.h"
#include "Arial24x23i.h"
#include "Arial28x28.h"
#include "Neu42x35.h"
#include "SCProSB31x55.h"


SPI_TFT TFT(p5, p6, p7, p8,"TFT");  // TFT -> mosi, miso, sclk, cs    your display device set up may be different here


int main()
{
  TFT.cls();       //clear screen
 
  TFT.set_font((unsigned char*)Arial24x23i);   // set font from the #include list above that you want to print
  TFT.foreground(White);                       //set text colour
  TFT.locate(10,20);                           // set screen position where to print
  TFT.printf("Some Text here...");

     TFT.cls();       //clear the screen again 

    TFT.background(Red);  // set the text display background to red this time (default is black)
    TFT.set_font((unsigned char*)Arial12x12); // set a different font    
    TFT.locate(60,70);  // set the text screen position where you want the text to print on your display 
    TFT.printf(" Print some more text");
  
}

Thanks,

How did you used these code? I mean how these codes implement in main program? did you made any library for using these fonts?

posted by mohsen nops 14 Mar 2014

dear @Paul, can I ask you to upload me the SPI_TFT_ILI9320.h and SPI_TFT_ILI9320.c because I'm using Keil compiler

posted by mohsen nops 15 Mar 2014

here is the link for the code I use:

http://mbed.org/users/frankvnk/code/SPI_TFT_ILI9320/#630b4da97968

posted by Paul Staron 15 Mar 2014
10 years, 8 months ago.

This code draws large digits to ili9341 controlled tft. The original code was written in Java and i reused it a lot when converting to C++.

http://www.youtube.com/watch?v=c15O3an6wFw

numberarea.h

#ifndef NUMBERAREA_H
#define NUMBERAREA_H
#include "mbed.h"

class NumSize
    {
    public:
    NumSize(int width, int height);
        int _width, _height;
        
        int getWidth();
        int getHeight();
        int getHalfHeight();
        int getHalfWidth();
        int getQuarterHeight();
        int getQuarterWidth();
        int getLineWidth();
    };

class NumberArea
{
public:
    int _width, _height;
    int _maxNumCount;
    NumSize _numSize;
    int _x, _y;
    NumberArea(int x, int y, int width, int height, int maxNumCount);
    void drawNumbers(int8_t numbers[], bool negative);    
};



#endif

numberarea.cpp

#include "NumberArea.h"
#include "SPI_TFT_ILI9341.h"

SPI_TFT_ILI9341 tft(P1_22, P1_21, P1_20, P1_23, P0_20, P0_21,"TFT"); // mosi, miso, sclk, cs, reset, dc
#define BACKGROUND   White 
#define INK     Black
NumSize::NumSize(int width, int height)
{
    _width = width;
    _height = height;
}

int NumSize::getWidth()
{
    return _width;
}
int NumSize::getHeight()
{
    return _height;
}
int NumSize::getHalfHeight()
{
    return _height / 2;
}
int NumSize::getHalfWidth()
{
    return _width / 2;
}
int NumSize::getQuarterHeight()
{
    return _height / 4;
}
int NumSize::getQuarterWidth()
{
    return _width / 4;
}
int NumSize::getLineWidth()
{
    return _width / 4;
}

NumberArea::NumberArea(int x, int y, int width, int height, int maxNumCount)
    : _numSize(0, 0)
{
    _x = x;
    _y = y;
    _width = width;
    _height = height;
    _maxNumCount = maxNumCount;

    // Figure out the screen aspect ratio.
    // Numbers are always 1:2 (width:height)
    int numWidth = width / maxNumCount;
    if(numWidth*2>_height) {
        numWidth = _height/2;
    }
    _numSize._width=numWidth;
    _numSize._height= numWidth*2;
    
    tft.set_orientation(3);//320*240, spi connector is left
    tft.background(BACKGROUND);
}

void NumberArea::drawNumbers(int8_t numbers[], bool negative)
{
    int num = 0;
    int xinc = _x + _width - _numSize.getWidth();
    
    if (negative) {
        tft.background(Cyan);
    } else {
        tft.background(BACKGROUND);
    }
    tft.cls();
    for(int i = 0; i < _maxNumCount; i++) {
        num = numbers[i];
        if(num==0) {
            tft.fillrect(xinc, _y, xinc + _numSize.getWidth()- _numSize.getLineWidth(), _y + _numSize.getHeight(), INK);
            tft.fillrect(xinc+_numSize.getLineWidth(), _y+_numSize.getLineWidth(), xinc + _numSize.getWidth() - 2*_numSize.getLineWidth(),
                          _y + _numSize.getHeight() - _numSize.getLineWidth(), BACKGROUND);
        }
        if(num==1) {
            tft.fillrect(xinc+_numSize.getHalfWidth(), _y, xinc+_numSize.getHalfWidth() + _numSize.getQuarterWidth(), _y + _numSize.getHeight(), INK);
        }
        if(num==2) {
            tft.fillrect(xinc, _y, xinc + _numSize.getWidth()- _numSize.getLineWidth(),_y+_numSize.getLineWidth(), INK);
            tft.fillrect(xinc + _numSize.getWidth()- 2*_numSize.getLineWidth(), _y+_numSize.getLineWidth(),
                          xinc + _numSize.getWidth()-_numSize.getLineWidth(), _y+_numSize.getHalfHeight(), INK);
            tft.fillrect(xinc, _y+_numSize.getHalfHeight(), xinc + _numSize.getWidth()- _numSize.getLineWidth(),
                          _y+_numSize.getHalfHeight()+_numSize.getLineWidth(), INK);
            tft.fillrect(xinc, _y+_numSize.getHalfHeight()+_numSize.getLineWidth(),
                          xinc + _numSize.getLineWidth(), _y+_numSize.getHeight(), INK);
            tft.fillrect(xinc + _numSize.getLineWidth(), _y+_numSize.getHeight()- _numSize.getLineWidth(),
                          xinc + _numSize.getWidth()- _numSize.getLineWidth(), _y+_numSize.getHeight(), INK);
        }
        if(num==3) {
            tft.fillrect(xinc, _y, xinc + _numSize.getWidth()- _numSize.getLineWidth(),_y+_numSize.getLineWidth(), INK);
            tft.fillrect(xinc + _numSize.getWidth()- 2*_numSize.getLineWidth(), _y+_numSize.getLineWidth(),
                          xinc + _numSize.getWidth() - _numSize.getLineWidth() , _y+_numSize.getHeight(), INK);
            tft.fillrect(xinc, _y+_numSize.getHalfHeight(), xinc + _numSize.getWidth()- _numSize.getLineWidth(),
                          _y+_numSize.getHalfHeight()+_numSize.getLineWidth(), INK);
            tft.fillrect(xinc, _y+_numSize.getHeight() - _numSize.getLineWidth(), xinc + _numSize.getWidth()- _numSize.getLineWidth(),
                          _y+_numSize.getHeight(), INK);
        }
        if(num==4) {
            tft.fillrect(xinc + _numSize.getWidth()- 2*_numSize.getLineWidth(), _y+_numSize.getLineWidth(),
                          xinc + _numSize.getWidth() - _numSize.getLineWidth() , _y+_numSize.getHeight(), INK);
            tft.fillrect(xinc, _y+_numSize.getHalfHeight(), xinc + _numSize.getWidth()- _numSize.getLineWidth(),
                          _y+_numSize.getHalfHeight()+_numSize.getLineWidth(), INK);
            tft.fillrect(xinc, _y, xinc + _numSize.getLineWidth(),
                          _y+_numSize.getHalfHeight(), INK);
        }
        if(num==5) {
            tft.fillrect(xinc, _y, xinc + _numSize.getWidth()- _numSize.getLineWidth(),_y+_numSize.getLineWidth(), INK);
            tft.fillrect(xinc, _y +_numSize.getLineWidth(), xinc + _numSize.getLineWidth(),_y+_numSize.getHalfHeight(), INK);
            tft.fillrect(xinc, _y+_numSize.getHalfHeight(), xinc + _numSize.getWidth()- _numSize.getLineWidth(),
                          _y+_numSize.getHalfHeight()+_numSize.getLineWidth(), INK);
            tft.fillrect(xinc + _numSize.getWidth()- 2*_numSize.getLineWidth(), _y+_numSize.getHalfHeight(), xinc + _numSize.getWidth()- _numSize.getLineWidth(),
                          _y+_numSize.getHeight(), INK);
            tft.fillrect(xinc, _y+_numSize.getHeight() - _numSize.getLineWidth(), xinc + _numSize.getWidth()- _numSize.getLineWidth(),
                          _y+_numSize.getHeight(), INK);
        }
        if(num==6) {
            tft.fillrect(xinc, _y, xinc + _numSize.getWidth()- _numSize.getLineWidth(),_y+_numSize.getLineWidth(), INK);
            tft.fillrect(xinc , _y+_numSize.getLineWidth(),
                          xinc + _numSize.getLineWidth() , _y+_numSize.getHeight(), INK);
            tft.fillrect(xinc + _numSize.getLineWidth(), _y+_numSize.getHalfHeight(), xinc + _numSize.getWidth()- _numSize.getLineWidth(),
                          _y+_numSize.getHalfHeight()+_numSize.getLineWidth(), INK);
            tft.fillrect(xinc, _y+_numSize.getHeight() - _numSize.getLineWidth(), xinc + _numSize.getWidth()- _numSize.getLineWidth(),
                          _y+_numSize.getHeight(), INK);
            tft.fillrect(xinc + _numSize.getWidth()- 2*_numSize.getLineWidth(), _y+_numSize.getHalfHeight()+_numSize.getLineWidth(),
                          xinc + _numSize.getWidth()- _numSize.getLineWidth(), _y+_numSize.getHeight(), INK);
        }
        if(num==7) {
            tft.fillrect(xinc, _y, xinc + _numSize.getWidth()- _numSize.getLineWidth(),_y+_numSize.getLineWidth(), INK);
            tft.fillrect(xinc+_numSize.getWidth()- 2*_numSize.getLineWidth(), _y + _numSize.getLineWidth(),
                          xinc+_numSize.getWidth()- _numSize.getLineWidth(), _y + _numSize.getHeight(), INK);
        }
        if(num==8) {
            tft.fillrect(xinc, _y, xinc + _numSize.getWidth()- _numSize.getLineWidth(),_y+_numSize.getLineWidth(), INK);//top line
            tft.fillrect(xinc + _numSize.getWidth()- 2*_numSize.getLineWidth(), _y+_numSize.getLineWidth(), //right line
                          xinc + _numSize.getWidth() - _numSize.getLineWidth() , _y+_numSize.getHeight(), INK);
            tft.fillrect(xinc, _y+_numSize.getHalfHeight(), xinc + _numSize.getWidth()- _numSize.getLineWidth(),//middle line
                          _y+_numSize.getHalfHeight()+_numSize.getLineWidth(), INK);
            tft.fillrect(xinc, _y+_numSize.getHeight() - _numSize.getLineWidth(), xinc + _numSize.getWidth()- _numSize.getLineWidth(),
                          _y+_numSize.getHeight(), INK); //bottom line
            tft.fillrect(xinc, _y + _numSize.getLineWidth(),// left line
                          xinc + _numSize.getLineWidth(), _y+_numSize.getHeight() - _numSize.getLineWidth(), INK);
        }
        if(num==9) {
            tft.fillrect(xinc, _y, xinc + _numSize.getWidth()- _numSize.getLineWidth(),_y+_numSize.getLineWidth(), INK);//top line
            tft.fillrect(xinc + _numSize.getWidth()- 2*_numSize.getLineWidth(), _y+_numSize.getLineWidth(), //right line
                          xinc + _numSize.getWidth() - _numSize.getLineWidth() , _y+_numSize.getHeight(), INK);
            tft.fillrect(xinc, _y+_numSize.getHalfHeight(), xinc + _numSize.getWidth()- _numSize.getLineWidth(), //middle line
                          _y+_numSize.getHalfHeight()+_numSize.getLineWidth(), INK);
            tft.fillrect(xinc, _y+_numSize.getHeight() - _numSize.getLineWidth(), xinc + _numSize.getWidth()- _numSize.getLineWidth(),
                          _y+_numSize.getHeight(), INK); // botton line
            tft.fillrect(xinc, _y + _numSize.getLineWidth(), //left line
                          xinc + _numSize.getLineWidth(), _y + _numSize.getHalfHeight(), INK);
        }
        xinc -= _numSize.getWidth();
    }
}

Eero this looks interesting, can you produce a lib on Mbed?

posted by Paul Staron 15 Mar 2014

You have to modify tft connection, orientation and maybe other things, so in the compiler create a new library and copy paste this code.

posted by Compass Developer 15 Mar 2014