Creating your own fonts for Adafruit TFT

Obviously you have to put your Touch Calibration into the sketch.
Your screen uses :

const int XP = 8, XM = A2, YP = A3, YM = 9; //ID=0x9341  m. Elegoo 2.8"
const int TS_LEFT = 907, TS_RT = 111, TS_TOP = 902, TS_BOT = 79;

Most shields use 6, 7, A1, A2

I attempted to build your ZIP. Obviously I changed for my Touch pins.
And I had to add some dummies for missing Menu functions:

void Menu_31(void) {}  //.kbv
void Menu_32(void) {}
void Menu51(void) {}
void Menu52(void) {}

Yes, there are several inappropriate TextColor() and TextSize()

I have no idea what the program is supposed to do. Increment buttons seem to decrement. OK button does not seem to function.

As I suggested earlier. Please get it functional with 5x7 System font. Use size = 1. Then it should be easy to see what colours, fonts or sizes will be appropriate for the Text in the Release.

It seems to respond to non-button images. I suggest that you make buttons look obvious. e.g. rounded. and show when they are pressed.

David.

Woo-hoo. You had mapped the Touch from BOT to TOP instead of TOP to BOT. Hence none of the buttons made sense.

    pixel_x = map(p.x, TS_LEFT, TS_RT, 0, tft.width()); //.kbv makes sense to me
    pixel_y = map(p.y, TS_TOP, TS_BOT, 0, tft.height());  //.kbv changed from BOT, TOP

Get the functionality correct.

Then we can change to some more attractive fonts. (and colours)

Using escapes in labels is a one-off.
Anything with lots of Danish text would be easier with UTF-8 encoded strings.

David.

The pic is from a test of other charset, where I use FreeMonoBold9pt7b, FreeMonoBold12pt7b, FreeMonoBold18pt7b and FreeArial12full. In the top the filename is written.

I forget some of the menus when packing the files and I deleted a routine, but don't all the call to it. Apologize.

The setup:
const int XP = 8, XM = A2, YP = A3, YM = 9; //ID=0x9341 m. Elegoo 2.8"
const int TS_LEFT = 907, TS_RT = 111, TS_TOP = 902, TS_BOT = 79;
is correct for my shield.
When I make this setup in 'buttom_multible.ino' (and changed TOP/BOT) the program work exelent!

In the attachment I has added the missing menus.

Not more for now, other things has to be done!
Kurt

Menu_MCU1_GB.zip (12.1 KB)

I think I now has changed the code as you expect.
But it is with my setup for touchscreen.
Kurt

Menu_MCU1_GB.zip (12.2 KB)

The code that you posted in #42 worked. I used my Touch Calibration. I corrected your BOT, TOP in k_sub.ino

Likewise, I had to correct BOT, TOP in #43

Seriously, the Calibration gives correct values for TS_LEFT, TS_RT, TS_TOP, TS_BOT. Please use them.

Touch panels vary. All screens from one batch probably have similar Calibration.
A new batch may be different.

Which fonts do you want to use?

David.

I has tryed some other tft-shild from mcufriend, and they all use:
const int XP = 6, XM = A2, YP = A1, YM = 7; as you say, so my shield from Elegoo is special!

I have tryed FreeArial12full and I like it, but would like also to get it in a bold version. And maybe also in fontsize 9.

Is it possible in your program to make it to reference to upper left corner as normal for GFX?

And I would like to have an arrowUp and arrowDown.

I suppose, that you have a program to make the charsets, is it a free program?

Kurt

There are many variations for the Touch pins. And even more for the directions.

Adafruit provide C source code for fontconvert. Fine if you have Linux.
Painful for Windows.

I believe that has the fontconvert.exe available online.
Kris has a tutorial video

I make other fonts with an Arduino sketch.

David.

I just used Kris's video to make the Bold9full font. Untested.
There is a bit of faffing about with changing names etc. And Notepad++ saves in Unifont and not regular ascii. (Please check the format)

In an ideal world someone would amend the current web-based converter accept first and last character arguments. It can default to 32, 126 but let you make a Number or Full font.

Edit. When you generate a 12pt Font from the Arial Bold TTF font, you get the Euro symbol at 128. You get blanks for characters 128-160 in 9pt even though it is generated from the same TTF.

FreeArial_Bold12full.h (31.5 KB)

FreeArial12full.h (29.9 KB)

FreeCourier_New12full.h (27.6 KB)

FreeArial_Bold9full.h (31.4 KB)

FreeArial9full.h (30.1 KB)

The Adafruit_GFX library does not handle UTF-8 encoded strings, hence the missing characters.

See this link.

