#include <Wire.h>
#include "AT24CXX.h"
#define EEPROM_I2C_ADDRESS 0x57
AT24C64 at24c64;
void setup()
{
Wire.begin();
pinMode(8, OUTPUT);
pinMode(12, OUTPUT);
digitalWrite(8, HIGH); // Write protect test
digitalWrite(12, LOW);
Serial.begin(9600);
at24c64.begin(EEPROM_I2C_ADDRESS);
// --- Example 1: Write and Read a 4-byte integer (uint32_t) ---
uint32_t data = 0xAE962B61;
// Write the uint32_t by casting it to a byte array and specifying 4 bytes length
at24c64.write(4000, (byte*)&data, sizeof(data));
// To read the integer back, we must read 4 bytes into a temporary buffer
// and reconstruct the uint32_t. The library's 'read' function is used for this.
uint32_t readData;
// Read 4 bytes from address 4000 into the memory location of readData
at24c64.read(4000, (byte*)&readData, sizeof(readData));
Serial.print("Read integer: 0x");
Serial.println(readData, HEX);
// --- Example 2: Write and Read a string ---
char *str = "abcdefghijklmnopqrstuvwxyz0123456789";
char strR[strlen(str)+1]; // Ensure the buffer size is correct
at24c64.write(50,(byte*)str,strlen(str)+1);
at24c64.read(50,(byte*)strR,strlen(str)+1);
Serial.print("Read string: ");
Serial.println(strR);
Serial.print("Comparison result (0 means identical): ");
Serial.println(strcmp(str,strR));
}
void loop()
{
}