Unofficial Nextion/TJC User Forum

Updating fields before page is displayed

Hi All,

I have some graphical status indicators on a page of my Nextion project that are controlled via the Crop component. I’d like to set these before the page is actually displayed, but can’t seem to make it work unless the page is already active.

In the Debug environment, this works:

page 1
MainPage.q1.picc=3

This does not work:

MainPage.q1.picc=3
page 1

So, is there a way to have elements on a page set before the page is actually displayed?

John

Can you use a global variable?

Hey Traxxtar,

Yes! Thanks for pointing me in the right direction! I changed the ‘vscope’ property of the Crop elements from ‘local’ to ‘global’, and Voila!, it works like I want it to!

I’m just getting going on my first Nextion display project, so I appreciate the time it took for you to answer my simple question!

John

1 Like

Yay! Glad to know it was helpful. Have fun with your project.

1 Like

If it is just about doing it before it’s displayed, you could do it in the “preinitialize event” (click on the background to modify it). This part is executed before anything appears on the screen when loading the page.

Be careful with global components. A component has many attributes, all of which become global and take up space. This might not be an issue with smaller projects, but I’d consider it good practice to make only variables global. Those only have one attribute, their value. You can load the value from the global variable to your component in the preinitialize event. Not too much additional code, but a lot less RAM used.

What do I mean by “a lot less”? Take a simple number element. It uses 24 bytes of RAM, because it has not only a value, but also a font, a background color, a foreground color, a length and many other attributes that become global, too. A (numeric) variable takes up 4 bytes (since it is a 32bit variable).
When does it become an issue? Let’s say you want to keep 2/3 of your memory for the local components. That leaves 1/3 of 3584 bytes of RAM for global components. divide this by 24 bytes per global component and you get a limit of 50 global components. Sound like a lot? That’s 5 global components on 10 pages. Not that much actually. With the 4 byte variable you could have 300 global values instead. Isn’t that a much more comfortable limit? :wink:

Kind regards,
Max

2 Likes

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).