Unofficial Nextion/TJC User Forum

How to Update Waveform From Other Page

Hello,
I have a display with four pages. The first page is the main page, and when that page is active, it pulls data from the serial port. On the third page of this display, I have a waveform. I need to have the main page open in order to get the data, but I would like to use this to update the waveform.

I have made the data and the waveform global, but I cannot get the “add” function to work unless I’m on the page with the waveform. I can’t find a way off addressing the object ID globally.

Is there a way to use the “add” function on a waveform that’s not on the active page? If so, how do I use an add" function on page 1 to update a waveform on page 3?

Thanks for your help.

Have you considered reading the Nextion Editor guide?

This is clearly explained.

Thanks. I have read it, and i disagree that is clearly explained. I’m pretty sure what i am asking for can be done by saving data to an sd card, and then loading it onto the waveform when the page becomes active.

I am probably using this screen in a non-typical manner. It seems that every search for Nextion is accompanied by an Arduino project. I generally do automation programming using PLCs and much more expensive screens that have far more functions. I’m new to Nextion. I like them. Their cost is excellent, but you tend to spend literally 10 times more in programming time compared to a higher end screen.

Here’s how you make a historical trend…and it’s cumbersome.

On the sheet where you have the waveform, create 10 numeric variables, all global. It’s important that their object IDs are in order. Let’s assume their IDs are 1 through 10. Then create two global variables in program.s, X and k

On the page where the data is being collected, create a timer and a for loop to load the ten variables like a FIFO queue. These can then be loaded when the waveform initializes.

This code creates a FIFO queue that loadable from the data page, and visible from the waveform page. In this case the waveform page is 3, and it’s ID is 12
//==============================================
X=readvalue.val // this is the value you are reading from serial
for(k=10;k>1;k–)
{
p[3].b[k].val=p[3].b[k-1].val
}
p[3].b[1].val=X // load the first value of the queue with the current reading
// ==============================================

Then on the waveform page, in the page initialization area
// ==============================================
for(k=10;k<=1;k–) // the most recent data gets loaded last
{
add 12,0,b[k].val
}

This works, but it’s cumbersome. The code isn’t, but if you wanted a waveform history of 200 data points, you’d have to create 200 variables. I don’t think that’s a lot of memory, it’s just a lot of work.

And the other thing to worry about is how indexing works. That is a tricky subject. Index values are based on objects and variables as they are entered on the page. You can’t choose or change IDs. And if you delete anything, all the index IDs from that number and above will change. If you are not aware of that, it makes your code very difficult to figure out sometimes.

The best way to do this is start with a clean page and make all your variable first. This way your indexing will start at 1 and will stay consistent even if you have to add things later. I would also create many more variables than are needed because if you have to add some later, you will have to delete everything with an ID higher than your last variable ID in order to get your new variables to have a sequential ID number.

AKG

You can arrange the objects on a page in any order using the Bring Top and Bring Bottom toolbar commands. This changes the order for indexing.

Thank you for your help


This forum is in no way affiliated with NEXTION®, ITEAD STUDIO®, TJC®, or anyone else really. All product names, logos, and brands are property of their respective owners. All company, product, and service names used in this website are for identification purposes only. Use of these names, logos, and brands does not imply endorsement from the respective rights holder(s).