Nextion Display - Performance issue, possibly library delay?

Hi guys,

I'm using a Nextion display through the ITEADLIB_Arduino_Nextion library. I have gotten it to work but it seems like when I add more and more components such as NexNumber, the Arduino lifecycle loop() starts to slow down very fast.

When I use a single NexNumber instance, the loop goes very fast. However, as I add more, it seems like the loop starts to slow down with approx. 100ms per additional instance. This is problematic as I intend to have 20+ components on my display.

A little snippet of my code (intentionally incomplete):

#include <Nextion.h>

NexNumber nEgt1(0, 7, "n6");
NexNumber nEgt2(0, 12, "n11");
NexNumber nEgt3(0, 11, "n10");
NexNumber nEgt4(0, 10, "n9");

void setup() {
  Serial.begin(115200);

  nexInit();

  // The following does not seem to help
  //  Serial1.print("baud=115200");
  //  Serial1.print(0xff);
  //  Serial1.print(0xff);
  //  Serial1.print(0xff);
}

void loop() {
  double t1 = <snip>.readCelsius();
  double t2 = <snip>.readCelsius();
  double t3 = <snip>.readCelsius();
  double t4 = <snip>.readCelsius();

  // every addition here seems to add 100ms delay to the loop
  // 4 calls adds ~400ms
  nEgt1.setValue(t1);
  nEgt2.setValue(t2);
  nEgt3.setValue(t3);
  nEgt4.setValue(t4);
}

Does anyone know what might cause this?

Things I have tried:

  • I have looked for usages of delay() in the ITEADLIB_Arduino_Nextion library. I found some, but commenting them out does not seem to help.
  • I have tried to increase baud frequency, but it does not seem to cause any difference.

Thanks for any response.

Hello msalte86,
Welcome to the forum. For following the forum rules and using code tags on your first post ++Karma;

I don't use the Nextion libraries, I kind of know from what others have said that they are slow, but I don't know the specifics. In my tutorial 'using Nextion displays with Arduino' there is a link to a much improved Nextion library created by Ray Livingstone, if you prefer the libraries you should probably use his libraries. You could also try my methods as set out in the tutorial, but they are different to the libraries and you have to understand how they work.

  // The following does not seem to help
  //  Serial1.print("baud=115200");
  //  Serial1.print(0xff);
  //  Serial1.print(0xff);
  //  Serial1.print(0xff);

It's not that simple to change the baud rate. You have to change it at both ends at the same time, well, sort of. The default on the Nextion is 9600 baud, so unless you change it in your Nextion configuration the rate you use for Serial.begin must also be 9600. If you want to use a higher rate then in the Nextion editor, in page 0 under Postinitialize Event put:

baud=<the baud rate you want>

For example:

baud=115200

Then use the same baud rate with Serial.begin. You have to be very careful changing the baud rate from within the program, and with your level of experience I think it's best to just say don't do it.

As for the 100ms delays, don't know, try Ray's libraries. If you are lucky he might pop along and offer advice, but that's up to him.

Good luck.

EDIT: I missed something....
This:

Serial1.print(0xff);

Does not send the single byte 0xff to the serial port, which is what you want it to do. You need to use

Serial1.write(0xff);

Instead.

Thank you for your quick response! I will definitely try out your suggestions!