Start a new topic

Touch Button - no response if no delay in Arduino

Hello,


i have a problem with my arduino due and  the nextion 3.2" display.


i.e. i have a main menu with 6 pages/buttons and each page has a back button.


when i enter one of this pages i have a switch case scenario in arduino.

so far so good, i enter one page, the case starts.


but now if i do something like a counter i++, in this case up to 2000 or whatever, i don't get a touch button feedback when i exit this page touching the exit button.

Display switch to main menu but arduino had no feedback from Nextion display that page was changing.

A text output in the sketch is updating a text with the counter value at the display.


if i do a delay in this switch case of the counter most time i get the serial feedback of the display. but not all the time.


that means, the counter is still running because there was no detection that the "back-button" was pressed.


In Nextion Editor, i checked "send component id" when touch release.


Then in Arduino:


 

void page1PopCallback(void *ptr)
{
  NexButton *btn = (NexButton *)ptr;
  displaypage=1;
}

 "displaypage" is the switch case


and here the "back" button for page 0 where nothing should happen (no counter)


 

void page1_1PopCallback(void *ptr)
{
  NexButton *btn = (NexButton *)ptr;
  displaypage=0;
}

 

and yes in loop there is "nexLoop(nex_listen_list);" ;)


Can someone tell me how i can do it, that the touch signal will always arrive at the arduino?


Thank you very much


I added support for page change events, and back button logic using global variables. On page initialize (nextion) I put the sendme command. Then my version of arduino code has a event that calls a function pointer. I am posting from my phone so it isn't easy to gather all the links. But search around for posts by me and you'll figure it out.

So here is my example:  Put the sendme command on all of your pages.  Then when a page is loaded it will send the page number over to the arduino.



in my branch of the arduino code (here) I added support for events on pages.

  

NexPage HomePage = NexPage(0, 0, "Home", NULL);
HomePage.attachPush(vUpdateScreen, &HomePage);
void vUpdateScreen(void *ptr)
{
    switch (((NexPage *)ptr)->getObjPid())
    {
      case D_HOME:
          vUpdateHomeScreen();
          break;
    }
}

 Notice my NexPage has an additional parameter, this is for my Value Change feature.  This allows objects such as the slider to automatically create an event and send the value, which will get stored directly in the variable to point to. 


2 people like this

Thank you very much for your answer.


I allready downloaded your version because i saw that you have some very nice and usefull features. but i have an error when i try to compile a sketch.

"application.h" is missing.


NexTouch.h:20:25: fatal error: application.h: No such file or directory

 #include "application.h"


Can you help me?



Got it :)


But can you explain me what the extra value at the end of Touch or Gauge or Progressbar is doing?

is it the value i want to send to the Nextion? so i don't need to call it again in my sketch?


FYI:

application.h for Arduino should be

#include <Arduino.h>


and in Nexgauge.h Line 36 the , void *value is missing but it is double in NexHotspot :)




1 person likes this
I ported this to the particle photon, and rhea use application.h, oops! I think right now the values will get written from the nextion to the arduino pointer. I don'T believe I had a chance to implement pushing the value back up to the nextion. A's for the value, it has to be 32 bit because the nextion sends 4 bytes. My plan was to implement strings so nextion could send you the string to write to the pointer too.

Ah ok, but it was not a big deal with the application.h


But my problem still exists.

If i have a counter with low delay like 100 inside a switch case, most times the serial signals of nextion do not arrive at the arduino.

I use the due at programmer port and the nextion at serial2

There should be no interrupt i hope.


For me, that means, if i want to update values very fast at the nextion comming from Arduino, it will work, but changing pages and stop reading the values will not work because my Arduino does not know that the Nextion changed the Page.

This is very very bad.


Only good for slow applications.


But i still hope it is an issue what i did, that there will be a solution ;)

Have you tried to increase the baud rate? Perhaps some extra bandwidth would help. Also look at the debug and see if your getting corrupt data. Maybe it doesn't notify you of that but it can always be added.

Thanks for the Tip.


I hope i did it the right way.

Just entered in Nextion Editor on Page 0 in usercommand:

bauds=115000

This should set the baudrate default to 115000

I had to change my serial communication to 115000 to see real text.

So i think it was working.


But nothing changes.


I think it is not a problem of the serial connection.


Here is the debug log:

 

recvRetCommandFinished ok
recvRetCommandFinished ok
recvRetCommandFinished ok
recvRetCommandFinished ok
recvRetCommandFinished ok
recvRetCommandFinished ok
recvRetCommandFinished ok
recvRetCommandFinished ok
recvRetCommandFinished err
recvRetCommandFinished err
page cmd:0
recvRetCommandFinished err
recvRetCommandFinished err
recvRetCommandFinished err
recvRetCommandFinished err
recvRetCommandFinished err
recvRetCommandFinished err
recvRetCommandFinished err
recvRetCommandFinished err
recvRetCommandFinished err
recvRetCommandFinished err

 Here i update a text with delay of 50.

all these "ok" is fine.

Then i change the page to 0 (MainMenu)

i receive the page command "page cmd:0" because of the "sendme"

But it looks like this does not bring up the arduino pointer to change my switch case. It should set my switch case to displaypage=0 which means the counter should stop

 

void page1_1PopCallback(void *ptr)
{
  NexButton *btn = (NexButton *)ptr;
  displaypage=0;
  Serial.println(displaypage);
}

 

But the variable does not change and i have no response in my log like "[537332224:1,1,b0,(null)] "


Can i grab this "page cmd:0" which will be sent out by "sendme" and use it to detect the changing of the page?

I tried:

 

if (Serial2.available()) {
    Serial.print("Here comes the Serial2 Input: ");
    Serial.println(Serial2.read());
  }

 But, the most time nothing happens here.


Other idea is to read this:

recvRetCommandFinished ok

and if it is not ok but err, then i know it is not at the same page anymore.


But how to use the debug information at the arduino sketch?

OK, now everybody can call me stupid ;)


Sometimes it is very good to read the documentation :)


in case some others have this problem.


use the boolean result of the value you want to update. i collect the false result and if it is 5 i go back to the case i want.


Everything is good now! I am very very happy :)


But i found a bug, i will write later in the bug section. Only a small bug, updating wrong text value on wrong page which was never declared. Strange.

Alex will you explain how you fixed it thanks

This thread is over 1 year old.


Fix probably came with many revisions of the Nextion Editor

- better communications

- faster processing

etc.


At a year old, such users are doing other things now ... no?

and indeed he already did ...


"Sometimes it is very good to read the documentation :)"

 

Or perhaps actually read the thread to see what happened

 - Alex read the documentation

I have the same problem, and such forms to help others resolved similar bugs, arduino due maybe the problem here.

Login or Signup to post a comment