Eeprom data copying to buffer

i want to move eeprom data's to buffer and then displaying the data via Serial.print or lcd .print . currently code doing Serial.print inside the loop but i want copy the data to buffer like char with pointer . can anyone suggest the code's to move the data from eeprom to buffer memory .

#include <Wire.h>

 char somedata[] = "GREAT"; // data to write
 char somedata1[] = "good"; // data to write
 char somedata2[] = "okok";
 uint16_t intValue = 105;
 uint8_t d = 255;
 
 char somedata3[] = "1235.25689";


void i2c_eeprom_write_byte( int deviceaddress, unsigned int eeaddress, byte data ) {
    int rdata = data;
    Wire.beginTransmission(deviceaddress);
    Wire.write((int)(eeaddress >> 8)); // MSB
    Wire.write((int)(eeaddress & 0xFF)); // LSB
    Wire.write(rdata);
    Wire.endTransmission();
    delay(10);
}

// WARNING: address is a page address, 6-bit end will wrap around
// also, data can be maximum of about 30 bytes, because the Wire library has a buffer of 32 bytes
void i2c_eeprom_write_page( int deviceaddress, unsigned int eeaddresspage, byte* data, byte length ) {
    Wire.beginTransmission(deviceaddress);
    Wire.write((int)(eeaddresspage >> 8)); // MSB
    Wire.write((int)(eeaddresspage & 0xFF)); // LSB
    byte c;
    for ( c = 0; c < length; c++)
        Wire.write(data[c]);
    Wire.endTransmission();
    delay(10);
}

