3

I get a compile error when I try to set a different font in Adafruit GFX on a TFT display on my Arduino Uno.

I'm testing a new TFT shield for Arduino equipped with an ILI9341 by using the Adafuit GFX libraries and examples. The test program supplied with the library works fine out of the box displaying text and all kind of drawings on the screen.

However, the standard font built into the Adafruit GFX library is "blocky" to save memory space. They do provide other fonts, but I get an error when I try to invoke them.

The segment of code that throws the compile error is this one:

unsigned long testText1() {
  tft.setFont();    // When I remove this line the sketch compiles OK
  tft.fillScreen(BLACK);
  tft.setCursor(0, 50);
  tft.setTextColor(RED);
  tft.setTextSize(13);
  tft.println("1234");
}

When compiling I get this error:

"error: ‘class Adafruit_ILI9341_8bit_AS’ has no member named ‘setFont’"

According to Adafruit's GFX manual, the setFont() procedure allows to define a new font or revert to the standard one.

I examined the libraries and nowhere could I find a procedure to select a font, yet the example has declarations like these below, so changing fonts should be possible:

#include <Adafruit_GFX_AS.h>
#include <Adafruit_ILI9341_8bit_AS.h>
#include <Font16.h>
// #include <Font32.h>
// #include <Font64.h>
// #include <Font72.h>
#include <Font7s.h>
#include <Load_fonts.h>

I would like to load the 7segment font with:

tft.setFont(&Font7s);

Does anybody have experience to share loading these fonts?

1

Looking further into documentation on the Adafruit website they indicate that indeed, their GFX library published on GitHub does not handle different fornts.

Case closed :-)

1

Newer versions of the library CAN use fonts.

#include <Fonts/FreeSerifBold12pt7b.h>

and then...

matrix.setFont(&FreeSerifBold12pt7b);

Whether they work or not, I dunno. Case closed, lol!

1

Tested on Windows, with newest libraries Adafruit-GFX and Adafruit_PCD8544 (Nokia5110 LCD connected to Arduino Nano).

#include <Fonts/FreeSerifBold12pt7b.h>

and then

matrix.setFont(&FreeSerifBold12pt7b);

Then there is one very important difference how to use function drawChar(...). Coordinates of character (x,y) begins in left-bottom corner of character instead of top-left corner so this will not work (you will see only about 1 px of character):

matrix.drawChar(0,0,'1', 1, 0, 6),

Use this to show all pixels of character:

matrix.drawChar(20,20,'1', 1, 0, 6),

Full manual for using fonts here: Adafruit GFX Graphics Library - Using Fonts

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.