This library (with examples) is designed to be integrated in projects using I2C EEPROM. It can read and write data from I2C EEPROMs. It has been fully tested with 24LC256 device but should work with others.
It should be compatible with 24LCxxx and CAT24Cxxx EEPROMs:
- 24LC512, 24LC256, 24LC128, ...
- CAT24C01, CAT24C02, CAT24C04, CAT24C08, CAT24C16, ...
-
On your Arduino IDE, click "Sketch" menu and then "Include Library > Add .ZIP Libraries"
-
You can now use the library for your project or launch an example ("File > Examples")
Most of I2C EEPROMs are connected the same way.
Here are the pin connections for 24LC256 device:
24LC256 | Arduino Source |
---|---|
VCC | 5V |
GND | GND |
SCL | SCL (A5) |
SDA | SDA (A4) |
Others | GND (-> I2C address = 0x50) |
- If you use a 24LCxxx EEPROM, you can initialize the EEPROM this way:
#define CHIP_ADDRESS 0x50 // Address of EEPROM chip
I2CEEPROM i2c_eeprom(CHIP_ADDRESS);
// Read and write the same value from EEPROM
i2c_eeprom.write(0 /* value address */, 15 /* value to write */);
unsigned int read_value = i2c_eeprom.read(0 /* value address */);
- If you use a CAT24Cxx EEPROM, you need to initialize the EEPROM this way:
#define CHIP_ADDRESS 0x50 // Address of EEPROM chip
#define CAT_EEPROM_DEVICE EEPROM_DEVICE_CAT24C01 // You can use one of those elements: EEPROM_DEVICE_CAT24C01, EEPROM_DEVICE_CAT24C02, EEPROM_DEVICE_CAT24C04, EEPROM_DEVICE_CAT24C08, EEPROM_DEVICE_CAT24C16
I2CEEPROM i2c_eeprom(CHIP_ADDRESS, CAT_EEPROM_DEVICE);
// Read and write the same value from EEPROM
i2c_eeprom.write(0 /* value address */, 15 /* value to write */);
unsigned int read_value = i2c_eeprom.read(0 /* value address */);
- If you use an other EEPROM, it should work the same way as 24LCxxx EEPROM (maybe not the same I2C address)
Three examples are provided with this library:
This project is under MIT license. This means you can use it as you want (just don't delete the library header).
If you want to add more examples or improve the library, just create a pull request with proper commit message and right wrapping.