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