External EEPROM - Read code just repeats one record

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

Which controller do you use?

What exactly does this method do?
How many bytes are read?

Thanks, Dr. Diettrich

Arduino Uno

.get is from the Arduino EEPROM library https://docs.arduino.cc/learn/built-in-libraries/eeprom

I'm writing and reading 200 bits for each sample (set of values = one line in CSV). That is 3 integers of 16 bits each and 8 characters of 8 bits each and some extra room for future (84 bits).

No, you don't :frowning:

Reading and writing is done in bytes, not bits, and dynamic data types like String are not supported. Most probably you write a pointer and read it back, so that you happen to log the String still stored in RAM.

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