ESP8266 ESP-12F NodeMCU - Simple EEPROM write/read fails!
Posted: Mon Jun 20, 2016 4:02 pm
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.
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
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