Start a new topic

Global functions

I'm building an application based on Arduino and Nextion, where the Nextion part is the "Master", which sends commands to Arduino, so Arduino is the "Slave", listening only to Nextion over TTL.

I'm trying to make some event-codes globally accessible from Nextion code or from Arduino over UART to avoid write the same code in different pages.

(I know, that the global variables let make possible to transfer information between pages independently from the active page. But I try a little more...)

I tried:

1. Place a button scope global on page with scope global, and place the "global code" into the press event. Then I'm calling  'click Globalpage.Global_Button,1'. It works fine, as long, as Globalpage is the current. Is not the current, I get "invalid component ID". But 'print Globalpage.Global_Button.txt' works. 

2. Global scope timer: I define the property 'en=0' at first. If I would like to call the "function" placed to the timer event, I let it enable: 'Globalpage.Global_Timer.en=1'
It works, as long Globalpage is current. Is not: No failure, but doesn't let it set to enabled:
'print Globalpage.Global_Timer.en' returns 0.

3. After the - for me - 2 possible solutions I try - from Arduino site - to change the current page for some msecs to Globalpage after 'ref_stop', but 'page Globalpage' refreshes the Nextion. I assume, that ref_stop is only for automatic "green property" based refreshing. So this is also not possible...

Anybody an idea?

Start with the following

  ref_star and ref_stop is command of Waveform.

So if not Waveform, ref_stop and ref_star makes little sense to use.

Use outside of intended waveform, is not really determined

  may or may not have effect, not  a bug if it does or doesn't

.vscope of global:

  - stores .txt / .val type values for component.

  - component remains not in memory when not current page

  - code in events of component - also not in memory if not current page.

sendme command will report Nextion Return Data of current page

   so that MCU is aware of which pages is current (place in preinitialize)

get dp command also returns current page - dp can be used Nextion side.


Thanks for the fast answer!
I assumed, the behaviour is more based  on memory limitations: What is actually in the memory, could only be accessed, without loading it with the whole page.

Memory limitation is

  Nextion side MCU is shared between

  • user HMI globals + current page
  • Nextion firmware
Nextion Compile message in Output pane
  states global usage + usage for compiled page

Order of 
  • PreInitialize Enent
  • Load page as per HMI design
  • Postinitialize
  • Wait for timer, command by serial, touch, gpio binding

Globals can be tested in Debug Simulator on non-current page
   - click page.component,1 for pressed
   - click page.component,1 for  released
   print page.component.attribute

When error occurs - not available globally.
  - a few changes in last few firmwares
  - but principle remains the same
Login or Signup to post a comment