logo elektroda
logo elektroda
X
logo elektroda

ESP8266-12E and EEPROM 24C32 (I2C) - problems with writing and reading data in LUA

Adrian1978 3066 4
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 15840728
    Adrian1978
    Level 11  
    Hi there , do you have any experience with storing data in external EEPROMs connected to ESP8266 modules ? I found a rather clearly described example where the author writes and reads data in an external EEPROM 24C32 (I2C) with this module but it doesn't work for me. I am using LUA with support for i2c among other things but either the write is going wrong or the read is not working as it should , silly reads , ie not what I intended to write.

    an example that supposedly works and with the latest firmware :

    Link
  • ADVERTISEMENT
  • Helpful post
    #2 15840760
    piotr411
    Level 22  
    May I ask for what purpose you need to connect a separate 4kb memory? One memory in the ESP8266 12F is already there and has 4Mb, and if that's not enough for you, the ESP8266 13 has 16Mb of it.
    In Lua, just create a file, e.g. with a txt extension, or any other extension, save it to the memory and retrieve data or write, add, with one command.
    http://nodemcu.readthedocs.io/en/master/en/modules/file/

    This is a code snippet for handling clock alarms in memory to fit about 100,000 alarms

    Code: Lua
    Log in, to see the code



    and this is the content of the timer.dat file

    Code: Ini
    Log in, to see the code


    How does this function work?

    16x per second it checks the contents of the data in the file and compares it with other data implemented by the program.

    ST - means to switch on the device with the address 01 at 05:00:00
    in the next line we again have ST at the beginning, i.e. the device with address 02 will be switched on at 05:20:00 in the fourth line there is SP which means that it has to switch off all devices at 06:35:02 and so on...... ;) the last line is the first empty line and the program leaves with repeat condition if a==nil then break end

    this is a small example of how to use the memory you already have for storing data.
  • ADVERTISEMENT
  • #3 15841102
    Adrian1978
    Level 11  
    Yes , of course , storing in Flash is possible and I have tried it, but if you want to write a dozen or so times a day literally a few bytes and read it from time to time (system status log, assigned passwords, temperature logger, etc.) then you will simply break the Flash. The service life of Flash memory is specified in its documentation as 100,000 cycles, while that of EEPROM is a million and more. Converting this into operating time and assuming that the device writes something to flash say 50 times a day, you have 50X365 days = 18250 records per year, the average life is say 100000 write cycles , so the memory will be gone after 5 years. And after my failed few memories I dare say after a year.... my flashes during playtime were flying...after a few hundred write cycles. The module is supposed to work quite reliably, so I would prefer to have those few bytes stored in a small cube.
  • ADVERTISEMENT
  • #4 15842355
    piotr411
    Level 22  
    Memories do not "fly" due to multiple writing, the problem is the formatting during firmware upload. There is something written there that tells ESP about the multiplicity of memory, if an error occurs there, ESP does not "see" the memory. It's probably possible to regain 'coherence' but ESP is so inexpensive that I don't entertain exploring the subject and dabble further. If the memory loses integrity, try playing around with formatting from the ESP BASIC firmware, there are formatting choices there, just avoid the 4mb size as it either doesn't format or just blocks the memory. Not tested so treat this as hearsay information, not a compendium of knowledge.
  • #5 15856624
    Adrian1978
    Level 11  
    The topic with writing to EEPROM tired me , I reorganised the data collection needed for archiving and just moved it to flash. now the writing is bigger , but less frequent. We'll see when it will dump and after how long.
ADVERTISEMENT