Arduino library for interfacing with various I2C EEPROM devices.
This library provides a simple and consistent interface to read and write data to I2C EEPROM devices. It supports both direct memory access and Arduino Stream interface compatibility, making it easy to use EEPROMs for data storage in your Arduino projects. The library includes automatic write cycle timing, address validation, and optimized page write operations when supported by the device and platform.
Install via the Arduino Library Manager by searching for "Sitron Labs EEPROM".
Alternatively, install manually:
- Download or clone this repository
- Place it in your Arduino
librariesfolder - Restart the Arduino IDE
Install via the PlatformIO Library Manager by searching for "Sitron Labs EEPROM".
Alternatively, add the library manually to your platformio.ini file:
lib_deps =
https://github.com/sitronlabs/SitronLabs_Generic_EEPROM_Arduino_Library.git| Device | Description | Memory Size | Page Size | Status |
|---|---|---|---|---|
| M24C64 | 64 Kbit I2C EEPROM | 8,192 bytes | 32 bytes | ✅ Implemented |
Initializes the EEPROM device.
i2c_library: I2C library instance to use (typicallyWire)i2c_address: I2C address of the EEPROM device
Returns 0 on success, or a negative error code otherwise.
Detects if the EEPROM device is present on the I2C bus.
Returns true if device is detected, false otherwise.
Reads data from the EEPROM.
address: Starting address to read fromdata: Pointer to buffer where read data will be storedlength: Number of bytes to read
Returns the number of bytes read on success, or a negative error code otherwise.
Writes data to the EEPROM.
address: Starting address to write todata: Pointer to buffer containing data to writelength: Number of bytes to write
Returns the number of bytes written on success, or a negative error code otherwise.
The EEPROM classes inherit from Arduino's Stream class, providing the following methods:
seek_read(size_t index): Sets the read position for Stream operationsseek_write(size_t index): Sets the write position for Stream operationsavailable(): Returns the number of bytes available to readread(): Reads a byte from the EEPROMpeek(): Peeks at the next byte without removing itwrite(uint8_t data): Writes a byte to the EEPROMprint(): Prints data to the EEPROMprintln(): Prints data with a newline
size_total_get(): Returns the total memory size in bytessize_page_get(): Returns the page size in bytes
All methods return an integer error code:
0or positive: Success (number of bytes read/written)- Negative values: Error codes
Common error codes:
-EINVAL: Invalid parameter (address out of range, null pointer)-EIO: I2C communication error-ETIMEDOUT: Device not responding
- Communication interface: I2C
- Stream interface: Compatible with Arduino Stream class
- Page write support: Optimized when supported by device and platform
- Automatic write timing: Built-in write cycle completion detection
- Address validation: Automatic bounds checking and rollover prevention