Error MyFont10.h with TFT_eSPI

Hello,

I have a lolin D32 pro with ILI9341.

I'd like to print characters with an extended ascii font . I used with success MyFont10.h

#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>

// The custom font files attached to this sketch must be included
// They only occupy memory if the sketch uses them.
#include "MyFont09.h"
#include "MyFont10.h"
#include "MyFont12.h"

// Easily remembered names for the fonts
#define MYFONT9  &myFont9pt8b
#define MYFONT10 &myFont10pt8b
#define MYFONT12 &myFont12pt8b

...

tft.setAttribute(UTF8_ENABLE , true);
tft.setAttribute(CP437_ENABLE, true);
 tft.setFont(MYFONT10);

It works fine with this library.

Now I'd like to use Bodmer Library TFT_eSPI.h with the example

I succeed to use the custom fonts and free fonts for example CF_OL24 &Orbitron_Light_24

But I tried to add MyFont10.h but I have an error message while compiling (MyFont10.h:4562:1: error: stray '' in program everywhere).

I modified : User Customs Fonts. h by adding #include <Fonts/Custom/MyFont10.h>

then add in my program : #define MYFONT10 &myFont10pt8b

tft.setFreeFont(MYFONT1O);

It's not working and I don't know what I'm missing.

#include <TJpg_Decoder.h>

// Include SD
#define FS_NO_GLOBALS
#include <FS.h>
#ifdef ESP32
  #include "SPIFFS.h" // ESP32 only
#endif

//#define SD_CS   4

#define MYFONT10 &myFont10pt8b

// Include the TFT library https://github.com/Bodmer/TFT_eSPI
#include "SPI.h"
#include <TFT_eSPI.h>              // Hardware-specific library
TFT_eSPI tft = TFT_eSPI();         // Invoke custom library

...

tft.begin();
  tft.setTextColor(0xFFFF, 0x0000);
  tft.fillScreen(TFT_BLACK);
tft.setFreeFont(MYFONT10);
tft.print("Test");

Thanks for your help.

error compiling.png

What format is your "MyFont10" ?

Attach the MyFont10.h file
Then we can identify the format.

TFT_eSPI will display FreeFonts e.g. from Adafruit.
You can generate a FreeFont from your PC via the SQUIX website http://oleddisplay.squix.ch/

David.

Sorry, it should have been attached to my first message.

MyFont10.h (35.7 KB)

I can't reproduce the error.

When you encounter an error you'll see a button on the right side of the orange bar in the Arduino IDE "Copy error messages" (or the icon that looks like two pieces of paper in the Arduino Web Editor). Click that button. Paste the error in a reply here using code tags.

If the text exceeds the forum's 9000 character limit, save it to a .txt file and post it as an attachment. If you click the "Reply" button here, you will see an "Attachments and other settings" link.

You mean the font is working with your program?

What file have you changed ?

Here the full Error Message.

Thanks

Full Error Message.pdf (1.89 MB)

const GFXfont myFont10pt8b PROGMEM = {
  (uint8_t  *)myFont10pt8bBitmaps,
  (GFXglyph *)myFont10pt8bGlyphs,
  0x20, 0xFF, 23 };

// Approx. 5561 bytes

That is a regular FreeFont. TFT_eSPI library will display it fine.

From TFT_eSPI.h

#ifdef LOAD_GFXFF
           setFreeFont(const GFXfont *f = NULL),
           setTextFont(uint8_t font),
#else
           setFreeFont(uint8_t font),
           setTextFont(uint8_t font),
#endif

So you would

...
#include "myFont10.h"
           ...
           tft.setFreeFont(&myFont10pt8b);
           tft.print("Hello World");
           ...

I really don't like the idea of "Font by index number" but hey-ho, that is how TFT_eSPI works.
If you don't have LOAD_GFXFF

David.

Edit. Removed the setFreeFont( 10 ) example

booby75:
You mean the font is working with your program?

I wrote a minimal sketch that #includes the MyFont10.h file you provided in your last reply:

#include <Adafruit_GFX.h>
#include "MyFont10.h"
void setup(){}
void loop(){}

and it compiles without any errors.

booby75:
What file have you changed ?

I didn't make any changes to the MyFont10.h file you provided in your last reply.

booby75:
Here the full Error Message.

Did you forget to post it?