byte i2c_eeprom_read_byte( int deviceaddress, unsigned int eeaddress ) {
    byte rdata = 0xFF;
    Wire.beginTransmission(deviceaddress);
    Wire.write((int)(eeaddress >> 8)); // MSB
    Wire.write((int)(eeaddress & 0xFF)); // LSB
    Wire.endTransmission();
    Wire.requestFrom(deviceaddress,1);
    if (Wire.available()) rdata = Wire.read();
    return rdata;

void setup()
{
   
    Wire.begin(); // initialise the connection
    Serial.begin(9600);
    i2c_eeprom_write_page(0x50, 0, (byte *)somedata, sizeof(somedata)); // write to EEPROM
    
   
    i2c_eeprom_write_page(0x50, 64, (byte *)somedata1, sizeof(somedata1)); 
    
    i2c_eeprom_write_page(0x50, 128, (byte *)somedata2, sizeof(somedata2)); 
    
    i2c_eeprom_write_byte(0x50, 192, d); 
    
           
   i2c_eeprom_write_byte(0x50, 256, lowByte(intValue));  
   
   i2c_eeprom_write_byte(0x50, 257, highByte(intValue)) ;

    //i2c_eeprom_write_page(0x50, 60, (byte *)somedata3, sizeof(somedata3));    
       

    Serial.println("Memory written");
}

void loop()
{
    int addr=0; //first address
    byte b = i2c_eeprom_read_byte(0x50, 0); // access the first address from the memory

    while (b!=0)
    {
        Serial.print((char)b); //print content to serial port
        addr++; //increase address
        b = i2c_eeprom_read_byte(0x50, addr); //access an address from the memory
    }
    Serial.println(" ");
        
    int addr1=64;
    byte e = i2c_eeprom_read_byte(0x50, 64); // access the first address from the memory
    while (e!=0)
    {
        Serial.print((char)e); //print content to serial port
       addr1++; //increase address
        e = i2c_eeprom_read_byte(0x50, addr1); //access an address from the memory
    }
    Serial.println(" ");
    int addr2= 128;
    byte f = i2c_eeprom_read_byte(0x50, 128); // access the first address from the memory
    while (f!=0)
    {
        Serial.print((char)f); //print content to serial port
       addr2++; //increase address
        f = i2c_eeprom_read_byte(0x50, addr2); //access an address from the memory
    }
    
    
    Serial.println(" ");
    byte g;
    int addr3 = 192;
    g = i2c_eeprom_read_byte(0x50, addr3);
    Serial.print(g);
    Serial.println(" ");
    
    byte l  = i2c_eeprom_read_byte(0x50, 256);
    byte h = i2c_eeprom_read_byte(0x50, 257);
    int combineInt = word(h,l);
    
    Serial.print(combineInt); 
    Serial.println(" ");    
    /*int addr5= 60;
    byte z = i2c_eeprom_read_byte(0x50, 60); // access the first address from the memory
    while (z!=0)   
    {              
        Serial.print((char)z);//print content to serial port
        addr5++; //increase address
        z = i2c_eeprom_read_byte(0x50, addr5); //access an address from the memory
    }    
    */
           
    Serial.println(" ");
    
    delay(2000);
}
byte i2c_eeprom_read_byte( int deviceaddress, unsigned int eeaddress ) {
    byte rdata = 0xFF;
    Wire.beginTransmission(deviceaddress);
    Wire.write((int)(eeaddress >> 8)); // MSB
    Wire.write((int)(eeaddress & 0xFF)); // LSB
    Wire.endTransmission();
    Wire.requestFrom(deviceaddress,1);
    if (Wire.available()) rdata = Wire.read();
    return rdata;

    void setup()
    {
        Wire.begin(); // initialise the connection
        Serial.begin(9600);

there's a missing closing brace before void setup().

doubt this fixes your problem. don't understand why you posted code that doesn't compile

This will read your first variable into a buffer. It is up to you to maybe turn this into a function you can use for any of your variables

#include <Wire.h>

char somedata[] = "GREAT"; // data to write
char somedata1[] = "good"; // data to write
char somedata2[] = "okok";
uint16_t intValue = 105;
uint8_t d = 255;

char somedata3[] = "1235.25689";


void i2c_eeprom_write_byte( int deviceaddress, unsigned int eeaddress, byte data ) {
  int rdata = data;
  Wire.beginTransmission(deviceaddress);
  Wire.write((int)(eeaddress >> 8)); // MSB
  Wire.write((int)(eeaddress & 0xFF)); // LSB
  Wire.write(rdata);
  Wire.endTransmission();
  delay(10);
}

// WARNING: address is a page address, 6-bit end will wrap around
// also, data can be maximum of about 30 bytes, because the Wire library has a buffer of 32 bytes
void i2c_eeprom_write_page( int deviceaddress, unsigned int eeaddresspage, byte* data, byte length ) {
  Wire.beginTransmission(deviceaddress);
  Wire.write((int)(eeaddresspage >> 8)); // MSB
  Wire.write((int)(eeaddresspage & 0xFF)); // LSB
  byte c;
  for ( c = 0; c < length; c++)
    Wire.write(data[c]);
  Wire.endTransmission();
  delay(10);
}

byte i2c_eeprom_read_byte( int deviceaddress, unsigned int eeaddress ) {
  byte rdata = 0xFF;
  Wire.beginTransmission(deviceaddress);
  Wire.write((int)(eeaddress >> 8)); // MSB
  Wire.write((int)(eeaddress & 0xFF)); // LSB
  Wire.endTransmission();
  Wire.requestFrom(deviceaddress, 1);
  if (Wire.available()) rdata = Wire.read();
  return rdata;
}

void setup() {

  Wire.begin(); // initialise the connection
  Serial.begin(9600);
  i2c_eeprom_write_page(0x50, 0, (byte *)somedata, sizeof(somedata)); // write to EEPROM
  i2c_eeprom_write_page(0x50, 64, (byte *)somedata1, sizeof(somedata1));
  i2c_eeprom_write_page(0x50, 128, (byte *)somedata2, sizeof(somedata2));
  i2c_eeprom_write_byte(0x50, 192, d);
  i2c_eeprom_write_byte(0x50, 256, lowByte(intValue));
  i2c_eeprom_write_byte(0x50, 257, highByte(intValue)) ;
  Serial.println("Memory written");
}

void loop() {
  const int bufferSize = 30;
  char buffer[bufferSize];
  int index = 0;
  int addr = 0; //first address
  byte b;

  do {
    b = i2c_eeprom_read_byte(0x50, addr); // access the first address from the memory
    buffer[index++] = b;
    addr++; //increase address
    if ( index >= bufferSize ) {
      Serial.println("Buffer to small" );
      while (1);
    }
  }  while (b != 0);
  Serial.print( "buffer = " );
  Serial.println( buffer );
  delay(2000);
}

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