Changing fonts with 3.5" LCD TFT (Driver IC: ILI9481)

Hey folks, I have recently bought a cloned 3.5" LCD screen for my Arduino project. I got it off for only $8, so I kinda expected that it might be a little challenging to figure out the "How-Tos" on everything related to this shield.

I have been scouring the internet looking for ways to render stuff on the screen, and eventually, I found that MCUFriend is able to do that. But one thing that I am currently stuck with is changing the font type. The current MCUFriend library only allows me to change the font size on my display and not the type. I practically copied and paste the graphics test example and modified it from there. Also, I have considered using the Adafruit TFT & GFX library, but when I looked at the tutorial, I noticed something different. There is supposed to be a LCD_CD pin (Command/Data), but on my shield, I do not see it. Everything else seems the same, but on my shield, there is a pin called "LCD_RS". What is the function of the LCD_RS pin for?

(Above) This is the shield that I have. I believe some of you with a little more experience might be able to help me.

(Above) This is what I would like to achieve on my home automation project. You can see from the LCD that the fonts are just really small. Setting the font size to '2' makes it very ugly so that is the reason why I want to explore using different font types.

First off. Shields are designed to plug into the sockets of an Arduino. Use angle male header strip to access the empty sockets on a Mega. You only need a few trailing wires to the external electronics on your breadboard.

If you want to use different fonts, look at the examples in the Adafruit_GFX tutorial.
It is just a question of including the specific font header file and using tft.setFont()


Hi guys, I've managed to solve the issue on my own. I have tried to go with the Adafruit_TFTLCD library, but somehow, it's just not working. So, I decided to challenge myself to go hack the Adafruit_GFX as well as the MCUFRIEND_kbv library. As it turns out, it's not too complicated, so I will share what I have done in case someone has a similar challenge.

  1. Making setFont public and virtual.
virtual void setFont(const GFXfont *f = NULL);
GFXfont *gfxFont;

The very first thing I did was to make the setFont method public and virtual, that way, I can have the option to override it in the child class - MCUFRIEND_kbv class.

  1. Adding setFont to MCUFriend_kbv.h & .cpp
void setFont(const GFXfont *f = NULL);
void MCUFRIEND_kbv::setFont(const GFXfont *f) {
    if(f) {            // Font struct pointer passed in?
        if(!Adafruit_GFX::gfxFont) { // And no current font struct?
            // Switching from classic to new font behavior.
            // Move cursor pos down 6 pixels so it's on baseline.
            cursor_y += 6;
    } else if(Adafruit_GFX::gfxFont) { // NULL passed.  Current font struct defined?
        // Switching from new to classic font behavior.
        // Move cursor pos up 6 pixels so it's at top-left of char.
        cursor_y -= 6;
    Adafruit_GFX::gfxFont = (GFXfont *)f;
  1. Next, we will replace the setFont method in the UTFTGLUE.h class with the following code:
void setFontAndSize(uint8_t size, const GFXfont *f) {
 MCUFRIEND_kbv::setTextSize(_fontsize = size);

Here's how I am using it:

myGLCD.setFontAndSize(1, &FreeSans9pt7b);    // Using a custom font type and using 100%

myGLCD.setFontAndSize(1, NULL);    // Using the default font type and using 100%

What it looks like on the actual display:

Additional example:

myGLCD.setFontAndSize(2, NULL);    // Using the default font type but enlarge to 200%

Once you have made the above changes, you can now easily set the Font Type you want to use as well as setting the font size. Personally, I think the font size setting made available through UTFTGLUE.h is really more like the 1x, 2x, 3x when you set the size=2 for example. If you want to really maintain a good font display, I would recommend using the relevant Font/[fontnamefile.h] in the Adafruit_GFX library.

I'll be adding in some additional fonts to test them out later.

P.S. I am not an expert, but I find that I can manage C++ pretty alright. So if anything that I shared seems wrong, please pardon me. My goal is always to just get things to work first. We can always fine tune the coding later. :slight_smile:

Both Adafruit_TFTLCD and MCUFRIEND_kbv use GFX. And hence setFont() e.g. with FreeFonts.

Read the comments in UTFTGLUE. You comment/uncomment a define to use UTFT fonts.

Please do not hack libraries. Compose your questions carefully in your own language. Then use Google Translate to produce the English message.
Someone will probably show you what to do.