Global variables update from Arduino

Hello guys, I’m new here!
I have a problem with my project (Arduino + Nextion).
I have some global variables (in page 5, all numbers) that I want to update from Arduino every second while displaying other pages.
The problem I have is that the variables update only when page 5 is displayed.
All the rest is working correctly.
I tried to simulate in debug a variable update (I was on page 1, page5.variable.val=1) and everything worked correctly, so I assume the problem is in the Arduino-Nextion communication.
I am using the Nextion brain to update numbers on all pages when displayed instead of having a lot of serial stream to update all the pages every time I call them.
Any suggestion?
Thanks!
Stefano

Hi Stefano

You should check on serial monitor how exactly your commands is send. I guess there should be something that makes it not compatible with instruction set.

It should be sent exactly as you write it in simulator (page5.variable.val=1) no space or other unexpected chars.

Regards Hubert

Hello Hubert,

Thank you for your reply.
In the Arduino sketch I use

variable.setValue(xx);

This sintax works fine, I can send the variables I want and I receive them correctly.
The problems comes in only when the variables are not in the displayed page (global in page 5, showing page 1 when Arduino sends commands).

any idea?

Thanks
Stefano

Hi Stefano

So how this function know on what page this variable is?
Inside this function there is probably some serial print function, you should check if command is prefixed with page number.
I don’t know how this library is designed.

Or you should just try to send this command using serial.print function.

Regards
Hubert

1 Like

Here’s the way I do it:
SerialPrint(“pageBE.t2.txt=”);
SerialWrite(0x22);
SerialPrint(distance_Axis);
SerialWrite(0x22);
SerialWrite(0xff);
SerialWrite(0xff);
SerialWrite(0xff);

SerialPrint and SerialWrite are just wrappers for Serial.print and Serial.write to allow printing/writing to Serial1,2,or 3.

p.s. I’d recommend naming your pages instead of using the number id. With names you can rearrange the pages.

1 Like