I have changed the baseline in my edition of charset FreeArial_Bold12full, so the baseline now is top left and I has 'handcoded' the two last chars ($FE and $FF) to show ArrowUp and ArrowDown.
In order to avoid mistake I would like to give the file another name, but it give error when compiling.
I have seen the tutorial video from #45, but it is difficult for mee to understand the method.
Anybody knowing a written tutorial anywhere?

I attach the fontfile.

FreeArial_Bold12full.h (31.5 KB)

Your file "looks" ok to me.

I will see what happens when I try to use it.

I edited the show_font sketch:

...
#include "FreeArial12full.h"
#include "FreeArial_Bold12full.h"
...
void loop()
{
    fontshow(NULL, "system_7x5");
    fontshow(M1(FreeArial12full));
    fontshow(M1(FreeArial_Bold12full));
    ...

It displayed char(254) and char(255) as arrows.
You will need to use escapes to display in regular Adafruit_GFX print() statements.
e.g. I appended this to the bottom of setup()

    tft.fillScreen(TFT_RED);
    tft.setFont(&FreeArial_Bold12full);
    tft.setCursor(0, 12);
    tft.println("David \xFE Prentice \xFF");
    tft.println("WORMSHILL \xFE");
    tft.println("KENT \xFF");
    delay(5000);
    tft.fillScreen(TFT_BLACK);

I strongly suggest that you rename your Font.

David.

: ) Hello friends !

Can you help me implement a GY MPU6050 in a demonstration code of the beloved Bodmer?

I'm having difficulty transferring to the TFT the Pich and Roll values generated by MPU6050.

Good luck everyone!

I realy want to rename, but I can't compile without error.

In the top of the file 'FreeArial_Bold12full_TL' I wrote:
// generate FreeFont from LCD Vision font
const uint8_t FreeArial_Bold12full_TLBitmaps[] PROGMEM = {.....

Later nearly 70% down I wrote:
// strip blank pixels: top = 0, bot = 0, left = 0, rt = 1, adv = 18, desc = 3
const GFXglyph FreeArial_Bold12full_TLBitmapsGlyphs[] PROGMEM = {
{ 0, 0, 0, 9, 8, -1 }, // 0x20 ' '

and in the bottom:

};
const GFXfont FreeArial_Bold12full_TLBitmaps PROGMEM = {
(uint8_t *)FreeArial_Bold12full_TLBitmaps,
(GFXglyph *)FreeArial_Bold12full_TLBitmapsGlyphs,
32, 255, 19
};
// FreeArial_Bold12full bitmap size = 2494 [4510] [7395]

When compiling the error is:
#include "c:\Arduino\Project\libraries\Adafruit-GFX-Library-Master\Fonts2\FreeArial_Bold12full_TL.h"
^
compilation terminated.

I use TextPad or Arduino IDE to edit the file

Please try the attached file. Note the way that all the structs are named.

I added it to the show_fonts sketch. It builds and runs fine.

FreeArial_Bold12full_TL.h (32.2 KB)

Thank you, David.
You file work.
And I found out why some other fonts give errors: the filename don't match the name in the file.

Now I has choiced the charset, it is FreeCourier_New12full.

I am lokking in Adafruit_GFX.cpp in order to find out to center the text in the buttons.
Kurt

Current:

  _gfx->setCursor(_x1 + (_w/2) - (strlen(_label) * 3 * _textsize),
    _y1 + (_h/2) - (4 * _textsize));

You would test for system font i.e. gfxFont == NULL
If not NULL, you would add the appropriate offset to _y1.

The system font uses 8 pixels height. - (4 * _textsize) centres it. i.e. subtract half-height * textsize to get the top-line
You would look up the height of the letter '8'. Then add half-height * textsize to get the base line

Most fonts contain the letter '8'. It is normally the same height as CAPITALS

Personally, I would always choose x1 when using FreeFonts.

What is the point of turning an attractive smooth font into an ugly blocky one?
You can see the difficulties with "special fonts"

David.

I don't understand you comments "What is the point of turning an attractive smooth font into an ugly blocky one?".

The system 5x7 font looks ok in x1 and x2. If you use setTextsize() bigger than 2 the text looks blocky.

FreeFonts look nice in x1. You notice the blocks in x2

David.

OK.
I plan to use font in 9, 12 and 18 pt. in order not to use x2.
But the problem when not using monospace is (as well as I can see in the program), that the program don't know the width af the single chars and then not the langth of the string. Am I rigth?

There are methods like getTextBounds(). I think there is a charWidth() too.

Look in Adafruit_GFX.h

You can write your own functions to centre or right-align proportional width fonts.
A monospaced font is easier. You read fixed width and height as a one-off.

When overwriting text, you can draw a fresh background for the whole string. Looks blinky.
Or you draw a fresh background one character at a time. Looks nicer.

Ideally you would draw letter and background in one go like you do with the 5x7 font.

David.

Thank you. I will look at it.