Start a new topic

Global button

Hello. Please hint whether it can be a global service element "button" in the Arduino. I mean, if you can define as "b0" to confirm the release of touch receive regardless of the number of the currently displayed page. I have a project where three pages are the same buttons ....

Best regards


actual button component from a non current page will not be in memory. events not available

Global stores the .txt or .val attributes for access, but the rest is not actually in memory.

Design accordingly

Do I understand correctly? :

1. I have global button on page 0. sta = crop , picc=0 set in "Attribute" window.
2. In debug mode I change: picc=1. 

 3. then I go to page 1, then return to page 0

What picc will I see on my button?


In fact it looks like a bug, when I return from page 1 i see picc 0, but when i press button picc doesnt change (like it was 1 and changed to 0).


PS: I do not want to use dsbutton in this situation because I want to redraw it on arduino side, not on display. As Steve said : "There is no need for a DS Button in my code either, if you modify the section you can emulate the same and it's always in sync with Arduino True/False Stop/Start Red/Green whatever...

What Nextion 'knows' is irrelevant, it's just a dumb display "

Nex File in attach

(626 KB)

What is your question?

1.  Is not of understanding, may be of-fact,

2.  Again, not an understanding, possible fact

2a)  exhibit is Touch Press code - material? yes/no?

3.  Rhetorical Question?  What did you see?

Your Question ...

   What picc will I see on my button? 

Answer as per your HMI design should be pic 0

But really what is your question?

A) if trying to do by Nextion Logic, you have not done so correctly

B) if trying to do by MCU (as Steve points to ... then MCU will change)

Both require you to set your code, but select one method to do so

Button has a .txt attribute - as such, global button will store .txt in memory

Ok lets make this clear :)

Question is: will global button remember picc param changed from 0 to 1 by code on press event after I leave page 0? 

I assume you have answered: no - because of my design. 

Then I ask for advice.

What I attempting to do is:

Button is pressed by user -> MCU recieves that press and sends command to change picc (now code does that for MCU) -> picc stays changed (1) until user press it again. 

Now it does not stay changed if I go to another page and return back. 

Using DSbutton in described manner (but changing val parameter instead of picc) works fine. 

I mean ds button changes val param itself when pressed and its state is saved globally.

There should be no assumption on this as facts are given right above your post.

actual button component from a non current page will not be in memory. events not available

Global stores the .txt or .val attributes for access, but the rest is not actually in memory.

Design accordingly

Yet you still expect an attribute to persist across pages even when told it cant persist as it is not stored.

Every page change dumps the existing page from the 3584 bytes of available sram

So that it can make room for the new page in the limited amount of sram.

Everything goes out the window, except for ... .txt and .val stored in the global section

What is the Page Preinitialization Event and the Page Post Initialization Event?

Well, the order of operations

   PreInitialization Event of loading page is run before the dump

   Then the existing page is dumped to make room for the new page

   Then the Page is loaded in from spi flash as per your HMI design

   PostInitialization Event is run after your loading page is loaded

   Then Nextion waits for one of

       Touch Event, Timer Event, Command coming in over serial.

       (and if you had the Extended K model, also a gpio binding event)

So if you wanted it to persist in the HMI

  in the Press Release Event just before the page command to change pages

  you would manually store what you need to persist into other global variables

  In the Preinitialization Event, you would ensure any other values/procedures

  The page then loads from your HMI design stored in SPI Flash

  and then your Postinitialization Event would adjust your design to reflect

  those items that you wanted to persist.

If you wanted to have it persist via the MCU where every press you toggle

   the value and that is in a global scope on your MCU side

Then you need to catch the page change 0x66 Nextion Return Data.

This is triggered only by the sendme command  When this 0x66 Return Data is

received, you can then see that your page has changed and then have your routine

send values (as Steve pointed to) to update the components that aren't persisting

- thus placing the control of the updates in the hands of your MCU.

But a Button component is perhaps the wrong component to begin with.

  - the .picc attribute is for what is shown when not pressed

  - such a component is momentary

  - there is no press occurring to have it hold to the .picc2 values

If all you are doing is toggling between two states with pictures

  - then you might even want to consider a Picture Component

The issue with the DualState is that it is changed from Nextion logic

  - regardless of if the MCU was able to carry out the requested tasks

    associated with the state change - meaning you will have to check

    this state MCU side and send status updates to reflect actual state.

But I suspect first you must really determine if Nextion or the MCU has control

and then design your HMI and MCU code accordingly.

1 person likes this

PS: Earlier, your question wasn't really a question

 - you already answered your question when you observed it not persisting.


MCU has control in my project. And I sincerely believed that global state saves all attributes across the project.. Now I have to redesign half of it :'(

Thank you for making things clear!

Good news, bad news:

Some attributes may indeed be enhanced across firmware versions

as the newer Nextion Editor versions come out. I don't know which or the when.

I can see in version v0.46

The Picture Component .pic attribute persists.

I have not gone through to test all, but debug will show which

I downloaded your HMI.

With very few changes you can get it to persist without a lot of component changes

b1 Touch Pressed Event code  - change to:




Page PostInitialize Event



Add numeric Variable component called va0

Now what is to persist is the .val of Variable va0.  (No issues ever on global .txt or .val)

button b1 toggles this va0.val

and page Postinitalize restores this, adjusting from the HMI design after loaded

(627 KB)

That is just what I was thinking about. Change button state using variable object. 

After all I decided to use crop image instead of button. Picc parameter presists if vscope of crop is global, It is the simpliest way.

 Then it should not say this when you click on vscope in the editor

local = visible in current page global = visible on all pages.

"visible" is the wrong word.

It should say "local = attribute is accessible in current page global = attribute is accessible on all pages"

Getting someone who speaks English to review this might help.

When reviewing scope in any programming sense, this is used in a proper manner.

However, only reading partially and expecting different is always in the wrong manner.


This clearly says Variable scope, referring to the values.
 - trying to twist this into component replication on all pages is poor logic.

But this fully-reading-within-context would also apply to many things:

Such as when the Nextion FAQs state that ticket support is for Hardware issues

 - this does not mean to use tickets for Queue Jumping for preferential treatment

Or fully reading the existing thread to see it is related to component declarations

   for the Iteadlib Arduino Nextion Library for Arduino MCU side coding.

Having an English reviewer most likely will never help for such

   users will still not read what is already written

Login or Signup to post a comment