Start a new topic

assign variable to a number/text


using a 3,5" display with Nextion editor V0.47

One question:

I have some variables (e.g Temp1; sta=string), that are written from an arduino.

Now I want to show the value on a page.

For this I inserted a textfield (T1) on the page, and write the value into the text with the "Preinitialize Event" of the page. (T1.txt=Temp1.txt+"°C")

Is there a better way? Can I assign the value directly to a textfield?

Taking number instead of text won't work, because I use one decimal (22,1°C)

regards brutzler

a textfield is nothing more than a string variable with visual property ... so, just assign ...


I do not really understand, what do you mean with "assign"
- Shall I awrite the value directly to the textfield from the arduino? And do not use the variable any more?
- or is there a possibility to link the variable into an attribute-field of the textfield?

you don't understand your own posting?


    - "Can I assign the value directly to a textfield?" was your statement ...

just try it out ... much less time consuming than write postings about ...

or do you fear your display? :-)

... much less time consuming than write postings about ...

uhh...sorry for asking and wasting your time. will not happen again.
I will try to help me for my own, if my questions are so funny.


Your Titel:   

    - assign variable to a number/text

Your Initial Posting:

    - Can I assign the value directly to a textfield?

My answer:

    - just assign ...

Your answer:

    - what do you mean with "assign" ... <umpf, what can I mean with?>


uhh ... your posting is not funny, more like a bit shameful ... you even don't understand your own initial ...

Programming has a hundred ways to accomplish the same task.

When the result is correct and as you wish,

   then technically the task is achieved.  Be happy.

If this be with or without using a Variable component 

   that choice is yours, and up to the programmer - many styles

  - and hence, there are a hundred ways to accomplish

A better way?  better for whom?

Better for me doesn't necessarily mean better for you.

As the programmer you must be able to think and follow your logic

  and not necessarily be trying to follow my logic

Why a text component or a variable component is a logic choice

  there was a logical reason to include it no?  Be happy.

As your program grows in complexity, it will be your logic that

   you need to unravel and follow, this is your reasonings.

As you read through the forum, you will notice there are several styles

and probably 50 posts for this exact thing of assignment to txt attribute.

My opinion

   t0.txt="Hello World"ÿÿÿ or page0.va0.txt="Hello World"ÿÿÿ

   should not require 50 postings on such

   Examples exist in Nextion Instruction Set, in threads ...

But perhaps when it works, be happy, move on to next task.


I am able to do such things like you posted: .... t0.txt="Hello World"

Would have been a great thing, if you answered this question from me:

>>- or is there a possibility to link the variable into an attribute-field of the textfield? <<

What do I want to know?

I have several pages. On every page there is a text-item. Now I want the display to show the same text on all items.

One way would be to write the same string to all text-items:

- page0.t0.txt="Hello World"

- page1.t0.txt="Hello World"

- ....

Therefore I thought, the better way is to write the string to a variable and distribute the information on the display to all pages. But how?

The only way I know is to do this in the events of a page.

- t0.txt=var_string.txt

Thats working, but only on entering the page. If I want to change the text without changing the page it doesn't work.

I hoped there would be a possibility to put a pointer on the txt-attribute of the item, that referes to the variable.

Programming has a hundred ways to accomplish the same task.

   If it is updating when you enter a page but not later,

     the clues suggest you (the programmer) put in the PostInitialize Event

   It will only do as and exactly as told to do.

As the programmer you must be able to think and follow your logic

   You told the MCU to update based on condition page now loaded

    - now update the t0.txt, and it did.

   It will not make updates without being told to make the updates.

The link to the component attribute (va0.txt, t0.txt) is the component attribute

    t0.txt= blah-bla-blah

    linking two component attributes needs an exacting assignment to happen



So the possibility is always there, as you chose to implement.

All components also have events, not just the page.

But more importantly, the temperature comes from the MCU

 - so you may want to ponder the MCUs role in your project.

The Nextion is more than capable of informing the MCU 

  - which page is the current page, because non-current is less useful.

But the MCU need not be informed by the Nextion

  - the MCU is more than capable of querying Nextion for current page.

One only needs to refer to the Nextion Instruction Set.

My point of there is already around 50 topics open for this topic.

 - Is it not a waste of space to duplicate it all again?

For me to type it out all again, hmm - maybe no one reads it

 - I see same question asked again, but already answered.

So which is a better way,

    sensor - MCU - Nextion Var - page0 Text, page1 Text, ...

or for the MCU to track which pages is current

    sensor - MCU - currentPage Text (no complexity of distribution)

What is the trigger for the update?  Must be a reason for an update.

    If you try to follow my logic, then it is my program?

    You following your logic, you should be able to follow your thoughts.

    But again, is not the source of the data the sensor?

    - if the value hasn't changed, then even with no update the data is correct.

    - is it not only if the data has changed that an update is needed?

   And this change or no change is known first at ... sensor reading?

What is used for a trigger to update when you which to update time?

   And within that "event" you make necessary assignments to update

   - then is such mechanism not also a viable and reusable concept?

Programming has a hundred ways to accomplish the same task.

As the programmer you must be able to think and follow your logic