OK, I see you posted it now. But please don't post errors as PDF files. Some forum members can't or won't download these files. Just use a text editor and save as a .txt file. If you don't have a text editor, get one! This is an essential tool for every programmer. There are many excellent choices of free open source text editors.

It looks like your MyFont10.h is the source of a web page of that file, thus the errors. Please replace the MyFont10.h on your computer with the one you attached in your previous forum reply. That should fix the error.

And do you change
User_Custom_Fonts.h ?

User_Custom_Fonts.h (1.71 KB)

Is that question directed at me or at @david_prentice?

Your Original Post seems to be doing everything about right.
I tend to put local Font into a local sketch tab.

I will try your Font later.

David.

Your Font works fine as a local tab.

I copied FreeSevenSegNumFontPlusPlus.h to Fonts/Custom

and added this to User_Custom_Fonts.h

#include <Fonts/Custom/FreeSevenSegNumFontPlusPlus.h>     //

And now I can use this Font in any sketch without a specific include

e.g.

     tft.setFreeFont(&FreeSevenSegNumFontPlusPlus);
     tft.println("12.34");
     tft.println("27:01:20");

Please ignore my example with an index number i.e. tft.setFreeFont(10);
I am not sure how to access a Custom font by index.

David.

FreeSevenSegNumFontPlusPlus.h (10 KB)

In fact,

I forgot to add #include <Adafruit_GFX.h>

Now it's compiling but it doesn't display something right.
this one is working with extended ascii demo

#define TEST_TEXT "ßäöü ñâàå"   // Text that will be printed on screen in the font

#include <SPI.h>
#include <Adafruit_GFX.h>     

// The custom font files attached to this sketch must be included
// They only occupy memory if the sketch uses them.
#include "MyFont09.h"
#include "MyFont10.h"
#include "MyFont12.h"

// Easily remembered names for the fonts
#define MYFONT9  &myFont9pt8b
#define MYFONT10 &myFont10pt8b
#define MYFONT12 &myFont12pt8b

#define TFT_CS 14  //for D32 Pro
#define TFT_DC 27  //for D32 Pro
#define TFT_RST 33 //for D32 Pro
#define TS_CS  12 //for D32 Pro

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);




void setup(void) {

  Serial.begin(115200);
  
  tft.begin();

  tft.setRotation(1);

  tft.setAttribute(UTF8_ENABLE , true);
  tft.setAttribute(CP437_ENABLE, true);
}

void loop() {

  tft.setTextColor(ILI9341_WHITE); // white characters

  tft.fillScreen(ILI9341_BLUE);    // Clear screen

  //tft.setFont(MYFONT9);          // Select the font
  tft.setFont(MYFONT10);           // Select the font
  //tft.setFont(MYFONT12);         // Select the font

  tft.setCursor(0,0);
  tft.println();                   // Drop cursor 1 line

  tft.println("ÿâäàå¡");           // Print test characters
  tft.println(TEST_TEXT);
  tft.println(12345);

  tft.println("Śś abc ŜŝŞ");  // Test with some out-of-range characters
                              // (only " abc " will be printed)

  tft.println("Hello");

  delay(2000);
}

The one I want to work with TFT_espi doesn't display properly.

#include <Adafruit_GFX.h>

#include "MyFont10.h"
//#define MYFONT10 &myFont10pt8b


// Include the TFT library https://github.com/Bodmer/TFT_eSPI
#include "SPI.h"
#include <TFT_eSPI.h>              // Hardware-specific library
TFT_eSPI tft = TFT_eSPI();         // Invoke custom library

void setup()
{
  Serial.begin(115200);

  // Initialise the TFT
  tft.begin();

  tft.setAttribute(UTF8_ENABLE , true);
  tft.setAttribute(CP437_ENABLE, true);

 }

void loop()
{
tft.setTextColor(ILI9341_WHITE); // white characters

  tft.fillScreen(ILI9341_BLUE);    // Clear screen

  //tft.setFont(MYFONT9);          // Select the font
  tft.setFreeFont(&myFont10pt8b);           // Select the font
  //tft.setFont(MYFONT12);         // Select the font

  tft.setCursor(0,0);
  tft.println();                   // Drop cursor 1 line

  tft.println("ÿâäàå¡");           // Print test characters
//  tft.println(TEST_TEXT);
  tft.println(12345);

  tft.println("Śś abc ŜŝŞ");  // Test with some out-of-range characters
                              // (only " abc " will be printed)

  tft.println("Hello");

  delay(2000);
 }

