I must say that I'm not verry experienced in programming, but I have learn a lot, since i've got the nextion display and iteaduino board. I have experinced a problem that I can't solve and need your help.
I, have created a project with 3 screens, on 2 of the screens i created dual state buttons. For now I have programmed only the button on first site, so that it lights a LED on pin 13 when TRUE. Moving trough pages is created with buttons in nextion editor.
Here is what i'm dealing with now. Everytime i power the UNO and display, i start on the first screen and the dual state button has a default state(OFF), I then change the state to ON and the LED lights up. If I move to any of the other screens, and then go back to page0, the LED stays on, but the state of the dualstate button is back on default state like in the beginning.
Thanks for your help in advance.
bumping this thread, I have the same issue...
Is there a way to retain the status within the nextion software or do you need to update all values from the main (in my case arduino) program on every page change?
I am still confused about this. I have built an application that has 2 pages and will probably go to three. I am using Number Components to display live data from the controlling program. All of that works well. However, as mention above as I go from page to page I loose the information that was previously in the Number Component. I do have all the devices selected as Global. In Gerhard's example It is unclear to me how I would apply that to what I have. My controller is a 16F887 PIC and the code is written using Mikroc Pro.
For the most part the main loop of the program calls different functions that read the HMI buttons and then send the received data to the control. Also there are A/D channels in the controller that process data from sensors and sends that info to the Number Components. Not all the Component are on the same page. Making in necessary to switch pages. I can post all the code if needed.
Please understand that an HMI page not the current page is not in Memory
It is useless to update a variable that is not in Memory.
However, setting a Components .vscope to global stores it's .val and .txt
This facilitates being able to access values on a page that isn't current.
Global variables are generally prefixed with their page to fully identify them
when the page they are on is not the current page.
n0.val=32 will update n0 of the current page, perhaps not what is intended
page0.n0.val=32 will only update the n0 of page0, more specific to what is needed.
- but n0.val on page0 has to have its .vscope set to global in the HMI.
I currently control it completely from the Arduino, so suppose you click a button on the screen, this sends the component ID to the arduino which then send a command to change the page and commands to update all values in text fields or status of toggle buttons.
But am also going to rewrite this as it is not the most efficient...
Not sure what you exactly want but you can create variables in which you store the data from a text field. If you declare this variable as global you can read it again on a different page.
I use it to show the version of the nextion GUI on a settings page:
va* are three variables that are declared in the home page and I update the value when I compile the software that I am going to use.
hope it helps.
Got it !! Thanks guys. Here is what I did:
UART1_Write_text ("n9.val=") ; //send value to number Component
UART1_Write_text ("page1.n9.val=") ; //send value to Number
UART1_Write_Text(reg2); //Component on page 1 );
.n9 is on page 0 and page1. with this code both page0 & page1 are updated and when I select one page or the other on the HMI the values stay as they should. n9 is has it's vscope set to global. Not sure if there is a better way to do this but now I can move on to the next bump in the road. \
Great device, tools and unbelievable support
Hey Jim, I want to present a concept for global variables.
Adding a variable component on page0
change its .objname from va0 to reg2
change its .vscope from local to global
UART1_Write_text ("page0.reg2.val=") ; //send value to Variable
UART1_Write_Text(reg2); //Component on page 0 );
This requires the value to be sent over serial only once.
To use it on both pages, add the following to each Page Postinitialize Event
If updates are often while on the same page
components being refreshed can be placed in say a hotspot m0 pressed event
// other values to be refreshed
to trigger the refresh you could either send
click m0,1ÿÿÿ over serial or put click m0,1 in a timer event.
This is just to demonstrate global Variable components - some extra considerations
@Patrick, any idea why we should not set all components global?
As Gerry states - you will run out of SRAM.
The normal HMI page dumps the old page to load the new page.
Every global then takes away from available space for your HMI pages
When you build your HMI project, you will see how much globals are using.
The other reason to not use all globals would be an increased lookup time
that can slow your HMI at runtime, so use globals only as needed.
after posting I looked up the int mem value (it says 3584 Bytes on the nextion site) that is ineed not much :-)
Thx for the tip that the global mem usage is shown in the compile window, currently 166 :-)