The AT24C256 is an I2C EEPROM (Electrically Erasable Programmable Read-Only Memory) that allows the Raspberry Pi to store and retrieve data even after power loss. This guide explains how to interface the AT24C256 with the Raspberry Pi, including wiring, enabling I2C, and reading/writing data using Python.
What You Will Need
- Raspberry Pi (any model with GPIO and I2C support, e.g., Pi 3, Pi 4)
- AT24C256 EEPROM Module
- Breadboard and Jumper Wires
- Python installed on the Raspberry Pi
Step 1: Wiring the AT24C256 to the Raspberry Pi
The AT24C256 communicates using the I2C protocol.
Connections
AT24C256 Pin | Raspberry Pi Pin |
---|---|
VCC | 3.3V (Pin 1) |
GND | Ground (Pin 6) |
SDA | SDA (Pin 3, GPIO2) |
SCL | SCL (Pin 5, GPIO3) |
WP (Write Protect) | GND (Disable write protection) |
Step 2: Enable I2C on the Raspberry Pi
- Open the Raspberry Pi configuration tool:
- Navigate to Interface Options > I2C and enable it.
- Reboot the Raspberry Pi:
Step 3: Install Required Libraries
- Update your Raspberry Pi’s package list:
- Install the necessary I2C tools and Python libraries:
- Verify that the AT24C256 EEPROM is detected on the I2C bus: The EEPROM should appear at 0x50 (or another address based on A0-A2 pin configurations).
Step 4: Reading and Writing Data to the AT24C256
The AT24C256 stores data in 256KB of memory, and each byte is accessed using its memory address.
Writing Data to EEPROM
Reading Data from EEPROM
Step 5: Applications of the AT24C256
- Data Logging: Store sensor data over time for offline access.
- Configuration Storage: Save system settings or calibration data.
- Secure Authentication: Store encrypted keys or authentication tokens.
- IoT Projects: Enable persistent storage for Internet of Things applications.
Troubleshooting
-
EEPROM Not Detected:
- Check wiring and confirm SDA/SCL connections.
- Run
sudo i2cdetect -y 1
to verify the EEPROM’s I2C address.
-
Incorrect Read/Write Operations:
- Ensure Write Protect (WP) is grounded to enable writing.
- Introduce delays (
time.sleep(0.05)
) to allow EEPROM write operations to complete.
-
I2C Communication Errors:
- Check for conflicting I2C addresses on the bus.
- Ensure
smbus2
is properly installed usingpip3 install smbus2
.
Conclusion
The AT24C256 EEPROM is a simple yet powerful way to store data persistently on a Raspberry Pi. Whether for data logging, storing settings, or IoT applications, this guide provides the foundational knowledge needed to interact with EEPROM storage effectively. Experiment with reading/writing larger datasets to explore its full potential! 🚀