Reading variables from other pages in Nextion HMI

Hi All,

Apologies in advance, I'm new to forums...

I am using a Nextion Touch Screen NX8048P050-011R-Y/NX8048P050-011C-Y (I think the Capacitive touch one). I have set up several screens for my project and am now starting to piece it all together. I will be using it in conjunction with an Arduino Uno. The Arduino will be sending and receiving, from, and to the nextion, mostly values. The Nextion does not do any calculations it just stores setting values for the Arduino to read.

The first part of this project I am just programming the Nextion screens so the operator can set the variables for the Arduino to read.

I have several screens programed, two of which are Operate and Settings.

On the "Operate" screen I have a gauge z1 which is just a static value on the gauge, it is to indicate a maximum position on the gauge Pic it is overlaying, On the screen "Settings" in n8 the value to use is stored.

My question is, what is the correct format to use when addressing a value from another screen. I just cant seem to find examples that work. I have tried, z1.val=page Settings n8.val (vscope for n8 and the "Settings" page is also set to global)
I get invalid variable page error.

It may also be beneficial to change the names of the pages to 0, 1, 2,,,, etc jus as they are at the moment they are easy to follow foe me.

I will most likely have more questions regarding this project but at the moment I am just trying to get the Nextion screen to function as I need it to. Then once it is all Ok I will start on the Arduino "Control" part of the jigsaw.

Thanks,

Jeremy

Hi @jlangel

welcome to the arduino-forum,

Your arduino should store each and every bit of data in the ==> arduino-uno-memory.
You should not rely on data stored in the nextion-display.

As a pre-test I would create a simple test-project with only two screens and test the principle on these two screens

I'm very sure that if you write it this way

this does not work for the following reason:
pagespaceSettingsspacen8.val

there are no spaces allowed in the syntax.

Example user-code

if(va0.val==0)
{
A.t0.txt=t0.txt //in page A, vscope of t0 must be set as global
}
if(va0.val==1)
{
A.t1.txt=t0.txt  //in page A, vscope of t1 must be set as global
}
page A

In programming each and every detail must fit to the syntax-specifications.
If you want really help even in your postings everything must fit to the syntax-specifications.

If I understand right you have a page where a value shall be adjusted and this value has effect on an element of a different page.
Let's name the pages setup-page and gauge-page

You can adjust a value on the setup-page that has effect on a gauge shown on the gauge-page.
Well as I recommended already to store each and every bit of data in ==> arduino-uno-memory you just this
storing the adjusted value in ==> arduino-uno-memory. and whenever the gauge-page is really displayed you assign this adjusted value the gauge-property

As long as the gauge is not shown it doesn't matter if some value for the gauge is "wrong" or not.

At the beginning of a nextion-project you have to make a fundamental decision about how you want to communicate with the nextion-display:

either
using the nextion-library
or
not using the nextion-library.

Me personal I prefer to not use the nextion-library because then I don't rely on the specificness of this library.

You can define the answers that were send to the microcontroller on your own in the user-code field.

by searching with this keywords
nextion access element of another page

I found this tutorial

In this tutorial they were using user-code

best regards Stefan

Hi Stefan,
Thanks for your help with this.
I have progressed a little further with my project. I have completed the Nextion screens and pages. I have been able to change pages from the Arduino by sending the same text as you would use when debugging the Nextion screen. As you mentioned I am only using the display to Send and Receive values to and from the Arduino. Any eeprom values will be saved in the Arduino.
This leads me to my original problem. I still can't get the correct syntax to change a val on another page. I have read many examples and posts but they do not work for me. If it is possible, can I send you my Nextion File for you to have a quick look at.

I can change the variables of z0.val if I do it in 2 lines like,
page 1
z0.val=200

Then... my next issue is being able to send a variable in place of the 200. For example the variable is pressure in Bar from a gauge and z0.Val is the gauge pressure value to display on the Nextion.

Not sure if this makes any sense.
I am hoping that once I get started with a bit of code the rest will evolve.

Regards,

Jeremy

Hi All,
I have managed to be able to change the values on the nextion display. The gauge z0.val had to be done different to the n2.val
One way of code layout worked for the n2.val but not the z0.val.
This is the way I made it work.

 //  Bar on Opperate Page
 //Serial.print ("n2.val=" + String(DforceBar));  // Will Change n2.val but not z0.val....
 Serial.print ("n2.val=");
 Serial.print (DforceBar);
 Serial.write ("\xFF\xFF\xFF");  //  This Works... for the end

//  Gauge on Opperate Page
 Serial.print ("z0.val=");
 Serial.print (DforceBar);
 Serial.write ("\xFF\xFF\xFF");

Regards,

Jeremy

(post deleted by author)

@rbutala
Don't hijack someone else's topic.
Please wait for the question to be answered in your topic.

Thank you.

P.S. Your post here is flagged for removing.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.