Start a new topic

Recieve variable value with .getValue

 Hello out there,


for my last year at school I have to build a project with 3 other classmates.

The project is going to be a measuring device with a data storrage over SD-Card.

The name of the first file created on the SD-Card is the year + month + day and I want to use the RTC on my Nextion enhanced 4,3''.

To get the values of the RTC I save them in variables va0 to va4 with the command va0.Val=rtc0 and so on.


On my Arduino mega 2560 I use the Nextion library for Arduino to handle my 12 Pages and stuff.


Now to my issue. When I tryto get the value of the variables decleared on the nextion one atfer the other, I get the year the current month a zero and  the day followed by a zero. When I try to recieve it again the zeroes get overwritten with the year and the month.


va0.getValue(&Year);


I decleared the variables like so:

NexVariable va0 = NexVariable(1,0,"va0");
...
uint32_t Year;
...
I also tried to handle the issue with extra pointers but nothing changed.

I didn't forget to put in some batteries, because I use the debugging window of the Nextion Editor

Thanks for your help

Mathias

Ps: My code is a little bit to long to post it, so I had to attach it. If the length is a problem I'll cut it down.
PPS: My code is written in german because I'm from Austria.
HMI
(4.04 MB)
ino

Hi Mathias,


Excellent work on you project. Well done.


I can't provide working code for a school project. However I just covered this issue on another thread.


So I can give you some ideas to try, and hopefully you will figure it out quite soon.


The problem appears to be caused by grouping several .getValue requests in one function.


Your Arduino Mega fires all those requests at once, but the routines for collecting and sorting the answers are not robust enough to do so without error. Slow Serial !


The answer over on the other thread 

http://support.iteadstudio.com/support/discussions/topics/11000009180


was to break down the group code block (yours below) and put each request into a separate routine, to run and complete before calling the next. 

 Y.getValue(&Jahr);
 M.getValue(&Monat);
 D.getValue(&Tag);
 H.getValue(&Stunde);
 min.getValue(&Minute); 

Hope this helps


Steve (indev2)


 

Thank you for your fast response Steve,

it looks like that's the issue.
I'll splitt it up and that should do it

Thanks,
Mathias

 

I put a delay of 40 msec between the value requests and
now it's working fine thanks for your help.

Mathias

 

Hmm..


I tried that as a quick solution to the problem in the first instance.

It still didn't produce reliable results. 

delay() effectively halts everything, and is the recommended bad practice for blinking LED's ;) 


Your project at least deserves you trying something a little more elegant :) 


If you try as I suggested, in theory it should work without any use of delay() 

Something like.....

       

void b12PopCallback(void *ptr) {
  
  Serial2.println("Page1");
  Y.getValue(&Jahr);
  Serial2.println(Jahr);
  b12PopCallback2();
}

void b12PopCallback2(void *ptr) {  
 
  M.getValue(&Monat);
  Serial2.println(Monat);
  b12PopCallback3();
}

etc...  

loop() should then continue to retrieve each answer (accurately) in the shortest possible time before the main thread moves on to the next.


If it doesn't work, then you can always go back to delay().


Steve. 

    

Never thought about sub programs leading into other sub programs but I tried it.
I rearanged my variables and tried it out but it didn't work, I just got zeros back

 

C++
void b10PopCallback(void *ptr)
{
  page10.show();
  t105.setText("");
  digitalWrite(Spow,HIGH);
  b10PopCallback2();
}
void b10PopCallback2()
{
  Serial2.println("Jahr");
  Jahr = 0;
  Y.getValue(&Jahr);
  Serial2.println(Jahr);
  b10PopCallback3();
}
void b10PopCallback3()
{
  Serial2.println("Monat");
  Monat = 0;
  M.getValue(&Monat);
  Serial2.println(Monat);
  b10PopCallback4();
}
void b10PopCallback4()
{
  Serial2.println("Tag");
  Tag = 0;
  D.getValue(&Tag);
  Serial2.println(Tag);
  Ordner = "";
  Ordner = Ordner + Jahr + Monat + Tag;
  Ordner.remove(0,2);
  Serial2.println(Ordner);
//  SD.mkdir(Ordner);
}

 

