TFT screen print new line

Hello
I recently recived tft 3.2 screen labled- "QVT 320 ILI9341"
I used the UTFT-library and the URtouch library:

http://www.rinkydinkelectronics.com/library.php?id=51

The touch and everything working great
But when i tried to write long text the line is being cut
I cant find a command to start new line automaticlly
Even if i use" /n" in the text itself its doing nothing....
Anyone knows how to do it????

How to warp up the text???

Just print a long text to see how many characters you can print on a single line. Then cut your text in parts of up to this number of characters and print each part at the correct place on the screen (meaning increase the y position by the heigth of one text line).

Using 15 characters per line, this would look like:

Just print a
long text to
see how many
characters you
can print on a
single line.

Thanks for your answer ...
The varible text im printing has a diffrent sizes
Im looking for command that handle it

Which fonts are you using?

Most UTFT fonts are fixed width. You can calculate the size of your message by multiplying the character-width by the length of the string.

Adafruit_GFX style libraries have methods to calculate the rectangle used by the string.

void getTextBounds(char *string, int16_t x, int16_t y, int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h);
void getTextBounds(const __FlashStringHelper *s, int16_t x, int16_t y, int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h);

But regular printing performs the linewrap automatically.

void setTextWrap(boolean w);

Hey-ho. You just have to choose whether to use GFX-style or UTFT-style classes.

I do not find UTFT intuitive.

David.

By saying GFX style you mean the library?

I mean Adafruit_GFX class.

Most TFT, OLED, GLCD, ... hardware libraries either inherit the Adafruit_GFX class or implement exactly the SAME methods.

This means that you can rebuild a program for another library easily.

Which UTFT fonts are you using?

The UTFT print() methods require you to know where to place each string. Many graphics programs know all the messages they are going to print at compile time.
If you have random text, you will need to calculate the coordinates yourself at runtime. Ideally, you keep whole words on one line. You might even justify left and right like professional typesetting. But you probably need to select attractive fonts before you consider this.

David.

Thanks David i will try to blend with the GFX lib hope its will suit to my screen

Seriously, say which UTFT font(s) you are using.

It is fairly easy to handle letterwrap or even wordwrap.

You would still need to do wordwrap with a GFX style library.

David.

Do you know if the GFX is suits for my screen i cant find any record that i can use gfx with my screen

Please answer my question about UTFT fonts.

I can then give you accurate advice.

If it takes many messages to get proper reply, your readers will stop answering.

David.

Sorry im using the defult fonts
Small, and the ,big
Like the examples....

SmallFont, BigFont and SevenSegNumFont are all fixed width fonts.

You just need to keep track of the print position.

Do you want to break on words or just on letters?
Do you want to print formatted f-p values?

I strongly suggest that numeric values do not wrap. You should format them in such a way that they always fit.

It should be easy enough to write your own helper function.
If you want assistance, say so. And provide some example text and desired layout on the screen.

David.

Im using the big font.... to write an error message
For example "piston time out.. please make sure sensor in place and try to run again"
The error varible can change to diffrent text in the code depend on the failure

When im print it i only get to see part of the sentence in one line
So please please help me handle cause i dont want to splite the text to several varibles

Yes i want assistant wih the function....

From DefaultFonts.c in the UTFT directory:

// BigFont.c (C)2010 by Henning Karlsen
// Font Size : 16x16
// Memory usage : 3044 bytes
// # characters : 95

Each letter is 16 pixels wide and 16 pixels high. You should find that the letter spacing and line spacing is already in the tables.

You can determine the space on screen used by "piston time out.. please make sure sensor in place and try to run again". e.g. width = strlen(message) * 16. height is 16.

I counted this as about 72 letters. i.e. 1152 pixels.
A 320 pixel wide screen can contain 20 letters. So you would write your message in 4 lines.

Seriously, it will look horrible if the words are broken. And BigFont is pretty ugly anyway.

Your helper function would look for spaces or periods. Print the whole words that fit on a line. Then do the same for subsequent lines. You can lose the trailing space.

David.

Edit. Have a go at writing the function for yourself. Post it here. I am sure that readers will help you if you get stuck.

Here is an example sketch for UTFT. If a string does not fit, it prints on the next line (at same X position)

Although GFX programs can handle letter wrap, they do not break on words. And the linefeed always goes to column #0.

You can adapt the helper function for a GFX style program.
You can adapt for char arrays in PROGMEM or for String class arguments.

David.

#include <UTFT.h>

// Declare which fonts we will be using
extern uint8_t BigFont[], SmallFont[];
extern uint8_t SevenSegNumFont[];

//UTFT myGLCD(model,RS,WR,CS,RST,[ALE]);  //assumes that nRD is tied high
//UTFT myGLCD(ILI9481, 38, 39, 40, 41);
UTFT myGLCD(ILI9486, 38, 39, 40, 41);
//UTFT myGLCD(R61581, 38, 39, 40, 41);

#define TFT_WHITE 0xFFFF
#define TFT_BLACK 0x0000
#define TFT_BLUE  0x001F

int widchar, htchar;    //global variables

void printwrap(const char *msg, int x, int y)
{
    int maxchars = (myGLCD.getDisplayXSize() - x) / widchar;
    int len = strlen(msg), pos, i;
    char buf[maxchars + 1];
    while (len > 0) {
        pos = 0;
        for (i = 0; i < len && i < maxchars; i++) {
            char c  = msg[i];
            if (c == '\n' || c == ' ') pos = i;
            if (c == '\n') break;
        }
        if (pos == 0) pos = i;   //did not find terminator
        if (i == len) pos = len; //whole string fits
        strncpy(buf, msg, pos);  //copy the portion to print
        buf[pos] = '\0';         //terminate with NUL
        myGLCD.print(buf, x, y); //go use UTFT method
        msg += pos + 1;          //skip the space or linefeed
        len -= pos + 1;          //ditto
        y += htchar;             //perform linefeed
    }
}

void setup()
{
    myGLCD.InitLCD(PORTRAIT);
    myGLCD.clrScr();
    myGLCD.setColor(TFT_WHITE);     //text colour
    myGLCD.setBackColor(TFT_BLUE);  //shows up trailing spaces
    const uint8_t *f = BigFont;
    myGLCD.setFont(f);              //set font and fetch dimensions
    widchar = pgm_read_byte(f + 0);
    htchar = pgm_read_byte(f + 1);
}

void loop()
{
    printwrap("piston time out.. please make sure sensor in place and try to run again", 0, 20);
    printwrap("earholes are cheap today, cheaper than yesterday.", 20, 100);
    printwrap("David Prentice\nWormshill\nKent", 60, 180);
    while (1) ;

}

In practice, most GFX programs would embed linefeeds in a message string to ensure that words wrap nicely. (disadvantage is that linefeeds always go to left hand column)

Hi David i just saw the code you were write i will check it ASAP and update...
Thanks for the help.....

Ok i test the code and it working great but the write is vertical insted of horizental
how can i fix it?

You choose LANDSCAPE instead of PORTRAIT

Hey it was the PORTRAI definition.....
You solved my problem!!!!!!!!!!!!!
you are a king!!!
Thanks for the great great Help!!! :slight_smile: :slight_smile: