Start a new topic

Timer with Nextion HMI Enhanced Model only

Hey guys.


I want to ask you if it is possible to create a "Timer" by using a Nextion HMI (Enhanced Model) only without another MPU.


For now, I tried to put my ideas into a the Nextion Editor and create something like a program. I used the "Timer" from the toolbox. But I am not very satisfied with the result. There is a delay or the timer is too fast.


Years ago, I wrote some small C-programs with functions, libraries or interrupts.

Are there such possibilities by using the Nextion Editor and an Nextion HMI or not really?


with best regards 

(373 KB)

The timer works better on the device hardware and certainly has known flaws in the debug simulator.

The Nextion Enhanced Models have an RTC (battery needed by user)

As I see from your HMI, you are already aware and using the rtc.

You have your timers on page4 at 100ms and 400ms

On page5, timers are at 1000ms and 1000ms

Your timer.tim values should perhaps relect an allowance for code completion

I am uncertain of what you are seeking - would you care to elaborate further?

If it is performance, there are things that can be done to improve your performance.

Is it these methods to improve performance that you would like to discuss?

1 person likes this

Thanks for your answer.

To be honest the timer1.hmi was only one of my first testing programs. The real task is to create a tool which is possible to show three timers at the same time. It is a part of project for my studies and I try to build this tool as small as possible. So, I try to solve the software part with the NX4024K032_011R. 

If it is possible or if you are interested or somebody else I want to show you my program but I don´t want to upload it for everyone till the project is done in January. So, I could send it in a personal massage till January and then post it in public if there are some interested people. But basically, I used the structure of the timer from the timer1.HMI.

The Problem is that the timer should be able to count down at least 4 hours. I tested my program for the project with a 5 minutes’ test and the timer was one second faster than my watch. This failure is too big and I can´t understand why the timer program is faster than a real watch. I used the setting 1000ms for the timer from the toolbox and then there is the program part which should take some time too. I guess one mistake could be the program part when the seconds or minutes reach 00 and move to 59 or the huge amount of if´s.

I am interested in your solution of methods to improve performance and I want to discuss some possibilities. But I am not able to say if this is helpful or not. I don´t have so much experience with the Nextion Editor and I am not the biggest fan of writing programs. I guess my writing style to create programs is very bad. So, if you have some good advice that would be great. But please do not misunderstand me, I am not asking somebody to finish my project or to steel somebodies’ ideas or work. I want to understand what to do to make my program better or to improve the performance and why I should do this.

One last question. @Patrick Martin I am wondering if you come from Germany. If you able to speak the German language I could write in English and German in this forum. I guess my English skills aren’t very helpful to explain my problems exactly. 

The problem you describe with inaccuracy is called drift.  It happens on almost every device with the exceptions of the atomic clock (which with the occurrence of the latest leap seconds over the last couple years, perhaps the atomic clock is also susceptible to drift).  You probably shouldn't stress about this, it isn't looking for 1ms accuracy.  The specifications on the RTC on the Enhanced Nextion models is +/- 3ppm as found in the RTC datasheet from the manufacturer.  So, fairly accurate. 

If all students are using Nextions, your instructor will not be grading the Nextion on how well its RTC held time, your instructor will be grading your ability to find effective solutions to the problem at hand.  With that in mind, I can reveal things that would equally benefit all Nextion users and not specifically to "do your project" as you have stated.  Everything I mention below, I have mentioned in various other threads on the Nextion board here.

The Nextion firmware is more of an interpreter processing the HMI design and is not straight compiled  machine code.  There are some aspects that take longer than others.

Fixed width fonts are just that - fixed width.  It takes time to draw the number of pixels for the Text or Number components.  Redrawing extra pixels for no reason wastes time.  So if the requirement is to draw two numbers, reducing the number of pixels needed to be drawn helps.  2 fixed width characters of 36x72 has wxh minumum pixels 72x72 or 5184 pixels.  A space of 121x78 is 9438 pixels or 182% of the minimum needed.  This potentially steals clock cycles unnecessarily.  Likewise .xcen of Center or Right and .ycen of Center or Bottom also requires more calculations to be made to find the proper positioning, where .xcen of Left and .ycen of Top can start immediate on rendering the two characters.  Smaller Fonts cover smaller area in pixels and therefore will perform faster.  Such is the same for 0 .spax and .spay and not using the word wrap .isbr

Text requires much more translations and many procedures to work with, where as numeric .val are faster and can occupy a register when required. So number variable out performs string variable.

Components (and variables are components) are processed in a huge lookup table.  But there are a few system variables mentioned in the Nextion Instruction Set such as sys0 sys1 and sys2 that are numeric and perform much faster that component variables.  sys0, sys1, and sys2 can be used to store values when changing pages or as a makeshift unseen parameter to another event.

Variables although they are a component, do not have a graphic aspect to draw - and perform faster than the number or text component counterpart. 

Hotspot Components have both a touch and a pressed event, also they don't have a graphic component.

If a hotspot is size wxh of 5x5 (minimum) and placed in a "non touch area", they will have little chance of being triggered.  This makes a good substitute to implement a subroutine.  If a hotspot has .objname of m0, then to trigger the code in its pressed event - click m0,1 or trigger its released event click m0,0

