At the moment I’m having a problem with my nextion coding, and until now I wasn’t able to find an answer here in the forum.
My Arduino is sending a numeric value in 10Hz to the nextion display. This value is stored in a global defined variable (engine_speed). I could show this value on the page (for example page1) where I have defined this variable.
Now I would like to switch to page 2 and use the same transmitted value also there. But the value seems not to be updated.
What I have tried:
On page 2 I have started a timer with 10Hz, which does this: n1.val=page1.engine_speed.val
(n1 is the number field where I would like to show the continuously updated value)
Now I have seen, that the value seems not to be updated. Only the latest value from my global variable (engine_speed) when I left page1 to page2 will be shown on page 2
Could it be, that if a page is not active where a variable is defined, that the display will not receive a transmitted value from SPI bus?
I really would like to send only ONCE the data via SPI to my nextion, and use this value on several pages – but how?
Sorry forgot the HMI file.
Where you could see my problem is on page2 the value for field x1
value update is in timer value_update
where did you buy a Nextion with SPI interface? :-)
Ok, I just tried that it seem to work just fine.
On page0 I have a variable called master defined as global.
On page1 I have a t0 defined and a timer define.
In the timer function I have:
I send page page1
then I send: page0.master.txt="Frank"
I see that value change to Frank when the timer kicks.
I also see my n0 increment as I watch it.
t0 is defined as local so when I switch pages and back I see the default value until the timer kicks.
And there I could not attach a "page0" for instance...
Thank you very much for your help!
That is why the values aren't changing for you. When your not on that page the page data has to be added or it will not update the global variable.
I will look into the Arduino library and see what you might do instead.
I think to fix your issue using the Arduino library is to define your variables with the page prefix. Once the variable is define as global it needs to have the page information prefixed.
NexNumber master = new NexNumber(5, 6, "page0.master");