Sending a springf in multilines to nextion

Hi there,
i code from esp32 and want to show differents variables in differents lines,
i don’t use any nextion libraries to communicate with nextion.
To show my texts and variables i only use t0.txt as a receipt and to show variables
i use direct typecasting,ex:

Serial.print("t0.txt=");
    Serial.print("\"");
    Serial.printf("first line:%s",String(123));
    Serial.print("\"");
    Serial.print("\xFF\xFF\xFF");

But now, i discovered a way to send to differents lines to nextion without
touching the nextion code inside exept the basic: t0.txt=t0.txt

1x line: Serial.print(“t0.txt="Hello World"\xFF\xFF\xFF”);

3x lines: Serial.print(“t0.txt="first line\rsecond line\rthird line"\xFF\xFF\xFF”);

Now my question is how can i manage a sprintf in 3 lines,with variables,with the
3x lines example?
I tried many ways to manage the " and the \ but that not feats the result i want,
here a dummy code ,i’m trying to do that:

Serial.print("t0.txt=\"first line:%s\\rsecond line:%s\\rthird line:%s\",String(45),String(32),
/String(123))\xFF\xFF\xFF");

but nothing is shown, i know something’s missing,does anybody know?

Anyone that have any kind of idea to guide me?

Try this

Serial.print(“t0.txt="first line:”);
Serial.print(“45”);
Serial.print(“\rsecond line:”);
Serial.print(“32”);
Serial.print(“\rthird line:”);
Serial.print(“123”);
Serial.print(“\xFF\xFF\xFF”);

Hi,i appreciate your help :slight_smile:
unfortunately that gives me nothing on nextion,and the weird thing is that
the copy from the forum gives me stray errors.
i also had to add a \ on the first line to debug a compil:

Blockquote
Serial.print(“t0.txt="\first line:”);
Blockquote

did you meant something like this?

Blockquote
Serial.print(“t1.txt=”);
Serial.print(“"”);
Serial.printf(“first line:%s”,String(123));
Serial.printf(“\rsecond line:%s”,String(4156));
Serial.printf(“\rthird line:%s”,String(12254));
Serial.print(“"”);
Serial.print(“\xFF\xFF\xFF”);
Blockquote

But that don’t go next line :slightly_frowning_face:

If You see “\r” in txt field instead of the new line. Tten you should probably use escape characters inside the string.

Try to use with double backslash.

Serial.printf(“\\rsecond line:%s”,String(4156));

Ok i finally got it,but my brain is warm! :partying_face:
my mistake was to put the final procedure after the variables definitions
and not inside,at the end of all the quotes " ".

here is a 5 lines of differents sorts of variables typecasted inside String():


Serial.printf("t1.txt=\"Line1: %s\\rLine2: %s\\rLine3: %s\\rLine4: %s\\rLine5: %s\"\xFF\xFF\xFF","Nextion multi lines test:",String(742),
String(8532),String(1.45),String(random(269)));

All the code is in only 1 line !!,but had to cut it to feat the forum dimension.