-->
Page 1 of 1

ESP8266 ESP-12F NodeMCU - Simple EEPROM write/read fails!

PostPosted: Mon Jun 20, 2016 4:02 pm
by nscripta
I'm using a ESP8266 ESP-12F NodeMCU Lua mini dev board and trying to get an EEPROM write/read sequence to work. Looking at other code online I believe it should be working, but could be wrong. Below is test code where I am writing to the first 3 bytes and then reading it back after a 10 second delay, the EEPROM bytes are used to store the RGB values for a web controlled chain of WS2801 LED's.

Code: Select all#include <EEPROM.h>

int rgb_code[4];
String colour;

void setup()
{
  Serial.begin(115200);

    delay(5000);
    Serial.println("");
    Serial.println("Writing EEPROM");

    EEPROM.write(0,0);
    EEPROM.write(1,0);
    EEPROM.write(2,128);
    EEPROM.commit();
     
    Serial.println("Waiting 10 seconds...");

      delay(10000);

  Serial.println("Reading EEPROM");
  Serial.println("");

   rgb_code[1] = int(EEPROM.read(0));
    rgb_code[2] = int(EEPROM.read(1));
    rgb_code[3] = int(EEPROM.read(2));

    colour = "RGB - ";
    colour += rgb_code[1];
    colour += ":";
    colour += rgb_code[2];
    colour += ":";
    colour += rgb_code[3];

    Serial.println(colour);
  }


void loop()
   
{
}
 


The code always print 0:0:0 which indicates that the EEPROM write has not been carried out, in addition infoo online indicates that the EEPROM should return 255 if no value has been previously written. Am I making a simple error in my code? Is the .commit required after the write, adding it makes no difference.

nscripta

Re: ESP8266 ESP-12F NodeMCU - Simple EEPROM write/read fails

PostPosted: Tue Jun 21, 2016 7:45 am
by martinayotte
You don't have any EEPROM.begin(); in your setup().

Re: ESP8266 ESP-12F NodeMCU - Simple EEPROM write/read fails

PostPosted: Wed Jun 22, 2016 1:02 pm
by nscripta
Thanks,

The EEPROM.begin(4) was exactly what I needed, the examples I had found were obviously not specific to the ESP8266.

nscripta