Updating page fields prior to displaying page- Global variables

I have a basic series, 2.4 inch display with a simple gui. It consists of only a few pages total and is for a PID Oven product. Three pages each have two variable fields, ie 6 fields in total that i want regularly updated.At present when i load a page and change a variable it is very visible so i am trying to avoid this by updating in advance of the page load.

I set these (6) variables in the designer as global, however when i set arduino code to use page identifiers in anything more than three cases , the device hangs on its first page upon power up ( its alive as such and the two menu buttons looks like they are reacting to touch but it is not calling another page as it should)

I have three main pages, heating up, heating and drying, each with a temp and time variable, and routines to update them.

void UpdateHeatingUPPage(){ // UpdateHeatingUPPage ///////////////
Serial.print(“page3.TempHU.val=”); Serial.print((int) (10*(celsius-Cal_offset)));
Serial.write(0xff); Serial.write(0xff); Serial.write(0xff);
Serial.print(“TimeHU.val=”); Serial.print((int) (CountdownTimer));
Serial.write(0xff); Serial.write(0xff); Serial.write(0xff);
void UpdateHeatingPage(){ // UpdateHeatingPage ///////////////
Serial.print(“page4.TempH.val=”); Serial.print((int) (10*(celsius-Cal_offset)));
Serial.write(0xff); Serial.write(0xff); Serial.write(0xff);
Serial.print(“TimeH.val=”); Serial.print((int) (CountdownTimer));
Serial.write(0xff); Serial.write(0xff); Serial.write(0xff);
void UpdateDryingPage(){ // UpdateDryingPage ///////////////
Serial.print(“page5.TempD.val=”); Serial.print((int) (10*(celsius-Cal_offset)));
Serial.write(0xff); Serial.write(0xff); Serial.write(0xff);
Serial.print(“TimeD.val=”); Serial.print((int) (CountdownTimer));
Serial.write(0xff); Serial.write(0xff); Serial.write(0xff);

The above works, however if i add another page identifier, for example change TimeHU to page3.TimeHU.val=… then display hangs!

What gets me is it will hang even when the routine is never even called! Bizzare!

I can make all 3 time variables globally driven or two temps and a time but as soon as i hit 4 or more with a page prefix (to drive globally) then it hangs

Driving me nuts! Is this something to do with menory capacity perhaps? I did look at the compiler and output says
available memory 3584
global memory 184
total size of picture 47,880
total size of font 19,934
page 0 184+92=276
page 1 184+312=496
page 2 184+220=404
page 3 184+128=312
page 4 184+164=348
page 5 184+164=348
page 6 184+148=332
page 7 184+92=276
File size 367,544

Doesnt appear to be an issue but who knows with this brand of display

Any help i would be very grateful


Don’t make the variable fields global. Create 6 global variables in program.s which you’ll then update from your Arduino. Update the corresponding fields in the preinitialize event of their page which will prevent the flicker. Use a timer on each page with event code which checks every second or so if the global variable and the field value differ, update the field if yes.
That’s called asynchronous updating and makes things much easier.


I dont quite understand, what is program.s ?

In the gui / designer i give basic values to put into the field , for example 20.0 deg (as this is near room temp) however when the arduino switched to the page i see the display show 20.0 and then the real measured values, ie it goes to 22.3 for example and updates/ moves about from there. This is what im trying to avoid , seeing the 20.0 value initially

I need to update within arduno, send the value from there. The code/ method i use at moment seems fine for three values but i can use more. Its bizarre as i get problem with the display before i even run the routine that has the page 4/5 etc identifier.

I think your suggestion may well work but this would be a significant change of code for me at this stage. I just need to update a field prior to displaying the page

Program.s is a new element introduced in editor v1.60, allowing to define global variables and startup code. To enable backwards compatibility, the traditional global variables sys0 to sys2 are now defined there by default.

Do you have any idea why i seem limited in how i control from my arduino as described? Why it would hang withouth even running that code.

I am keen to not do procesing or set variables using the display processor. It is the arduino that needs to update fields

Normally and technically, there is no reason to hang when using more than 3 page addressed variables or components.
If your Nextion hangs though, there must be an error somewhere. Best is to connect the Nextion via an FTDI adapter to your PC and the Arduino, too, and to handle their interconnection via the Debugger/Simulator window of the Editor. Then, you can trace all the communication between them, including the Error messages which the Nextion probably sends and which the Arduino doesn’t trap. Doing so will allow you to locate the problem within minutes.

1 Like