logo elektroda
logo elektroda
X
logo elektroda

[Solved] ESP8266 - writing data to EEPROM and reading gives different data.

sotb 1581 6
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 18051217
    sotb
    Level 11  
    D1 mini PRO. I used the example. I did a bit of reading on how it works and wrote a dozen boolean and byte variables to the EEPROM. Writing and reading was correct. I tested for 2 days. I decided that everything was working correctly. I wrote mainly the byte variables with a value of 100.
    I set the EEPROM size to 512 and increased the usage to 380. This I did at home.
    At work I checked and corrected the code a dozen times also resetting the board. I saved some space in the eeprom with a variable byte of value 99. Everything wrote and read correctly.
    At home I connected the board to the PC, fired up the Arduino IDE, did a readout and all the values I had at work saved as 99 read as 100.
    What is it, I thought? I ran a piece of code writing the EEPROM with a byte count of 99. Each time the readout gave 100. I changed the value being written to 0. Also 100. Finally, I did the write three times without doing the readout. After the third time, all the fields that were supposed to be zeros turned out to be numbers 99.
    Well... if the EEPROM.commit() was missing I would still understand, but this action of the eeprom completely deprives me of the possibility of a logical explanation.

    Code: C / C++
    Log in, to see the code
    .

    Above are snippets of code to enable the relay. I am operating on time, so the numbers 99 indicate empty eeprom cells.
    Below is a function that should produce 0, and the numbers 99 appear.

    Code: C / C++
    Log in, to see the code
    .
    So what can you make of this?
    Do you have a problem with Arduino? Ask question. Visit our forum Arduino.
  • ADVERTISEMENT
  • Helpful post
    #2 18051334
    khoam
    Level 42  
    sotb wrote:
    I set the EEPROM size to 512 and increased the usage to 380.
    .
    Show what this initialisation of the emulated EEPROM looks like in setup(), in particular this "increase".
  • ADVERTISEMENT
  • #3 18051364
    sotb
    Level 11  
    Ordinary.
    Code: C / C++
    Log in, to see the code
    .

    When testing the initial code I used 319 bytes. Currently 382.
    That's all the code when it comes to assigning values to variables.
    Code: C / C++
    Log in, to see the code
    .

    And below is the save function in its entirety.
    Code: C / C++
    Log in, to see the code
    .
  • ADVERTISEMENT
  • Helpful post
    #4 18052376
    khoam
    Level 42  
    What board settings do you have in the Arduino IDE in both cases? 16M (14M SPIFFS) or 16M (15M SPIFFS)?
    I assume that "LOLIN (WEMOS) D1 mini Pro" is selected.
  • ADVERTISEMENT
  • #5 18053111
    sotb
    Level 11  
    I didn't even notice that at work I have LOLIN(WEMOS) D1 R2 &mini - 4M(no Spiffs). At home Lolin(Wemos) D1 mini PRO - 16M(14M SPIFFS). Could this be the cause?
  • Helpful post
    #6 18053466
    khoam
    Level 42  
    sotb wrote:
    Could this be the cause?
    .
    Maybe. This is relevant when linking code for ESP.
    The EEPROM class documentation for the ESP8266 says " EEPROM library uses one sector of flash located just after the SPIFF S".
    I wonder if, if you compiled and uploaded the code in "4M(no SPIFFS)" mode, this library will work correctly.
    It wouldn't hurt to compile and upload the code again, but with the board settings "Lolin (Wemos) D1 mini PRO - 16M(14M SPIFFS)" and check.
  • #7 18053495
    sotb
    Level 11  
    Indeed. After changing the settings at work to the correct board these surprising problems do not occur, so thank you for the tip. I click "helped" and close the topic.

Topic summary

The discussion revolves around issues encountered while writing and reading data from EEPROM on the D1 mini PRO using the ESP8266. The user initially reported consistent results at home but faced discrepancies when testing at work, where values saved as 99 were read as 100. The problem was traced back to different board settings in the Arduino IDE: the user was using "Lolin (Wemos) D1 mini PRO - 16M(14M SPIFFS)" at home and "LOLIN(WEMOS) D1 R2 & mini - 4M(no SPIFFS)" at work. After adjusting the board settings to match, the discrepancies were resolved, confirming that the EEPROM library's functionality is affected by the board configuration.
Summary generated by the language model.
ADVERTISEMENT