Hello!
I am trying to use the internal EEPROM of PIC18F27K42 for saving string using the macro "WriteString" it is very helpful for my present project, I am able to read and write a string which is 15 Bytes (15+nul as mentioned) long (using the memory of EEPROM from 0x00 to 0x0F).
Now the main problem, this PIC has got 1024 Bytes of Memory, so i am able to save only 64 strings (16 Bytes long) an i have to save 250 strings in total.
I tried to check the other option of using external EEPROM unfortunately none of the listed has the macro of ReadString and WriteString, it was very easy while using internal EEPROM, is it possible to add same macro to the external EEPROM.
Is there any other possibility of using SD card to read and write strings?
I hope there is some answer for my problem.
Thank you.
Abhi
External EEPROM ReadString/WriteString
-
- Posts: 32
- http://meble-kuchenne.info.pl
- Joined: Thu Dec 03, 2020 6:26 am
- Has thanked: 3 times
Re: External EEPROM ReadString/WriteString
Hello!
It seems there is no answer to my doubt, is it? team kindly advise, or the only other option is to go for higher size of EEPROM chips, I guess it is available in 16 bit chips, I need to buy 16 bit chip pack?
Thank you.
Regards
Abhi
It seems there is no answer to my doubt, is it? team kindly advise, or the only other option is to go for higher size of EEPROM chips, I guess it is available in 16 bit chips, I need to buy 16 bit chip pack?
Thank you.
Regards
Abhi
-
- Valued Contributor
- Posts: 1582
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 140 times
- Been thanked: 745 times
Re: External EEPROM ReadString/WriteString
Hi Abhi,
There are some options... First up - do your strings need to be 16 bytes each - and even if so there are some tricks to 'compress' the data
For example
ABCD // Stored
ABCDE // Stored as 'previous' + 'E'
ABCDEF // Stored as 'previous' + 'F'
Alternatively - if strings are shorter then save:
'Hello' (6 bytes including \0)
'ABCDE' (6 bytes)
etc
The drawback (with both these approaches) is there is a performance penalty - so access will probably be slower.
Secondly:
Use an external EEPROM (see for example viewtopic.php?t=440&hilit=eeprom+24l) This is fairly straightforward - and would usually use i2c or SPI
Or use an SD - this gives most storage - but at the cost of complexity (and cost)
Let us know some more details of what you want to store - and available hardware - and we will try and help some more.
Martin
There are some options... First up - do your strings need to be 16 bytes each - and even if so there are some tricks to 'compress' the data
For example
ABCD // Stored
ABCDE // Stored as 'previous' + 'E'
ABCDEF // Stored as 'previous' + 'F'
Alternatively - if strings are shorter then save:
'Hello' (6 bytes including \0)
'ABCDE' (6 bytes)
etc
The drawback (with both these approaches) is there is a performance penalty - so access will probably be slower.
Secondly:
Use an external EEPROM (see for example viewtopic.php?t=440&hilit=eeprom+24l) This is fairly straightforward - and would usually use i2c or SPI
Or use an SD - this gives most storage - but at the cost of complexity (and cost)
Let us know some more details of what you want to store - and available hardware - and we will try and help some more.
Martin
Re: External EEPROM ReadString/WriteString
Hello! Martin
good morning
Thank you for writing back, I appreciate.
I will quickly brief you about the project, I am using NEXTION display and PIC18F27K42 in this project. The first part of the project is to create the data, user has to save one item number which is approximately 12-14 digits long alpha-numeric number (so i mentioned 16 bytes), the item number will be punched in the display and transmitted using RS232 from display to PIC, I used "ReceiveString" macro and saved the string in internal EEPROM, for that i used "WriteString" macro.
The second part is to identify the location of the items saved, the user will punch the item number on the NEXTION display and the same will be compared with the saved strings in the EEPROM and the location number will be displayed on the NEXTION.
As you suggested about saving on the SD card, that too is a good option, yesterday I tried to use 24C01 external EEPROM, I was able to use it to save and read back a single byte.
One more doubt, kindly excuse me if I sound stupid, after reading on the internet i understood 16Bytes long memory is addressed as "Page" am I right? I ask this doubt because in external EEPROM read/write page macro is available.
I hope i was able to explain my project well, I guess I am thinking in correct direction, kindly prompt me if I am wrong, do suggest the correct way.
Thank you, hear you soon.
Abhi
good morning
Thank you for writing back, I appreciate.
I will quickly brief you about the project, I am using NEXTION display and PIC18F27K42 in this project. The first part of the project is to create the data, user has to save one item number which is approximately 12-14 digits long alpha-numeric number (so i mentioned 16 bytes), the item number will be punched in the display and transmitted using RS232 from display to PIC, I used "ReceiveString" macro and saved the string in internal EEPROM, for that i used "WriteString" macro.
The second part is to identify the location of the items saved, the user will punch the item number on the NEXTION display and the same will be compared with the saved strings in the EEPROM and the location number will be displayed on the NEXTION.
As you suggested about saving on the SD card, that too is a good option, yesterday I tried to use 24C01 external EEPROM, I was able to use it to save and read back a single byte.
One more doubt, kindly excuse me if I sound stupid, after reading on the internet i understood 16Bytes long memory is addressed as "Page" am I right? I ask this doubt because in external EEPROM read/write page macro is available.
I hope i was able to explain my project well, I guess I am thinking in correct direction, kindly prompt me if I am wrong, do suggest the correct way.
Thank you, hear you soon.
Abhi
-
- Valued Contributor
- Posts: 1582
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 140 times
- Been thanked: 745 times
Re: External EEPROM ReadString/WriteString
Hi Abhi,
There is another option i forgot to mention - use a chip with more memory - something like an esp32 - which can use part of it's memory as a 'disk drive'
The EEPROM chips are divided into pages - the size depends on the chip - larger capacity chips tend to have a larger page size.
Before writing, a page (or the entire chip) needs to be erased - sand this can be only done in pages (or the entire chip). It affects the user if you need to rewrite data particularly - as you cannot rewrite part of a page without erasing the whole page.
Do you know the format the item strings take?
Entering a 1000 strings on a touchscreen sounds like hard work - and possibly error prone. Would it be possible for the user to create a table on a PC and upload that. Then the data could be sorted which could make searching it much quicker.
Also is there a format - or are they 'random'.
For example:
AAA BBB CCC 133 ( where AAA is section, BBB subtype, CCC class, and 123 product id)
Or
A4B7XD0CHIA2 (random(ish))
Martin
There is another option i forgot to mention - use a chip with more memory - something like an esp32 - which can use part of it's memory as a 'disk drive'
The EEPROM chips are divided into pages - the size depends on the chip - larger capacity chips tend to have a larger page size.
Before writing, a page (or the entire chip) needs to be erased - sand this can be only done in pages (or the entire chip). It affects the user if you need to rewrite data particularly - as you cannot rewrite part of a page without erasing the whole page.
Do you know the format the item strings take?
Entering a 1000 strings on a touchscreen sounds like hard work - and possibly error prone. Would it be possible for the user to create a table on a PC and upload that. Then the data could be sorted which could make searching it much quicker.
Also is there a format - or are they 'random'.
For example:
AAA BBB CCC 133 ( where AAA is section, BBB subtype, CCC class, and 123 product id)
Or
A4B7XD0CHIA2 (random(ish))
Martin
Re: External EEPROM ReadString/WriteString
Hi! Martin
good morning
Kindly excuse for my delayed response, was out of office for some site work yesterday.
I do agree with your other option/suggestion about using ESP32, to be honest it will be my first time to use that component, fortunately i took the ESP pack along with FC10 but not used it yet.
Regarding the format of the string it will be a random number, any numerical digits with alphabets and it will be 13-14 digits long.
About the data in all there are 120 item numbers and 120 warning dates to change the item on that date, so in all i need 240 locations, the internal EEPROM has got very handy macro of reading and writing string.
Using SD card is also a good option but unfortunately i have never worked on that much and i am not aware how to read the string from 120 locations, if I use SD card the data entry job will sure get easy for me, as you mentioned earlier, let me try to read on the forum if i find any pointer about reading the data from SD card.
Thank you again for writing back.
Regards
Abhi
good morning
Kindly excuse for my delayed response, was out of office for some site work yesterday.
I do agree with your other option/suggestion about using ESP32, to be honest it will be my first time to use that component, fortunately i took the ESP pack along with FC10 but not used it yet.
Regarding the format of the string it will be a random number, any numerical digits with alphabets and it will be 13-14 digits long.
About the data in all there are 120 item numbers and 120 warning dates to change the item on that date, so in all i need 240 locations, the internal EEPROM has got very handy macro of reading and writing string.
Using SD card is also a good option but unfortunately i have never worked on that much and i am not aware how to read the string from 120 locations, if I use SD card the data entry job will sure get easy for me, as you mentioned earlier, let me try to read on the forum if i find any pointer about reading the data from SD card.
Thank you again for writing back.
Regards
Abhi
-
- Valued Contributor
- Posts: 1642
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 362 times
- Been thanked: 575 times
Re: External EEPROM ReadString/WriteString
Hi Abhi / Martin
Just a quick note to say that I have been assisting another forum member and they have just discovered a potential issue with ESP32 EEPROM.
Basically, at initial "first run", certain values are captured and stored in EEPROM, then on subsequent runs, say after a power cycle / cut etc the code looks in the EEPROM for these values. In normal operation the addresses are only written to once. One address contains a known value as a sanity check, the other address is the value of interest. This value will change if parts needs to be replaced or such like, therefore it shouldn't be written to very often at all. Even including testing, write operation would at most be a few dozen times during lifetime.
Testing showed that the values were being written to EEPROM and could be retrieved after power cycling. However no longevity test was done. One ESP used in the testing has been sitting for a few weeks unpowered. Yesterday when powered it had apparently lost the previously stored data.
Investigation continues and it could just be a bad ESP32 but thought to mention.
Regards
Just a quick note to say that I have been assisting another forum member and they have just discovered a potential issue with ESP32 EEPROM.
Basically, at initial "first run", certain values are captured and stored in EEPROM, then on subsequent runs, say after a power cycle / cut etc the code looks in the EEPROM for these values. In normal operation the addresses are only written to once. One address contains a known value as a sanity check, the other address is the value of interest. This value will change if parts needs to be replaced or such like, therefore it shouldn't be written to very often at all. Even including testing, write operation would at most be a few dozen times during lifetime.
Testing showed that the values were being written to EEPROM and could be retrieved after power cycling. However no longevity test was done. One ESP used in the testing has been sitting for a few weeks unpowered. Yesterday when powered it had apparently lost the previously stored data.
Investigation continues and it could just be a bad ESP32 but thought to mention.
Regards
-
- Valued Contributor
- Posts: 1582
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 140 times
- Been thanked: 745 times
Re: External EEPROM ReadString/WriteString
If using an esp32 - I would probably use a SPIFFS partition or LittleFS partition - this gives all of the benefits of data persistence - but actually uses protected memory and not the EEPROM - so has less issues with multiple writes. Also allows much more data storage space
- depending on chip -and size of program - but could use 2MB for example.
I've posted a brief guide to SPIFFS (though it's deprecated now and LittleFS is preferred)
Martin
- depending on chip -and size of program - but could use 2MB for example.
I've posted a brief guide to SPIFFS (though it's deprecated now and LittleFS is preferred)
Martin
Re: External EEPROM ReadString/WriteString
Hello! Martin and Chipfryer
Thank you for all the updates and explanation.
May I request you to help me understand one string function, I am not able to figureout even after a lot of reading.
I send "FC10" from Nextion and received it at 232 port as String, then I saved one by one to 4 different locations of EEPROM, below are the decimal and Hex values of FC10.
Dec 70 or Hex 46 is "F"
Dec 67 or Hex 43 is "C"
Dec 49 or Hex 31 is "1"
Dec 48 or Hex 30 is "0"
I recalled the values from EEPROM and transmit those to Nextion display as Char and it displayed FC10 one by one, I mean first F followed by C etc but only one character at a time.
Now the main concern is i want to display FC10 in a single go, so my doubt is how can I combine all the 4 values together and transmit as a single string to Nextion.
I hope I explained my doubt well.
Thank you, hear you soon.
Regards
Abhi
Thank you for all the updates and explanation.
May I request you to help me understand one string function, I am not able to figureout even after a lot of reading.
I send "FC10" from Nextion and received it at 232 port as String, then I saved one by one to 4 different locations of EEPROM, below are the decimal and Hex values of FC10.
Dec 70 or Hex 46 is "F"
Dec 67 or Hex 43 is "C"
Dec 49 or Hex 31 is "1"
Dec 48 or Hex 30 is "0"
I recalled the values from EEPROM and transmit those to Nextion display as Char and it displayed FC10 one by one, I mean first F followed by C etc but only one character at a time.
Now the main concern is i want to display FC10 in a single go, so my doubt is how can I combine all the 4 values together and transmit as a single string to Nextion.
I hope I explained my doubt well.
Thank you, hear you soon.
Regards
Abhi
-
- Valued Contributor
- Posts: 1582
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 140 times
- Been thanked: 745 times
Re: External EEPROM ReadString/WriteString
Hi Abhi,
I hope I've understood and this gives you some ideas:
It should be possible using the Nextion::SetText() macro.
You'll need a string variable - for example text[10]
You can read from EEPROM using the ReadString macro - this will read up to a maximum character length (and or \0 (nul) which is a termination character for a string - so if you request up to 10 characters and the saved string is "FC10\0" then text will be "FC10\0" - I've shown the termination character )
Note that you can also assign a value text = "FC10" (or text[0] = 'F' text[1] = 67 text[2] = 0x31 or text[.i]= EEPROM::ReadByte(.position) - if you assign values like this then remember to set a final byte as '\0' (or just 0) - assigning as a string this is done automatically.)
Then call Nextion::SetText("FieldName", text)
Martin
I hope I've understood and this gives you some ideas:
It should be possible using the Nextion::SetText() macro.
You'll need a string variable - for example text[10]
You can read from EEPROM using the ReadString macro - this will read up to a maximum character length (and or \0 (nul) which is a termination character for a string - so if you request up to 10 characters and the saved string is "FC10\0" then text will be "FC10\0" - I've shown the termination character )
Note that you can also assign a value text = "FC10" (or text[0] = 'F' text[1] = 67 text[2] = 0x31 or text[.i]= EEPROM::ReadByte(.position) - if you assign values like this then remember to set a final byte as '\0' (or just 0) - assigning as a string this is done automatically.)
Then call Nextion::SetText("FieldName", text)
Martin