Start a new topic
Solved

Nextion Text value Read Bug

Hello,


I am running on simulation.

I have a page with 3 text (t0, t1, t2)




I have attached a pop on page post initialize and i am reading the texts


void getPIDValues() {

  getPID_P_Value();

  getPID_I_Value();

  getPID_D_Value();

  SaveGainsFile();

 

  Serial1.print("P ");

  Serial1.println(Settings.PID_P, DEC);

  Serial1.print("I ");

  Serial1.println(Settings.PID_I, DEC);

  Serial1.print("D ");

  Serial1.println(Settings.PID_D, DEC);

  Serial1.println("==============");

}


void getPID_P_Value() {

  char buff[17] = "";

  while (NexText(8, 5, "t0").getText(buff, 15) == 0) {}

  Settings.PID_P = String(buff).toFloat();

}

 

void getPID_I_Value() {

  char buff[17] = "";

  while (NexText(8, 6, "t1").getText(buff, 15) == 0) {}

  Settings.PID_I = String(buff).toFloat();

}

 

void getPID_D_Value() {

  char buff[17] = "";

  while (NexText(8, 7, "t2").getText(buff, 15) == 0) {}

  Settings.PID_D = String(buff).toFloat();

}


The problem is that each time it may read something false, not something random but the value of previous text reading. That may happen to second text or to third, first is always correct, like a buffer on screen (simulation) is not updated.

For the example bellow i was going back and forward on the screen without changing anything and the results were different each time.

2, 2, 3 or 2, 3, 3 but never 2, 3 ,4 as expected




Is this a bug on simulation only or on the screen too?


I am sorry that I didn't upload the hole code but its a big application and a bit messed up.


Thank you


This is not a bug.


The Nextion IS an Integer Based firmware without floating point.

You will need to adjust your programming to take this into consideration

I know that, that's why I ended up with a complex combination of integers to store the part before comma, after comma and count zeros after comma, its like {int - comma - number of zeros- int} but that's not the problem.


These are simple text, at the end of calculations I convert all those integers to a simple text, transfer the text (where the bug appears) and then convert the text back to decimal for further processing on arduino

If i add delay after each textbox reading it works fine, but i guess that's not how it meant to work.

I will try to read simple text boxes back to back and post the results.

Here are the examples of an other test, reading 3 text box back to back I also uploaded the nextion page and arduino file and run 2 test.


Bellow there is no delay, we get like one, one, one | one, one, two | one, two, two.



Here is with 50ms delay, it works fine


ino
(551 Bytes)
HMI

Again this is not a Nextion bug, it is not even an Arduino bug.

- you have posted under Report a Bug.


Your HMI has nothing but three .txt values in three Text Components

 - this does nothing and has no interaction.

 - so this is not the source of your grief.


Your Arduino code is doing exactly what you have told it to do

  - or at least attempting to do such, and ... perhaps you don't trust your observations.


Your code is extremely simple, so thankfully there is little to influence the result and perhaps

even easier for you to ponder what is going on.


So what do you know about the Nextion Instruction Set?

Or what your library code is doing in NexText.cpp, NexHardware.cpp and NexTouch.cpp?


So when I break your loop() down

   while (t0.getText(buffer, 4) == 0) {}

   -- will never do anything, but it will manage to send get t0.txtÿÿÿ across the tx and will

       start to receive 0x71 One 0xFF 0xFF 0xFF ... so a buffer len of 4?

       condition is getText to be length 0 ... so it moves on immediately to next line.

  you have one buffer for everything

     - each getText call is reusing the same buffer

     - but since the while is never satisfied and does nothing the immediate skip

       makes me wonder if the entire receive is complete before tx sends again.


You have never instructed your serial1 to actually print what t0.txt was

   -  what you have actually asked serial1 to do was print your buffer content

      and your buffer is too small. but regardless ... it will skip onto t1


Ahhh ... t1, same old same old, cascading issues, same instructions

   and without satisfying the while and doing nothing, immediate skip to print

   and again, didn't say print t1.txt, you asked to print what is in buffer.

   - yep, probably not completed ... but off to t2


Ahhh ... t2, is again same old same old, cascading issues, same instructions

   Not satisfying the while and doing nothing, immediate skip to print

   and again, didn't say print t2.txt, you asked to print what is in buffer.

   - yep, probably not completed ... but off to a 1/2 second delay.


Finally ... can catch up on receiving chars coming in on TX

And start it all over again ....


So your code is doing EXACTLY as you instructed.   And that is not a BUG.


So mostly, if it compiles, it will run.

If the result is not what you anticipated, you need to think about what you told it

to do, and change what you tell it to do next time.


For the future - post in Free Chat.  This is not a Nextion Bug.

- and Arduino code is far removed from a Nextion Bug.