Thanks for your time,
Mathias

Update:
I haven't seen that I open page ten in the first line, fixed it
But still there are issues with the speed...

 

Mathias


The (void *ptr) in each subsequent routine is important, and missing in your examples !


In NexHardware.h https://github.com/itead/ITEADLIB_Arduino_Nextion/blob/master/NexHardware.h


timeout = 100 ms. This should be long enough to complete the...


bool recvRetNumber(uint32_t *number, uint32_t timeout) 


routine in NexHardware.cpp


https://github.com/itead/ITEADLIB_Arduino_Nextion/blob/master/NexHardware.cpp


You can edit timeout if it really too slow at 100ms.


Are you set at @ 115200 baud on Nextion Serial ?


The library and display defaults are 9600 ! 

I missed them because the debugger is missing an argument when I call the function
Do I have to initialze something that I can use it properly?

The baud rate is default (9600)

 

Regards

Mathias

Mathias,


OK, after some real world tests on an Arduino, I found the best workaround is to edit timeout in NexHardware.h


The file is in your C:\Users\*UserName*\Documents\Arduino\libraries\ITEADLIB_Arduino_Nextion-master


At line 50.... bool recvRetNumber(uint32_t *number, uint32_t timeout = 200);


A value of 200 will enable good consistent results without needing delay() in your main code.


You can even go back to your original format and call all the .getValues in a single routine :) 


This figure was determined in Nextion Editor debug simulator, which can be rather slow. You may find it can be less when you connect to your hardware display.


I stand corrected on the (void *ptr) requirement, I was thinking of the previous issue on the other thread.

You shouldn't need those methods now anyway, I did test, and it does work with the above edit also.


Steve.

Nice, thanks

I changed the timeout to 200 and it worked.
I'm going to do some testing tomorrow with the display conected, I'll also try different timeout values

Thanks for your time

Mathias

 

Final Solution:

I made some tests (unfortunately not with the display) and I figured out that it takes some time for the display to write the values into the variables. To compensate this I wait a little bit before I catch the values and it's running smoothly ^^
I also increased the timeout to 300 (I think that this is unnecessary but I won't change that)

I want to thank you, Steve, for your time and patience

Regards

Mathias

 

Mathias,


You're welcome, on a side note, I'm only just beginning to understand the workings of the library myself.

So this has been an education in itself, in my own projects, I use my own custom code, which I must say is much more efficient.


Looking through the forum, there are several other instances of similar issues to yours.

More often than not, they also come to light when using the debug simulator.


It would not be unreasonable to conclude that the only way to properly debug a design, is to do it on the real hardware.


I don't know about your experiences with windows applications built on Java (Nextion Editor included),

on my PC they run the processor hard and can be inherently Slooooooooooow :)


Arduino IDE is another example.


Just my $0.02


Steve.  

Hello!


I have several pages, on page2 I have a label with numbers. I set this number-label-field as global. Is it possible to get value of this number-field from nextion screen when I am on page0 or page1?! When I am on page2 where actually sits this number-label, i can get its value by calling myNumber.getValue(); But I need to get Its value from page0 also. Is it possoble? Why do I need this? When I press various buttons, they change value of this number-field (this is programmed on Nextion side) and I need to get thos values to my arduino controller whatever page it is on curently.

I think what you want to do will work, as long you always refer to the Number field with the page prefix and make sure it's global. For example n0.val on page 2 would be page2.n0.val

A quick test in Nextion Editor seems to work OK for me :)


Viljams Vidauskis -- 


Arduino Side : When you initialize NexNumber instead of n0.val, use page2.n0.val. 

Under nex_listen_list - &n0,

Use - uint32_t number1

n0.getvalue(&number1) 

Login or Signup to post a comment