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.
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).
what MCU are you using, and are you looking for Arduino?
ITEADLIB is located https://github.com/itead/ITEADLIB_Arduino_Nextion
and Edwin's Simplified Library is http://support.iteadstudio.com/support/discussions/topics/11000005359
If I were an Arduino guy, I would use the ITEADLIB (configured for Mega already), and it will have the
atoi() (Ascii to Integer) and itoa() (Integer to Ascii) functions. I would look deeper into the code it calls to see what is being done underneath. Such as how SendCommand() works. Also look through the standard Arduino functions in the standard libs. The Nextion.h include is going to tie in the base functions for the Nextion Display, but don't forget to take advantage of Arduino's standard functions as well. Understanding it, is going to allow you manipulate it and squeeze the most out.
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:-)