I'm recording some data to external EEPROM (I2C) in a CSV format.
My sketch to Write seems to work , as indicated by troubleshooting code I added that does a read to Serial Monitor after each write.
But my sketch to Read to Serial Monitor fails b/c repeatedly reads off the same record.
I got the same result with 2 different I2C/EEPROM modules, 2 different Arduinos and with similar code written by two people.
--- Write sketch (with lines to read that I added for troubleshooting) :
result to Ser Mon is rows of CSV with incrementing SampleCounter and values as expected from random()
#include <Wire.h>
#include "SparkFun_External_EEPROM.h" //
ExternalEEPROM myMem;
String sample2Write = ""; // build up data from one sample
String sampleRead = "";
int sampleSize = 200; // for demo, each sample= 200 *bits*
int sampleCounter = 1;
void setup() //////////////////////////////////////////
{
Serial.begin(9600);
Wire.begin();
// create and check connect to Ext EEPROM
if (myMem.begin() == false){
Serial.println("No memory detected. Freezing.");
while (1);}
} // setup
void loop(){
delay(3000);
sampleCounter++;
// WRITE ////////////////////////////////////////////////////
sample2Write = "";
// sample # and address
sample2Write = sample2Write + String(" - ") + "," ; // spacer for SerMon display
sample2Write = sample2Write + String(sampleCounter) + "," ;
sample2Write = sample2Write + String(random(10, 20)) + "," ;
sample2Write = sample2Write + String(random(21, 30)) + "," ;
// write to external EEPROM
myMem.put(sampleCounter*sampleSize, sample2Write); //(location, data)
// READ DATA /////////////////////////////////////////////
sampleRead="",
myMem.get(sampleCounter*sampleSize, sampleRead); // location, receiver var
Serial.println(sampleRead);
} // loop
--- Read sketch: result to Ser Mon is rows of CSV with values but always the same sampleCounter and same data
#include <Wire.h>
#include "SparkFun_External_EEPROM.h" //
ExternalEEPROM myMem;
String sampleRead = "";
int sampleSize = 200; // for demo, each sample= 200 *bits*
int sampleCounter = 1;
void setup() //////////////////////////////////////////
{
Serial.begin(9600);
Wire.begin();
if (myMem.begin() == false)
{
Serial.println("No memory detected. Freezing.");
while (1);
}
} // setup
void loop(){
delay(3000);
// READ DATA /////////////////////////////////////////////
sampleCounter++;
sampleRead="",
myMem.get(sampleCounter*sampleSize, sampleRead); // location, receiver var
Serial.println(sampleRead);
} // loop