24c04 writing issue

I really must apologize. :frowning:

Somehow, between the sketch that I tested and the sketch that I posted, Wire.begin() got left out of setup. I usually download what I post and run the code, but somehow I didn't do it with this posting.

Try again with Wire.begin() added at the top of setup and see if you can store and retrieve the 16 bit and 32 bit values.

If you need help incorporating the techniques demonstrated into your sketch let me know. I owe you one.

Wire.begin() ...Now it's saving .. Thanks ..

i am trying to save the string data inside the eeprom

https://playground.arduino.cc/Code/I2CEEPROM/#`#include <Wire.h>

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

// 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, byte eeaddresspage, byte* data, byte length ) {
Wire.beginTransmission(deviceaddress);
//Wire.write((int)(eeaddresspage >> 8)); // MSB
//Wire.write((int)(eeaddresspage & 0xFF)); // LSB
Wire.write(eeaddresspage);
byte c;
for ( c = 0; c < length; c++)
Wire.write(data[c]);
Wire.endTransmission();
delay(5);
}

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

// maybe let's not read more than 30 or 32 bytes at a time!
void i2c_eeprom_read_buffer( int deviceaddress, byte eeaddress, byte *buffer, int length ) {
Wire.beginTransmission(deviceaddress);
//Wire.write((int)(eeaddress >> 8)); // MSB
//Wire.write((int)(eeaddress & 0xFF)); // LSB
Wire.write(eeaddress);
Wire.endTransmission();
Wire.requestFrom(deviceaddress,length);
int c = 0;
for ( c = 0; c < length; c++ )
if (Wire.available()) buffer[c] = Wire.read();
}

void setup()
{
char somedata = "this is data from the eeprom"; // data to write
Wire.begin(); // initialise the connection
Serial.begin(9600);
i2c_eeprom_write_page(0x50, 0, (byte *)somedata, sizeof(somedata)); // write to EEPROM

delay(100); //add a small delay

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(" ");
delay(2000);

}`

actual print out data : this is data from the eeprom

but it's saving only half data & print half data

16:46:51.294 -> Memory written
16:46:51.294 -> m the eeprom
16:46:53.309 -> m the eeprom
16:46:55.297 -> m the eeprom
16:46:57.330 -> m the eeprom
16:46:59.307 -> m the eeprom

Your code is not posted correctly.
Please learn how to post formatted code within code tags.
There is an automatic function for doing this in the Arduino-IDE
just three steps

1)press Ctrl-T for autoformatting your code
2)do a right click with the mouse and choose "copy for forum"
3)paste clipboard into write-window of a posting

Please read "How To Use This Forum".

Your code should appear in a block like this:

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

but it's saving only half data & print half data

You can not perform a block write across page boundaries. The data will wrap to the beginning of the page. Here is a better tutorial which give some information on how to manage the page boundary and wire library buffer limits.
https://www.hobbytronics.co.uk/eeprom-page-write
Your page size looks to be 16 bytes with the eeprom you are using.
You may also want to try using the extEEPROM.h library. Available through the library manager.

hi .. extEEPROM usage is my beyond my level . requesting you to give small example code (Write & Read of Few string data , integer data , float data..)using ext eeprom library .. so that i can understand something start further using the library . i have checked github but examples not easy understanding one .. apologies me for making you restless ...

I have had some issues with the PaoloP74 fork of the Christensen which is the library which comes from the library manger. I would delete that, and instead download the zip version of the original Christensen library from https://github.com/JChristensen/extEEPROM and install it with the add .ZIP library.

Let's see if that library works with the 2k eeprom by using this simple sketch to store a long character string. Unfortunately I don't have a small eeprom to test with, but this code works with a 24C32


#include <Wire.h>
//Christensen v3.0 extEEPROM.h
#include <extEEPROM.h>

//24C02 EEPROM 2kbits, 256 bytes, 16 byte page length
//constructor
//extEEPROM(eeprom_size_t deviceCapacity, byte nDevice, unsigned int pageSize, byte eepromAddr = 0x50);

extEEPROM eep(kbits_2, 1, 16, 0x50);

char test[] = {
  "Hello-1234567890-and-abcdefghijklmnopqrstuvwxyz-Goodbye\n"
};//null terminated character array

char buffer[100]; //output buffer

void setup()
{
  Serial.begin(9600);
  Wire.begin();

  int length = sizeof(test);
  Serial.print("Length   ");
  Serial.print(length);
  Serial.println();

  //return byte z for error checking on write over end of EEPROM
  //EEPROM_ADDR_ERR defined as 9 in library

  byte error = eep.write (0, test, sizeof(test)); //included null terminator
  Serial.print("Error status returned = ");
  Serial.println(error);
  if (error == 9) {
    Serial.println("ERROR ADDRESS TOO LARGE FOR EEPROM");
    return;
  }
  if (error != 0 && error != 9) {
    Serial.println("I2C ERROR");
    return;
  }
  if (error == 0) {
    Serial.println("No Errors");
  }

  eep.read(0, buffer, sizeof(test));

  Serial.println(buffer);
  Serial.println();

}

void loop()
{
}

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