Go Down

Topic: Nextion 7 inch DIsplay - file gets to large (Read 340 times) previous topic - next topic

Manuel_o

Hey freinds.

My problem is, that my tft file is now 33.5 mb large.

I have 60 images in in.

When i try to upload the sketch, i get the message "file to large for destination device"

So I am kinda frustrated now because my project isnt finished.

I cant imagine i am the only one who faces the limits of the Nextion

So my question now. What ways, tricks, tips you found out to manage the problem?

What also confuses me: I made the pictures with Adobe XD. My 60 pics (pngs) have together a filesize of
1.2 mb. I dont get it, why the Nextion gets so large with the pics. Does the NExtion "scale" them up or something?


Thank you! 

PerryBebbington

#1
Nov 12, 2019, 04:07 pm Last Edit: Nov 12, 2019, 04:08 pm by PerryBebbington
All the images I have used in my projects have been jpg, not png. I don't know how it handles png. I've never built a project with 60 images. Just looking at the background image for one of my projects it is 32kB, so 60 of those would be under 2MB.

Are you editing the images to be exactly the number of pixels you need them to be?

Not sure if that helps :smiley-confuse:

Manuel_o

#2
Nov 12, 2019, 06:26 pm Last Edit: Nov 12, 2019, 06:27 pm by Manuel_o
Hello

Thank you for your answer

Yes the pictures are exactly the size of my 7 inch screen.

I tested it now with JPG. I dont understand it


I create a pictrue A with adobe XD.

The scale of the picture is 800x480. The size of the picture is 31.2 KB

My Nextion project has now a size of 26649 KB. When i add the picture A to my project, my projectsize now is 27444. I dont get it

Any ideas?

Thank you

PerryBebbington

#3
Nov 12, 2019, 07:40 pm Last Edit: Nov 12, 2019, 07:42 pm by PerryBebbington
Quote
Any ideas?
Not really, sorry.

Are you saying that using jpeg images helps?

I see the 7" screens have 32MB of flash, I would have imagined your project would fit into that easily.

  • My biggest project has 3 images over 5 pages and the tft file is 2934kB.
  • I have another, also on a 7" screen, no images at all, 318kB.

It does seem that the images take up more room than their file size suggest they should.

Manuel_o

yes unfortunly.

I never looked at the filesize because i knew that my pichtures arent that big.

Strange that the nextion display uses so much space for one small pic.  :smiley-confuse:

Manuel_o

#5
Nov 12, 2019, 10:23 pm Last Edit: Nov 12, 2019, 10:24 pm by Manuel_o
Hey Perry. I hope u dont mind if i can ask you a short questionn about a Serialcommand.

Code: [Select]

/Serial2.print("ErrorMsg_1.txt=\"");
      Serial2.print(variable);
      Serial2.write('"');
      Serial2.write(0xFF);
      Serial2.write(0xFF);
      Serial2.write(0xFF);


is it possible to make the 1 of ErrorMsg_1 a vriable?

for example

int z =1

Code: [Select]

/Serial2.print("ErrorMsg_z.txt=\"");
      Serial2.print(variable);
      Serial2.write('"');
      Serial2.write(0xFF);
      Serial2.write(0xFF);
      Serial2.write(0xFF);


something like that. I am kinda confused about the \"

Thank you


Seithan

Code: [Select]

       Serial2.print("ErrorMsg_");
         Serial2.print(z);                 // z is the variable from your example
         Serial2.print(".txt=\"");
         Serial2.print(variable);
         Serial2.print("\"");
         Serial2.print("\xFF\xFF\xFF");



From my Tutorial you can see adout \"

at : How to change components' attributes at Nextion from Arduino:

and also How to make a useful pop-up message on Nextion

UBUNTU:
"I am what I am, because of who we all are", compassion, kindness and humanity that connect us together by sharing  ourselves with others and caring for those around us.

PerryBebbington


Quote
I am kinda confused about the \"
Consider this:
Serial.print ("Some text");
The text sent to the port will be:
Some text
However, the Nextion wants to see what you send in quotes, for example it wants to see
"Some text" (not Some text)
The problem with that is that Serial.print uses " to indicate the start and finish of the text you are printing, it does not normally actually send the " to the serial port. In this case we want the " to be sent. In order to tell Serial.print that " should be printed put a \ in front of it. So
Serial.print("\"Some text\"");
Will send to the serial port
"Some text"

Yes, you can break the text into parts as you want to and as Seithan has illustrated. Be careful with
Serial.print and Serial.write though, don't get them mixed up.

Manuel_o

Thank you all for your help.

Always appreciate it. I kinda manged it and made this. Maybe it will help someone.

Code: [Select]

int z = 1;

      String str = String("ErrorMsg_")+String(z)+String(".txt=")+String("\"")+String(IamAVairable)+String("\"");
      Serial.println(str);
      Serial2.print(str);
      Serial2.write(0xFF);
      Serial2.write(0xFF);
      Serial2.write(0xFF);


PerryBebbington

Slight problem with that....
Using String (capital S) on Arduino leads to all sorts of random problems. There are lots of discussion on this site about it.

