Unofficial Nextion/TJC User Forum

Problem with array TX

hi, I have a display nextion NX1060P101-011C-I, so the top of the range.
With this display I created a GUI that must represent 15 values ​​with bars and graphs, the problem is that I have to send the data packet cyclically to the display every 50ms and I only have 20-25ms of time (so half cycle time) to send everything. If I use the “standard” technique, then send data by data to the display … for example:
ywirP.setValue (GUI_DATA [i]);
ywirN.setValue (100);
rotP.setPic (GUI_DATA [i]+353);
etc…
I lose too much time, in fact using a logic analyzer I noticed that after sending each line of code, my MCU expects a response from the nextion that comes after 1-2 ms, so I can’t send all the data to the display, or if I try, I cause enormous delays on the code!
How can I do?
I thought, if possible, to send an array of data, for example a “packet [15]” array to the display, so that the display immediately receives all the data (1-3ms) and in the remaining time the display can graph it all.
Thank you all for your help

PS: i set the baudrate to 115200

I think it’s just a limitation of the library. You can send out one big command string delimited by ÿÿÿ (0xFF 0xFF 0xFF) in one go. As long as the commands fit in the 1024 byte serial buffer.

Depending on the type and number of fields you want to update, it should be possible to stuff as much as possible in one string. That should considerably speed up the rendering without waiting for each individual response.

but on the gui of the nextion i have to write code?

scuse me, can you write a small example please…for example a code to send data to change 2 image and to set 5 values.

PS: i use the official (i think) library for arduino : ITEADLIB_Arduino_Nextion, i take it on github.

thanks for your help

You don’t need to change anything on the GUI.

I’m not an arduino guy, but I would presume it to be somethng like:

Serial.write(“p[0].b[1].val=123”);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(“p[0].b[2].val=456”);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(“p[0].b[3].val=789”);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);

etc… p[] being the Pagenumbers and b[] the oBjectid’s. You can also use the objectnames:

Serial.print(“n1.val=”); // Changing the value of box n1
Serial.print(“200”);
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);

Just send the time-sensitive commands directly to the screen instead of passing them through the library.

Perfect dear, infact the problem is the library…it’s really really slow! Now the comunication is good and the display is fast and reactive
but now i have another problem… i want to put a button on the display, but i don’t want to use an interrupt.
So, my question is, can i read the state of button without the library?
thanks

You need to read the serial bytes into a buffer and watch out for 0xff 0xff 0xff as that indicates the end of an event message.

Check ok this code from HASP: https://github.com/aderusha/HASwitchPlate/blob/8618c55bbe444258369e2c779e7058a2a6a5f996/Arduino_Sketch/HASwitchPlate/HASwitchPlate.ino#L658-L689

// Example: 0x65 0x00 0x02 0x01 0xFF 0xFF 0xFF
// Meaning: Touch Event, Page 0, Object 2, Press

The whole instruction set can be found here: https://nextion.tech/instruction-set/#s7
Pay attention to the return codes and format.

Perfect…the code now is perfect!
I can send all code in 20ms, every 58ms and at the same time i can read on button on touch…Thanks :wink:


This forum is in no way affiliated with NEXTION®, ITEAD STUDIO®, TJC®, or anyone else really. All product names, logos, and brands are property of their respective owners. All company, product, and service names used in this website are for identification purposes only. Use of these names, logos, and brands does not imply endorsement from the respective rights holder(s).