Do you think it's not working due to
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST); different to
TFT_eSPI tft = TFT_eSPI(); ?

TFT_eSPI may have similar methods but it does NOT inherit from Adafruit_GFX class.

When using TFT_eSPI you should never #include "Adafruit_GFX.h"
And it is important to #include Font files in the correct order.

Try this:

#include "SPI.h"
#include <TFT_eSPI.h>              // Hardware-specific library
TFT_eSPI tft = TFT_eSPI();         // Invoke custom library

#include "MyFont10.h"              // include **after** TFT_eSPI.h
// *** do NOT #include "Adafruit_GFX.h" *** 

void setup()
{
    tft.begin();
}

void loop()
{
    tft.setTextColor(ILI9341_WHITE); // white characters
    tft.fillScreen(ILI9341_BLUE);    // Clear screen

    tft.setFreeFont(&myFont10pt8b);           // Select the font
    tft.setCursor(0, 0);
    tft.println();                   // Drop cursor 1 line

    tft.println("ÿâäàå¡");           // Print test characters
    //tft.println(TEST_TEXT);
    tft.println(12345);

    tft.println("Śś abc ŜŝŞ");  // Test with some out-of-range characters
    // (only " abc " will be printed)

    tft.println("Hello");
    
    tft.setFreeFont(&FreeSerifBold12pt7b);
    tft.println();
    tft.println("FreeSerifBold12pt7b");
    tft.println("ÿâäàå¡");           // Print test characters
    tft.println(67890);
    tft.println("Śś abc ŜŝŞ");  // Test with some out-of-range characters
    tft.println("Hello");

    delay(2000);
}

David.

Thanks a lot !!

Where did you get your myFont10pt8b from?

The SQUIX site only produces a 94 letter Font. tilde i.e. char(126) is not correct.

I can generate FreeFonts but it is nicer to use a website like SQUIX.

I have not looked at Bodmer's documentation recently. Does he handle UFT8 Fonts nowadays?

MCUFRIEND_kbv inherits from Adafruit_GFX so I can use Olikraus's u8g2_for_adafruit_gfx.
This means you can use u8g2 fonts e.g. Unicode, Chinese, Greek, ... via UFT8 text.

David.

@bobby75
You do not need to edit the library if you keep the font file local to the sketch, you can adapt the example here.

If you follow the YouTube tutorial (link here) then you can use any contiguous 16 bit UNICODE code point range above the normal ASCII range with the Adafruit "Free Font" format. You will not be able to do that with the stock Adafruit_GFX library, although I did add the capability to a tweaked copy here.

I see nothing wrong with the font file you posted so look for a problem in your own IDE setup and/or sketch.

@bodmer,

The SQUIX site will only generate FreeFonts for 0x20-0x7D. The bitmap and glyph is missing for 0x7E (tilde)
If I select the Library: <3.0.0 I can get 0x20-0xFF. Which I can translate into FreeFont format. And output any subset of 0x20-0xFF.

Do you know what this <3.0.0 format is?
Do you know what the >=3.0.0 format is?

<3.0.0 looks like Thiele format but with packed bitmaps (and a special feature)

I will probably raise an Issue on GitHub - squix78/esp8266-oled-ssd1306-font-converter: WebApp to create fonts for the esp8266-oled-ssd1306 library
but I suspect that squix78 will not respond.

Do you know of any other online Font Converter sites?

David.

@David,

david_prentice:
Do you know what this <3.0.0 format is?
Do you know what the >=3.0.0 format is?

<3.0.0 looks like Thiele format but with packed bitmaps (and a special feature)

I have not looked at the format, they are for Squix's (aka Daniel Eichhorn) TFT library (called miniGrafix I think) at different versions.

david_prentice:
Do you know of any other online Font Converter sites?

Here is one I found almost by accident a while ago, it looks promising but I have not tried it.

For command line generation of fonts with an extended range I followed following the tutorial here:

and downloaded the pre-compiled Windows compatible files from the .exe link in that that tutorial to generate extended range fonts.

As an example command line for the Japanese Hiragana characters in the code point range 12353 - 12435 is:

fontconvert C:\Windows\Fonts\sourceFont.ttf 12 12353 12435 > hiragana12.h

TFT_eSPI supports 5 font formats already but if I were to add another format it would probably be the one used by LittlevGL as the format and converter tools appear to be well thought out.