Start a new topic

waveform, loop and double state button

My problem ist about loop… (While, if then else, for…), waveform (pass through data) and double state button.


I want to start an acquisition with a button, receive continuous pass through data and stop it with the same button. Imagine I want 100 hundred values, for little reason I need to stop it before the reception of entire values…


I didn’t find any solution… Is it possible to have interruption with gpio??



Refer to the Nextion Instruction Set

addt command can be set to have 100 bytes sent through

 - must wait for the 0xFE 0xFF 0xFF 0xFF to be received first

 - then send your 100 bytes

 - wait for the 0xFD 0xFF 0xFF 0xFF to be received

 - proceed with rest of program

 - if 100 bytes requested in addt stream, 100 bytes are needed.

   Waveform will not move on until after requested amount is sent

the doevents command tries to prevent HMI from hanging.

 - a while loop will not update until completed unless the

   doevents is used - see while command in Nextion Instruction Set.

GPIO is generally digital data, but interpreted nature of HMI sets

GPIO to be reasonably slow, not for high speed.

 - to get GPIO as trigger with inbound binding as loop control will be a fair amount of playing. 

Good to have a analyzer when debugging timing issues

the other way is to work wit addt 1,0,1 function in a loop.. The condition to start the loop is a double state press button. The first impulse let the button in press mode and the second press release it. But it doesn't work....


You have to think in Single threaded Sequential processing on Single Core.

I don't really understand doevents function in while or for loop. Could you give me an example, please.

What does it means "isbr" in buttons?

Is it possible to create this function while (bt0.val==1 && .......)?



Please Refer to the Nextion Instruction Set

  Compound expression is not supported so && in a compare fails.

  && is not listed in Nextion Instruction Set - so not supported

doevents allows to monitor other events (such as touch/updates)

Sequential processing goes line by line

A doevents function call inside of a loop looks for other events

   examples are in while command Nextion Instruction Set

isbr ... where br is a linebreak .. isbr true is to support multiline.

do i try doevents to check the state of an another double state button to stop my loop?

do you think that it was possible to do what i want?


i saw that nextion developpe intelligent system. What can you find on this new tft's?


I need to address GPIO interrupt

void function () {




void loop(void) {

   a expression

   b function

   c expression


Sequential programming is going to do





  handle serial and other flags

  and then back up to loop.a

Interrupts on Nextion are Serial and Touch

In sequential processing on a single core

a microprocessor can only do one thing at a time.

For GPIO binding to a component, has to reach an end of loop and then handled with flags segment

When your programming is doing a loop, it is doing a loop

 - it can not be doing multiple things at the exact same time.

 - once it finishes with what you requested, then it can move forward

The doevents is like a branch out to function where it can check on other things

  but still sequentially processed ... timing becomes different

But for it to handle other things, it has to leave your while loop

You will need to play with getting your desired effect with your code

Can it check another dualstate button? No doevents is more on refresh and update

If your code is not too intense, perhaps using a 50 ms timer can help

But this is mostly general speak, without exact details hard to expand on

Unfortunate that some sellers use the word intelligent to sell T series Basic model.

Intelligent as in the Nextion is "smarter" with MCU than a dumb TFT without MCU

A practise I would prefer stops as it is very misleading, but no control over.

 bt0 start addt..... normaly i wait for 420 data. After each addt 3,0,1 instruction (one data at a time), i put a doevents , put a 100 ms time and check the state of bt1 and put 421 in no.val to end the loop

(10.4 KB)

 this is my program

(10.4 KB)
(3.53 KB)

No need to use addt 3,0,1 ...

As stated in the Nextion Instruction Set and explained earlier

 each addt will cause

    0xFE 0xFF 0xFF 0xFF before

    0xFD 0xFF 0xFF 0xFF after 

If only one data point in data bundle use the add command

Back to sequential processing

 - bt1 can not really be set and run while in loop of bt0 code.

 - bt0 code has to end first before

It's like trying to force it, but in the wrong manner.

Delay=100 is bad to use unless you mean to do delay

  - delay means "do nothing, absolutely nothing" for 100ms

If bt0 is a start and bt1 is a stop/pause

  perhaps timer at 100ms (other code still runs between timer events)






      add 3,0,1






bt0.val press event



(10.7 KB)
but with add command you cannot receive data from uart


the add command can indeed to sent over serial

Decide if MCU is in control, or if Nextion is in control.

Which ever is in control should send the add/addt command

It is easy if MCU is in control to have MCU respond to button press event

In HMI design bt0.val check off Send Component ID in Touch Release

In MCU code listen for 0x65 0x00 0x01 0x00 0xFF 0xFF 0xFF

(0x65 touch, 0x00 page0, 0x01, 0x00 release, 0xFF 0xFF 0xFF termination)

on such a received event trigger function

  Either with add

    byte ter[3] = {255,255,255}

    for(x=0;x<data_points_to_send;x++) {

        Serial2.print("add 3,0,");




  Or by addt

     byte ter[3] = {255,255,255};

     byte respFE[4] = {0};

     byte respFD[4] = {0};

     byte y, x;

     Serial2.print("addt 3,0,");



     while (Serial2.available() < 4) {    }

     for(x=0; x <4;x++) {

        respFE[x] =;


     // check that respFE is 0xFE 0xFF 0xFF 0xFF




     while (Serial2.available() < 4) {    }

     for(x=0; x <4;x++) {

        respFD[x] =;


     // check that respFD is 0xFD 0xFF 0xFF 0xFF

Something in this manner.

But think sequentially ... one step is after the other

   only one thing can occur at a time.

addt shouldn't be issued Nextion Logic side at all

 - what if data in points requested never comes

     Nextion will hang forever until data is received.

 - also note the overhead and delays for addt when only one byte to be sent

Login or Signup to post a comment