Please read 'Using Nextion displays with Arduino', the examples in there show you how to achieve what you are trying to do.

Seithan

#10
Nov 13, 2019, 06:38 pm Last Edit: Nov 13, 2019, 06:43 pm by Seithan
How to use < sprintf > command:

A very useful command is the <sprintf>. This command will construct a string from different type of variables and will store it
in a char array in our case <buffer>. We must declare the length of the array to be long enough to hold all the characters.
With sprintf we can include variables within a text using format specifiers with the prefix < % >, format specifiers are replaced  
by the values specified in subsequent additional arguments.
sprint(char array to store value, "<TEXT TO PRINT %[format specifier]NEXT TEXT%[format specifier]",<name of 1 variable>,<name of 2 variable>)
Format specifier table from: https://arduinobasics.blogspot.com/2019/05/sprintf-function.html



More for sprintf-function to:http://www.cplusplus.com/reference/cstdio/sprintf/


And a sample of code

Code: [Select]

#define ARRAY_ROWS 5 // Number of rows.
#define ROW_LENGTH 38 // Max number of characters in a single row. At the Nextion, the txt_maxl is setted to 40.

const char text [ARRAY_ROWS] [ROW_LENGTH]{
  {"0) Test text of 37 characters @@@@123"},
  {"1) This the page of the demonstration"},
  {"2) For The scrolling TEXT on NEXTION_"},
  {"3) Crtd by SEITANIS THANASIS 8-8-2019"},
  {"4) Find it at my site www.seithan.com"},
 };

void setup(){  
  Serial.begin(9600);
  delay(500);
}

void loop(){

      int i = 2;
      
      char temp_data[50];  // temp_data or buffer
      sprintf(temp_data, "va%u.txt=\"%s\"", i, text[i]);
      Serial.print(temp_data);
      Serial.print("\xFF\xFF\xFF");

}


This is going to send the line 2 (i=2) to va2 on nextion
UBUNTU:
"I am what I am, because of who we all are", compassion, kindness and humanity that connect us together by sharing  ourselves with others and caring for those around us.

Seithan

Sorry for the late reply, but I had to do research on why the pictures become so big in file size when you import them on Nextion.

The accepted picture types to import are *.jpg, *.png, non animated *.gif and *.bmp files.

When importing a picture, the picture is converted into the 565 16 bit color format used by Nextion.

In Basic and Enhanced models: Nextion is not a graphics card, as such transparency and in picture animation is not supported.

In native 16-bit color, picture, resources consume 16 bits per pixel, or width x height x 2 bytes.

In Intelligent models: Nextion now supports transparency and image compression allowing more picture resources for the same space, the 2 bytes per pixel formula does not apply.

Also, I wanted to see if this was true, so I tested it to prove it.

For Basic and Enhanced models:

Resolution   .tft file size  format/image size  imported image size  .tft after import
480x320:   277 KB  .png / 196 KB  307,224 B  605,536 B
480x320:   277 KB  .jpg / 12 KB  307,224 B  605,536 B

800x480:   277 KB  .png / 351 KB  768,024 B  1064,288 B
800x480:   277 KB  .jpg / 22 KB  768,024 B  1064,288 B


And for Intelligent models:

Resolution   .tft file size  format/image size  imported image size  .tft after import
800x480:   538 KB  .png / 351 KB  138,919 B  669,980 B
800x480:   538 KB  .jpg / 22 KB  88,630 B  669,980 B


Conclusion:
Basic and Enhanced models no matter the picture format and size, the final size of the imported image, will be the same, following the rule: width x height x 2 bytes. For example: 800*480*2=768,000B.

For the Intelligent models, the file format does not matter again, as the final .tft file size will be the same, following Nextion's image compression.
UBUNTU:
"I am what I am, because of who we all are", compassion, kindness and humanity that connect us together by sharing  ourselves with others and caring for those around us.

PerryBebbington

Excellent information Seithan.

++Karma;

Seithan

Hello Perry,

Thank you for your kind words.

A karma from a guy like you is much appreciated  :)

UBUNTU:
"I am what I am, because of who we all are", compassion, kindness and humanity that connect us together by sharing  ourselves with others and caring for those around us.

krupski

Code: [Select]

/Serial2.print("ErrorMsg_z.txt=\"");
      Serial2.print(variable);
      Serial2.write('"');
      Serial2.write(0xFF);
      Serial2.write(0xFF);
      Serial2.write(0xFF);


something like that. I am kinda confused about the \"

Thank you


If you create a string, you do it like this:  string= "Hello there"

Now what if you want the quote character in a string like this:  string= "where did you "find" it? "

The compiler thinks your string is whatever is inside the first two quotes... that is "where did you "

Then it sees find" it? " and says Huh???

You need to use the backslash character to tell the compiler "the following character is not a control character, but something I want printed".

So, now the proper way to do it is:  string= "where did you \" find\" it? "

See? The \" means "print this as a quote character... its not the end of my string".
Gentlemen may prefer Blondes, but Real Men prefer Redheads!

Go Up