On an Arduino, I'm recording some data to external EEPROM (24LC256 by I2C) in a CSV format.
My sketch to Write seems to work , as indicated by troubleshooting code I added that after every write, does a read and prints to serial monitor.
But my sketch to Read to Serial Monitor fails b/c repeatedly reads off the same data. (I'm not sure it is actually row/record.)
I got the same result with 2 different I2C/EEPROM modules, 2 different Arduinos and with similar code written by two people.
--- Here is Write sketch (with lines to read that I added for troubleshooting) : result to Ser Mon is correct: rows of CSV with incrementing SampleCounter and values as expected from random().
/* Library: SparkFun_External_EEPROM_Arduino_Library Stores serial number and 2 values Also reads to get confirmation on Ser mon.*/
#include <Wire.h>
#include "SparkFun_External_EEPROM.h" //
ExternalEEPROM myMem;
String sample2Write = ""; // build up data from one sample
String sampleRead = "";
int sampleCounter = 0;
int sampleSize = 32; // bytes
void setup() //////////////////////////////////////////
{
Serial.begin(9600);
Wire.begin();
if (myMem.begin() == false) {
Serial.println("No memory detected. Freezing.");
while (1);
}
} // setup
void loop() {
delay(1000);
sampleCounter++;
// WRITE ////////////////////////////////////////////////////
sample2Write = "";
sample2Write = sample2Write + String(" - ") + "," ; // for future
sample2Write = sample2Write + String(sampleCounter) + "," ;
sample2Write = sample2Write + String(random(10, 20)) + "," ;
sample2Write = sample2Write + String(random(21, 30));
myMem.put(sampleCounter * sampleSize, sample2Write); //(location, data)
// following read is just to observe data real-time for troubleshooting
// actual read is different sketch
sampleRead = "";
myMem.get(sampleCounter * sampleSize, sampleRead); // location, receiver var
Serial.println(sampleRead);
} // loop
--- Here is Read.ino sketch: Problem is Ser Mon shows rows of CSV but always the same data (probably not even actual saved values)
/* Library: SparkFun_External_EEPROM_Arduino_Library*/
#include <Wire.h>
#include "SparkFun_External_EEPROM.h" //
ExternalEEPROM myMem;
String sampleRead = "";
int sampleSize = 32; // bytes
int sampleCounter = 0;
void setup() //////////////////////////////////////////
{
Serial.begin(9600);
Wire.begin();
if (myMem.begin() == false){
Serial.println("No memory detected. Freezing.");
while (1); }
} // setup
void loop(){
delay(300);
// READ DATA then display to serial monitor //////////
sampleCounter++;
sampleRead="",
myMem.get(sampleCounter*sampleSize, sampleRead); // location, receiver var
Serial.println(sampleRead);
} // loop