Hi - I have a page with a slider [h0] and 6 dual state buttons [bt0-bt5] - I attached a picture so you can have a better idea of what's going on.
I'm wanting to be able to strafe through an array. This would probably pretty easy if I had a fixed number of items in that array, but I only want items of a particular value to populate the list.
Each dual state button would represent a saved file. I have a SPIFFS filesystem working for saving and reading, and I have a function that populates 4 different arrays with all of the data from 50 possible save items:
String filePaths[51];
String fileNames[51];
int fileStatus[51];
int fileNum[51];
Each array # has corresponding values to make up a whole save file - for example:
filePaths[4], fileNames[4], fileStatus[4], and fileNum[4] make up all of the data for one save file.
I'm using PerryBebbington's Nextion method, which allows all of the programming to be done on the arduino in response to serial messages from the nextion.
My idea involves sending a signal from the nextion every time the slider's value changes, then having the arduino decide whether it has gone up or down and repopulate the dual state values based on that.
I suppose I'm looking for a way to count the number of items that have a fileStatus[\i] of 1 and populate with those items, but also sequentially scroll up and down through those items.
This all sounds kind of convoluted, I know - I just don't know how to filter/traverse an array in a sequential manner.
I don't know anything about SPIFFS file systems (that's for the future for me!) so excuse my ignorance on that one. Aside from that, I need to check I have understood you correctly, is this a fair summary:
You want a slider (or sliders) with a range of output of 0 to 50 (51 possibilities) and you will use those values as an index for your 4 arrays. Is that correct? If not then please correct me.
Please can you upload your HMI file to this discussion? You will need to put it in a zip file as I don't think the web site will accept it otherwise.
I don't know anything about SPIFFS file systems (that's for the future for me!) so excuse my ignorance on that one. Aside from that, I need to check I have understood you correctly, is this a fair summary:
You want a slider (or sliders) with a range of output of 0 to 50 (51 possibilities) and you will use those values as an index for your 4 arrays. Is that correct? If not then please correct me.
Please can you upload your HMI file to this discussion? You will need to put it in a zip file as I don't think the web site will accept it otherwise.
I've actually rigged something together (very ugly) that will work, it's just a lot of counters and extra arrays - it's so ugly but I don't care at this point.
The last piece is just getting the Nextion to send the h0.val every time it changes.
printh a5 //Start
printh a5 //Start
printh a5 //Start
printh 00 //Page
printh 01 //Type
printh 00 //Index of this type
print h0.val //Setting
Does that help? Put under Touch Move or Touch Release depending on what works for your project. That's from my light dimmer project, which uses the sliders to control colour and brightness of lights in my conservatory. It uses the same method I outlined in the tutorial. The final print h0.val sends 4 bytes, but you only need the first 2, or first 1 if you are not going above 255.
PerryBebbington:
Does that help? Put under Touch Move or Touch Release depending on what works for your project. That's from my light dimmer project, which uses the sliders to control colour and brightness of lights in my conservatory. It uses the same method I outlined in the tutorial. The final print h0.val sends 4 bytes, but you only need the first 2, or first 1 if you are not going above 255.
Since I only have one slider element (type 3), I'm just wondering if I can stick it in the index slot:
And, assuming this is fine, once I go down the line and have identified a message is coming from the h0 element (HMI_read_data[2] value), can I just use HMI_read_data[3] and if statement/operators to compare whether it has moved up or down compared to the previous value?
I have a new issue - in the initial page load, I calculate the number of save entries (int NoS) and then attempt to send that value to the slider using the following code:
Serial1.print(F("h0.maxval=\""));
Serial1.print(NoS);
Serial1.print(F("\""));
HMICommandEnd();
Serial1.print(F("h0.val=\""));
Serial1.print(NoS);
Serial1.print(F("\""));
HMICommandEnd();
Serial1.print(F("ref 9")); // the h0 id is 9
HMICommandEnd();
Unfortunately, it seems to have no effect. I can see it because I have the value being sent back from the slider on move, and it still cycles through the initial maxval & val set on the Nextion HDI file.
Are the slider's parameters just not able to be affected?
I designed this to be flexible and adaptable. I built in 3 levels of identification for each object (page, type and index of type) but you don't have to use all 3. You could just use 1 and simplify things, or you could invent a 4th if you needed for some reason. Unlike a library with predefined functions this is a framework for you to adapt to what you are making. It does mean you have to understand how it works, but when you do it is very flexible.
Are the slider's parameters just not able to be affected?
Some you can and some you can't. I thought maxval was one you couldn't, but I've just tried it using debug and it seems to change OK. Have you tried it using debug? AFAIK the Attributes in green in the design tool can be changed by instructions, the ones in black cannot. If there's a mistake in your code I can't see it. Try some of the others such as changing the colours and the dimensions of the slider to verify your code is OK. What value is NoS? Could it be out of range for the slider?
If it were me I would not try to change the max value of the slider, I'd pre-define it as the maximum I will even need then scale it in software on the Arduino if I needed a smaller range. However, there is no reason to always copy me! :o
PerryBebbington:
Some you can and some you can't. I thought maxval was one you couldn't, but I've just tried it using debug and it seems to change OK. Have you tried it using debug? AFAIK the Attributes in green in the design tool can be changed by instructions, the ones in black cannot. If there's a mistake in your code I can't see it. Try some of the others such as changing the colours and the dimensions of the slider to verify your code is OK. What value is NoS? Could it be out of range for the slider?
If it were me I would not try to change the max value of the slider, I'd pre-define it as the maximum I will even need then scale it in software on the Arduino if I needed a smaller range. However, there is no reason to always copy me! :o
The issue turned out to be me forgetting that numeric values don't need to be wrapped with quotation marks - I removed those and it's all good now!
So now that I'm getting the value and the slider is always going to be moving in intervals of 1, I can do the math on the Arduino (it's actually an ESP32 now) to compare the new value to the previous one, get the difference, then add or subtract that from the list's starting number for the array to repopulate the list with.
jtbennett:
The issue turned out to be me forgetting that numeric values don't need to be wrapped with quotation marks - I removed those and it's all good now!
I've been writing C for ages, and I still make mistakes like that!
RayLivingston:
You do realize you can just do this?
printh a5, a5, a5, 05, 03, h0.val, 00, 00
Hello Ray,
Are you sure? I've just tried that in the Nextion IDE and it does not compile. I have tried with and without spaces after each comma. When I first played with the Nextion I quickly discovered that it only allows one instruction per line, or at least, I never found a way to have more than one.
Are you sure? I've just tried that in the Nextion IDE and it does not compile. I have tried with and without spaces after each comma. When I first played with the Nextion I quickly discovered that it only allows one instruction per line, or at least, I never found a way to have more than one.
If this guy's saying I can just put commas between my commands instead of new print arguments, I'd be happy to reduce a bit of the lag when things are processing over serial
I don't believe him though
e: maybe he's just saying it works from nextion to arduino that way ?
Are you sure? I've just tried that in the Nextion IDE and it does not compile. I have tried with and without spaces after each comma. When I first played with the Nextion I quickly discovered that it only allows one instruction per line, or at least, I never found a way to have more than one.
Sorry, I mis-remembered the syntax - spaces, no commas.
I now have a fully functional scroll bar for a file list generated from an array. It's very ugly code, and the action is a little crusty since there's quite a number of calculations going on, but it's functional. I was able to recover some functional speed by returning a bunch of processes to the Nextion's HMI instead of going back and forth through the serial (stuff like visibility based on scroll position, refreshes after actions, etc).
I am replying to this because I implemented a scrollable file list on Nextion a few years ago, and it works very well. The files are read from an SD card attached to the Arduino. The HMI and TFT files are on the Github repository for anyone who wants to see how it's done. The URL for that is Github for Nextion Scroller.
You can see it in action (running off an Arduino Micro) on this YouTube video. I will be happy to help/explain if anyone has any problems with implementation.
Hi DrBoo - that link takes me to some sort of TV project - I'm interested in this list thing though, especially if it has nice smooth action, mine requires refreshes and calculations at every movement and since I'm running back and forth through the serial connection, it's a little slower than I'd like it to be.
I'm sure there must be a smarter way to send all the data needed over to the nextion in one go, but I'm just too tired to start over again
Mine requires refreshes and calculations at every movement and since I'm running back and forth through the serial connection, it's a little slower than I'd like it to be.
Here's a suggestion, I am not completely sure it will work and you'll have to play about with it to get it working.
Create several separate text boxes, one above the other, one for each line of text you want to scroll, so if you want to display 8 lines create 8 boxes.
Create 2 buttons, these should be hidden out of sight by making them small (1 pixel x 1 pixel) and with the colour to match the background.
Under 1 button put something like
t7.txt=t6.txt //Moves text 6 to text 7
t6.txt=t5.txt //Moves text 5 to text 6
etc...
To activate this send from the Arduino
click b0,1
click b0,0
Which clicks the button (you have to send click press and click release, try without and you'll see why)
Do the same for the other button but in the opposite order for scrolling the other way.
You then only have to send either the top or bottom line of text.
I think this should work, but you will have to play with it.