Im working on a small project, where I need the text in t0 to be shown after rebooting the display, so the display remember the value. It is an advanced display im working with, so saving the value in the EEPROM and loading it again should be possible, but I haven't had any luck doing so.
How is this done?
Any help is greatly appreciated.
Nextion Instruction Set:
At the point you know the text that will be displayed in t0.txt on boot, you should store it in EEPROM. If it changes, then with that new change procedure - again store it in eeprom. Pick your addresses. IF t0 is a name and max name might be 16, then 16 + 1 bytes of space for t0.txt. So if I pick addresses 40..56 as where I will store t0.txt with the command wepo t0.txt,40
When I want to pull the value in eeprom on bootup, I already know this is stored at address 40, so in the PostInitialize Event of the page I would put the command repo t0.txt,40
Note that you are reserving addresses 40 to 56 for t0.txt, your next usable address would be 57.
Largest hurdle in EEPROM is to keep track of what address have been assigned for what. Your code has to ensure that you are not overwriting into other addresses (and thus lose what would be overwritten). Numbers always use 4 bytes - it is too easy to think that a simple time HH:MM:SS just needs three bytes HH at 10, MM at 11, and SS at 12, and next address of 13 -- when that should be HH at 10, MM at 14 and SS at 18 with the next usable address of 22.
Im not completely sure about this, but it doesn't work as it is now, pic attached:
The code at each button is:
Where the "0" changes accordingly with the numbers on thew pad.
Code at the save button:
And got the repo t0.txt,40 at the page0.
what am I doing wrong?
at the text area t0, I have the txt-maxl set to 15, but I see that I need to set it to 60 with the numbers I want to use...
Well, haven't played with arduino for 7 years, and working as CNC/Macro programmer, I see that I have a lot to catch up to:-)
woops, brain fart!
I save from 0 and up, but now nothing shows up:-)
Sorry I don't see the picture attachment.
A number that is 4 bytes is n0.val, sys0, pio1, va0.val ... not "0" or "15".
"01234" is 5+1 or 6 bytes required.
perhaps you can use the attach a file.
The wepo could be placed in the HMI design button's Pressed Event (where user presses save)
The repo could be placed in the HMI design page PostInitialize Event
I am assuming (cant see the picture) that the "pad" is a virtual pad displayed on the Nextion and not a physical sensor pad.
Are you asking if button 12 is currently using picture #25 as the criteria if you should save to eeprom?
picture now shows -- must have taken a bit to propagate,
That looks as if the font you are using is not set correctly in the HMI
IF the font height for a 12x24 font is 24 pixels, ensure that the height of the text component is 24
Perhaps set .ycen attribute to Up
Double check your .font attribute has the correct font selected in the HMI
this forum needs a quoting feature, makes things a lot easier!
Took a breath, looked thru the buttons and pages, and deleted my if statement. works now:-) had a kid and wife taking too much of my concentration, multitasking isn't my thing, wait untill they go to sleep, then work on projects:-)
My idea with the if statement was to use one of the two pictures it has in the attribute to send/save the number, but it didn't work:-)
Thanks for the help, next step is to figure out how to use the keypad on two text areas on the same page, but will try that tomorrow. There I will need the if for sure:-)
Handling two texts can be approached with dropping a numeric variable (va0) on your page. Then in your Text Component Touch Pressed Event put va0.val=0 for the first and in the other va0.val=1.
Now when the user taps which text to type into - you can check va0 to see which is active and deal with that one.
Sending "get va0.val" and three 0xFFs or "get t1.txt" and three 0xFFs will return number and text values with the Nextion Response codes 0x71 and 0x70 respectively. Refer to the Instruction Set.
Any component attribute you see in the Nextion Editor can be retrieved. Any in green can be changed. All bold green can be changed with an automatic refresh. The ITEADLIB can be found at https://github.com/itead/ITEADLIB_Arduino_Nextion -- it will of course need to be configured for yours.
Remember that a byte is a char. There usually is some atoi or itoa function, or CHR(byte) / ORD(char) that does the basic translation. The magic comes in how we put these together :) There is little magic in MCUs, rather, way way more need to look after the tinest of details that desktops now handle so transparently.
I created a small tool in copy text from box thread that might help visually, but ultimately we have to code for the parts we are needing in our program (ditch what isn't needed).