Start a new topic

Show text from keypad after reboot?

Hi,


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.


Cheers


Daniel





Nextion Instruction Set:

wepo and repo commands are for writing and reading text to EEPROM


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.


1 person likes this

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.


if(va0.val=0)

{

}else

if(va0.val=1)

{

}




1 person likes this
Got it all working as I want now, sweet little display and program:-) I'm about to start some arduino coding, and wan to ask if there is an easy way to get the text values from the display, or component values? What arduino library to use and so on. Sorting serial data will become a rather large project, if need of many variables and functions. Cheers, Daniel

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.




And I get the value in HEX right? Don't have time to program before the weekend, but still have some Qs:-) I need the value in ASCII for communication with some other hardware, is there some magical way to do this? Been looking for some code to do this, but haven't had any luck finding anything... Cheers, Daniel

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).

Thanks:-) Just thought that maybe someone out there made an library to do this stuff:-) Well, need a new game plan now, but now I know what to search for.... Did look at your thread, but need the PC to download:-) Cheers

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


Arduino Mega:-) An library for the HEX to ASCII conversion, as said, my programming skills are a bit rusty and need some polishing:-) Cheers

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.

Thanks:-) Well, have been doing that:-) Haven't uploaded the sketch to the device yet, I have only been debugging on my pc, and can't see the text in the area:-) will upload tonight and see if it works, and write here... Still my first project, so have a lot to learn:-)

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.


Happy Coding

Im not completely sure about this, but it doesn't work as it is now, pic attached:


The code at each button is:


t0.txt=t0.txt+"0"


Where the "0" changes accordingly with the numbers on thew pad.


Code at the save button:


if(b12.pic==25)

{

  wepo t0.txt,40

  print t0.txt

}


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:-)


Cheers, Daniel


woops, brain fart!


I save from 0 and up, but now nothing shows up:-)


Cheers, Daniel

Login or Signup to post a comment