Using .crop images will always take longer to process than a simple solid background color.
If a background image is used and there are static items, perhaps incorporating the static into background image and foregoing needing to use additional components will use less clock cycles to complete.

In an HMI design, H stands for Human - M stands for Machine - I for Interface.  The Machine thinks in numbers, so where possible allowing the machine to deal in numbers will help speed things up.  It only needs to be translated back for the Human aspect _after_ the machine has completed with its numbers.
Time to a machine is generally an ever increasing large number, such as in systick.  It is a human thang that wants to divide it into various non binary parts.  In my Nextion Analog Clock (without an RTC), I revealed time as spd or "seconds per day".  The task in an HMI is to interface both these Human requirements and the Machine Requirements and optimize for each side "at the appropriate" time.

There is a b[.id] component array, although not documented well, more info can be found on it under the Nextion Gallery topic The Yet-To-Be Documented b[ ] component array.  It performs better as it bypasses the need to lookup the component .objname attribute and can position to the appropriate component with an internal startadd+sizeof(components)*id_value.

The useful modulo operator % is undocumented but is available.

The Nextion does not use complex expressions, but assignments can handle more than one expression.
Caution is needed to properly form your assignment expressions
The above is parsed on each operator and is equivalent to

These are some things mentioned by myself and others throughout the board and previously available to all Nextion users that aid in helping to increase a users HMI performance, so I don't think anything gets violated by consolidating some of them into a single location.

As for your writing style, that is not for me to critique, but rather for your instructor.  Every moment that you deal with the details under the microscope, the more you become familiar with them.  And even though I have may now have 26 years of long hours working with computers, there remains the fact that on my first day - I certainly didn't know then what I know now.

2 people like this

Thank you very much for your answer. Sorry that i answer so late.


I am the only one with the Nextion and a Task with a Nextion. The Task is to realise the project with an Arduino and an Nextion. The Nextion is new for my Instructor so he said that i can do it without the Arduino if the task is done right.


But All in all, your solutions and the collected one sounds great and are very useful for me. I want to try them on my Nextion project before I use an Arduino, because like I said I don´t want to waste space for an Arduino


I try to reduce my text blocks and paste them in the background or button pictures or try to use numeric blocks. 

As for the variables, I guess I could replace some variables with system variables. Especially if I use the modulo operator it will reduce my written code very much. The biggest help for me is the explanation of the assignments expression. I didn´t know why my expressions didn´t worked right in the past.

Hi my friend... It is possible to help me to add days in your project? And how to stop timer when values is 0:00:00 and not go - ?
generic code logic ...

    - if Value$="0:00:00" then stop timer



Thank you Gerry... And how to calculate dates?

 too generic, what do you like to calculate?

    - weekdays

    - day of the year

    - Julian DateNumber

    - calendar week of the year

    - days difference between 2 dates

    - which date is after 25 days 

    - ...

there are endless things out you can calculate and do with dates ... so, you should be a bit more specific ...

in page4 in hmi file example I add one field t3 and I calculate numbers. Now the user add there days. E.G 30 days...Now in page5 I add n3 field to go values there. My problem is the code in page5 > Preinitialize Event when values go there and I click start then days have 30 value but not counter ... Hours go -0 minutes it's ok and seconds it's ok...


cov chicken.t0.txt,va0.val,0 // Übergabe, Konv. der Sekunden eingabe
if(va0.val<60) // Wenn Sekunden kleiner als 60
{              // va0.val=konvertierte Sekunden Eingabe
n0.val=va0.val //konvertierten Wert übernehmen
if(n0.val>59)  //INÖTIG da hier nicht aktualliesiert wird
n1.val=va0.val/60 //es gibt keine Rest dievision
cov chicken.t1.txt,va3.val,0
cov chicken.t2.txt,va6.val,0
cov chicken.t3.txt,va6.val,0


when you follow the code line by line, you should find the error in your logic by yourself ...

I wonder, how variables can be counted up, when you always reset them to 0 ...  :-)

sorry, when you have an explicite date-calculation question, ok, but debugging your code is not a good weekend activity ... :-)

 i fix the code... now the only problem is when i add e.g. 48 in hours value the days stays with previous values and not go 2 days with calculation... and hours 0...


cov chicken.t0.txt,va0.val,0
cov chicken.t1.txt,va3.val,0
cov chicken.t2.txt,va4.val,0
cov chicken.t3.txt,va6.val,0


Hey hackertom. I think it should be possible to add days in this project. But to be honest i finished my project and didn´t work with Nextion Editor anymore. So unfortunately i can´t help you very much. If you want i can upload my finished project. But it is much bigger and there are german words and comments i it. And my programming skills are not very good. Actually i want to wait till i get the valuation back. But if it could help you i will upload it. 

You can stop the timer with an if structure as an timer event. Maybe there are better ways, but it works.

if(n1hour.val==0) // compare the actuall figures from your clocktime with an 0






      tm1.en==0 // deactivate the running timmer




It is basically Gerrys answer. I copied it from my project. I used for hours, minutes and second a seperate number field

If you want i could take a look at you project, but i preffer to see an HMI file to see the whole programm. But still i can´t promise to give an good or helpful answer.

hi @HRdt and thank you. upload it if this help me :)


and one more help... when timer ends 0:0:0 i want to send me a component ID in simulator return data for arduino move... it is possible??


Login or Signup to post a comment