If I want to change the text without changing the page it doesn't work.

One possible solution is to use a timer, see post 5 on this page:


Programming has a hundred ways to accomplish the same task.

As the programmer you must be able to think and follow your logic

Yes, I am with you. But for this I must know what is possible in the programming language, that I am actually using.And this I wanted to figure out with my posts.

But the thread is somehow pending to philosophic.

Basicly I am a PLC-programmer. And here it is usually to talk from the µC to variables. (Normally all variables get a cyclic update from MCU). These variables are assigned in more or less pages to visible items. The Update of the values in the pages is done in the Background. No need for the MCU to know what is the active page. This is the difference here. And for this I am looking for a roundabout.

@ Raphael; Thx. THIS was constructive!

HMI is Human Machine Interfacing 

 - Human Interaction: Request notifies the MCU

    MCU decides, takes action if apropriate

 - Machine Status: MCU updates the Display.

What is possible?  Too vague - so much is possible.

   Component attribute assignments

   Commands in Nextion Instruction Set

   Globals attributes (.vscope) + Page component attributes

   Every attribute green in the Editor read/write, else readonly.

   Enhanced have

       8 Digital IO, 4 PWM capable (low res, low speed)

       RTC Nextion side, 1K EEPROM

   Max attribute code lines 65534 (space permitting)

   Nextion side STM32/GD32 at 48/72/108 MHz (model dependent)

   Font and Picture Resources Nextion side (high speed draw)

   Basic GUI, line, fill, circle, pic, cropping, dynamic text

   No floating point - integer based   56000/20000=2

   No compounded expressions

   No order of operations (left to right on operator)

   Multi-operator on assignment (as long as left to right)

   Nested if else

   for and while loops

   triggers for event code via command or gpio binding

   Press/Release via 0x65 Return Data

   Current Page via 0x66 Return Data

   Coordinates via 0x67 and 0x68

   Sleep mode for low power

   Nextion builtin framework via Return Data

     - Send Component ID triggers 0x65 on touch

   print and printh allow for complete user defined protocols

   ZI Font matrix can be customized

   Final HMI design is interpreted, not machine code

   Up to 6 timers

   Maximum of 4 waveforms per page up to 4 channels each

   250 Component Max per page

   200+ pages possible (dependent on not running out of resources)

   Video/Multimedia/streaming not a fit

   Dynamic Picture over Serial possible, not efficient

   Serial over GPIO done, not efficient

   Metrowide mapping for GPS done to 5m accuracy 1/14400 degree/pixel resolution

   1200 item menu

   Floating point 4 op Calculator - no MCU

   Moving sprites

   Font based icons within mono-bit

   I've made a multi tuned Player Piano with PWM in Nextion logic - no MCU

   On screen Keyboard entry to Morse Code output

   With press/release triggering, any press/release event is a function holder

   System/Global Variables make parameter passing possible

   Basic animation, logic, illusion

So as a programmer, you'd know possibility is in the ordering of instructions

Most is up to the imagination

  - though most imagination is out of scope to an HMI concept

Variables, Loops, Conditional Branching, Timers, Digital GPIO, Touch

  - lots is possible.

The Gallery and threads linked from the Gallery show some of what is possible

Other threads in Free Chat show some of what is possible

So from a title of assign variable - yeah, philosophic is all there is without details.

I will argue for the MCU knowing which page is current.

In a 1500+ component HMI design over many pages

- the basic mcu side framework defines a counterpart to component

This in many cases will consume more MCU side SRAM than many MCUs have.

As such knowing which page is current allows for

  only the necessary components to be loaded in MCU side SRAM

  while the corresponding HMI page is loaded.

This approach matches more to the Nextion HMI design

  when non current HMI side pages are not in Nextion memory

So if they are inaccessible on the Nextion side,

   does it make that much sense to have all loaded MCU side.

I should add the six timers are interpretive

- so this means a trigger, execute the code, set the counter, count down.

this is not going to provide a high res timer,

this is not going to provide a code interrupt to execute the timer code.

So a 400ms timer really depends on how long the tasks inside the timer take.

   it is always lapsed code execution + counter, so it varies if there is a branch.

Nextion side timers are not going to act as MCU side timers, or PLC.

But the quickest way to a functional HMI is using the 0x65 Return codes

  Component press or release Send Component ID, and MCU side handling

The MCU can easily capture the 0x65 page component touch

  and react knowing which component on which page is pressed/released

In this manner, Nextion side HMI can be accomplished in hours

  Graphics work will always be a time consumer for a good look a feel.

Then all that remains is the MCU side coding.

Although the Nextion is capable of Nextion side logic,

   one has to consider where the logic is done, Nextion or MCU.

When logic is one side or the other, maintenance isn't so bad.

    When logic is in both, not only would maintenance be complex

    but conflict of which is in control becomes a legit question.

    - hence which side updates a dual-state?

    is MCU slave to the Nextion, or is Nextion Human Interface

    and the MCU is in control of the machine sending Status.

Especially as the project grows in complexity.

There will of course be many opinions and styles on how to do

    as there are several ways to accomplish a given task

Login or Signup to post a comment