ESP8266 (D1 mini pro) EEPROM problem (with commit)

Hi all,
it seems that the emulated EEP inside my D1Mini does not work.
In order to avoid misunderstanding I wrote following simple code.

Immediately after reset it print first 10 byte from EEP to serial.
So, it start a write cycle and a read cycle.
Always seems to work until I reset the device discovering that data weren't written..

#include <ESP8266WiFi.h>
#include <Arduino.h>
#include <EEPROM.h>

int i;
int ii=0;

void setup()
{
  Serial.begin(115200);
  EEPROM.begin(10);
  delay(1000);

  Serial.println("******************** EEP content after reset.");
  for(i=0; i<10;i++) Serial.print("["+String(i)+"]="+String(EEPROM.read(i))+" ");
  Serial.println("End of 1st read.\n\n");
}

void loop()
{
  Serial.println("\nStarting writing cycle "+String(ii));

  for(i=0; i<10;i++) EEPROM.write(i, i+ii);
  EEPROM.commit(); //EEPROM.end();
  delay(100);

  Serial.println("Write cycle ends. Starting reading");
  for(i=0; i<10;i++) Serial.print("["+String(i)+"]="+String(EEPROM.read(i))+" ");
  Serial.println("Reading ends.\n");

  delay(5000);
  ii++;
}

This is what's happening during execution (seems to be OK):

******************* EEP content after reset.
[0]=0 [1]=0 [2]=0 [3]=0 [4]=0 [5]=0 [6]=0 [7]=0 [8]=0 [9]=0 End of 1st read.

Starting writing cycle 0
Write cycle ends. Starting reading
[0]=0 [1]=1 [2]=2 [3]=3 [4]=4 [5]=5 [6]=6 [7]=7 [8]=8 [9]=9 Reading ends.

Starting writing cycle 1
Write cycle ends. Starting reading
[0]=1 [1]=2 [2]=3 [3]=4 [4]=5 [5]=6 [6]=7 [7]=8 [8]=9 [9]=10 Reading ends.

Starting writing cycle 2
Write cycle ends. Starting reading
[0]=2 [1]=3 [2]=4 [3]=5 [4]=6 [5]=7 [6]=8 [7]=9 [8]=10 [9]=11 Reading ends.

This is after reset..

******************* EEP content after reset.
[0]=0 [1]=0 [2]=0 [3]=0 [4]=0 [5]=0 [6]=0 [7]=0 [8]=0 [9]=0 End of 1st read.

0 0 0 0 .. again.. ?#!?
It seems that EEPROM.read works in RAM only. It does not really read EEP data.

Same if I try with EEPROM.end()..

Thanks for help!

How lang have you been playing with that ESP?

If I test your program (big thanks for posting a compilable program!) I get

Starting writing cycle 0
Write cycle ends. Starting reading
[0]=0 [1]=1 [2]=2 [3]=3 [4]=4 [5]=5 [6]=6 [7]=7 [8]=8 [9]=9 Reading ends.


Starting writing cycle 1
Write cycle ends. Starting reading
[0]=1 [1]=2 [2]=3 [3]=4 [4]=5 [5]=6 [6]=7 [7]=8 [8]=9 [9]=10 Reading ends.


Starting writing cycle 2
Write cycle ends. Starting reading
[0]=2 [1]=3 [2]=4 [3]=5 [4]=6 [5]=7 [6]=8 [7]=9 [8]=10 [9]=11 Reading ends.


******************** EEP content after reset.
[0]=2 [1]=3 [2]=4 [3]=5 [4]=6 [5]=7 [6]=8 [7]=9 [8]=10 [9]=11 End of 1st read.
[code]
So works as expected

I tried as well on a Wemos D1 Mini and it works as expected

Just to put some color to the question:

How long have you been playing with that ESP?

The sector holding the data needs to be re-flashed every time the changed EEPROM data needs to be saved (when you commit), thus will wear out the flash memory quickly even if small amounts of data are written

Flash has about 10,000 write cycles. if you write every 5 seconds you'll reach the 10,000 cycles in less than 14h. Did you leave your Wemos with that sketch running all night?

Hi guys, thanks for your repliesI

My ESP run since dicember but EEP code was written some day ago (not more than 300 re-write cycles).
It's very strange...

Wich toolchain are you using ? I'm using Visual Studio Code+Platformio.

May be I have to install Arduino and try it..

UPDATE:
I try with Arduino toolchain and nothing change.
So, I decide to try with another Wemos D1 mini pro: nothing change.

Hypotesis 'a'
May be I set wrong some parameter inside tool ?
I mean: 'Flash size', 'Vtables' etc..

Hypotesis 'b'
@ this point, I'm suspecting that purchased D1 device are 'fake' or different from original Wemos ones. But, if this is the case, I can't figure how a different HW implementation of ESP chip could be responsible of this behaviour...

Tool chain is the Aduino IDE of course. That is what one would expect if you post here. Don't say I do everything in the IDE, but that's the golden standard if it comes to the Arduino forum. Name / URL might give it away :stuck_out_tongue:

B seems very unlikely to me, we would have heard from that.

A, maybe. I had everything set to the default of a Wemos D1 Mini and ESP8266 board def 2.7.4.

I agree with you.
'B' it's very unlikely also for me.

Regarding 'A': I'm using default settings too..

Someone has other idea ?

Thanks.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.