Nextion display get current page

Hey all,

I'm working on a project that has a Nextion display. The project has 3 pages on the Nextion and counting. I'm using the official Arduino Nextion library at the moment; but looking to use RayLivingston's version later on possibly.

I have the following issue:
I need to send data from the Arduino to the Nextion display to update components on page 0. I need to send different data for different components on page 1 and so on. I don't want to send data for the wrong page. I've heard about using global variables to store the values when on a different page; but I don't find that solution elegant.

To achieve this the Arduino needs to know what page the Nextion display is on. How do I do this? (Ideally using the library)

Regardless of whether you use a library or my methods or invent your own I sugest that the solution is that on each page under post initialisation event you put some code that sends the current page to the Arduino. In your Arduino code you read this data and store it in a variable. That variable then tells you which page you are on.

This is built in to my methods. No idea about any library but I guess it must be possible.

PerryBebbington:
Regardless of whether you use a library or my methods or invent your own I sugest that the solution is that on each page under post initialisation event you put some code that sends the current page to the Arduino. In your Arduino code you read this data and store it in a variable. That variable then tells you which page you are on.

This is built in to my methods. No idea about any library but I guess it must be possible.

That was what first came to mind; but the issue is that the library handles all the serial comms.(correct me if I'm wrong)

That was what first came to mind; but the issue is that the library handles all the serial comms.(correct me if I’m wrong)

I don’t know as I don’t use the library. I have a vague idea there is a function in the library to get the current page, but if that’s correct I don’t know what it is.

If you are going to use the library I strongly suggest using Ray’s version, I have read many, many comments on here about how bad the official library is and how much better Ray’s version is.

Here is what I did to update a current page to the controller, I am using official library by the way

I am dragging a button component to the Nextion editor, enabling 'touch release',

I create it's NextButton instance on Arduino side so I am able to listen to it, upon release-event
to note down the hex data sent to Arduino ( hexString ) ,

the button gets deleted

I then create a timer instance that's set off to fire say every after x seconds, whose event it to send the noted down 'hexString' back to Arduino,

so the timer here mimics a button I just deleted

I do this to each Nextion page

KASSIMSAMJI:
Here is what I did to update a current page to the controller, I am using official library by the way

I am dragging a button component to the Nextion editor, enabling 'touch release',

I create it's NextButton instance on Arduino side so I am able to listen to it, upon release-event
to note down the hex data sent to Arduino ( hexString ) ,

the button gets deleted

I then create a timer instance that's set off to fire say every after x seconds, whose event it to send the noted down 'hexString' back to Arduino,

so the timer here mimics a button I just deleted

I do this to each Nextion page

Sorry I don't understand what you mean; can you please clarify :)?