AT24C256 Arduino: 32 KB External EEPROM, Page Write and Code
AT24C256 Arduino guide: 32 KB I2C external EEPROM, address pins, 64-byte page write and 5 ms delay, storing settings, ESP32 data logging and SD card comparison.
In AT24C256 Arduino projects the AT24C256 is a 32 KB external memory that keeps its data even when the power goes off. It connects over I2C with just two wires (SDA and SCL), can be written 1,000,000 times and retains its data for at least 40 years. Since the Arduino Uno's own EEPROM is only 1 KB, the AT24C256 is a cheap, practical solution for projects that need to store settings, passwords, counters and small measurement logs; on the ESP32 it's ideal for frequently written data that would otherwise wear out the flash.
In this article you'll learn how the AT24C256 works, how to put eight chips on the same bus with the A0, A1, A2 address pins, how page writes of 64 bytes work and the 5 ms delay after every write. We'll write a library-free read/write on the Arduino Uno, CRC-protected settings storage, a ring-buffer data logger on the ESP32 and a MicroPython example for the Raspberry Pi Pico. At the end you'll compare internal EEPROM, the AT24C256 and an SD card and see which one to choose when.
What is the AT24C256 and how does it work?
The AT24C256 is a chip from Microchip's (formerly Atmel) serial EEPROM family. The 256 in its name is the capacity in kilobits: 256 Kbit ÷ 8 = 32,768 bytes, or 32 KB. The memory is split into 512 pages of 64 bytes, and every byte has an address between 0 and 32767, sent as two bytes (high and low). Reading is fast and you can read as much as you like. Writing is slow: the chip first takes the data into an internal buffer, then programs the cells once the I2C transfer ends, and this internal write cycle takes up to 5 ms. During that time the chip doesn't respond on I2C. If you haven't seen the basics of EEPROM and the Arduino's internal EEPROM yet, start with the Arduino EEPROM article.
| Feature | AT24C256 |
|---|---|
| Capacity | 256 Kbit = 32,768 bytes (32 KB) |
| Page | 64 bytes, 512 pages in total |
| Interface | I2C: 100 kHz, 400 kHz (1 MHz on the C version) |
| Supply | 1.7–5.5 V (AT24C256C); 5 V on the Uno, 3.3 V on the ESP32 and Pico |
| Write cycle | Up to 5 ms (same for a byte or a page) |
| Endurance | 1,000,000 writes per byte |
| Data retention | At least 40 years (100 years on the C version) |
| Current | A few mA while writing, a few µA in standby |
| I2C address | 0x50–0x57 (set by A0, A1, A2) |
AT24C256 pinout and I2C address
| Pin | Name | Function |
|---|---|---|
| 1, 2, 3 | A0, A1, A2 | Address select: GND = 0, VCC = 1; jumpers or DIP switch on modules |
| 4 | GND | Ground |
| 5 | SDA | I2C data line |
| 6 | SCL | I2C clock line |
| 7 | WP | Write protect: GND = writable, VCC = whole memory read-only |
| 8 | VCC | Supply (1.7–5.5 V) |
The chip's base address is 0x50; the A0, A1 and A2 pins set the last three bits of that address. With all three tied to GND the address is 0x50, with all three at VCC it is 0x57. That lets you connect eight AT24C256 chips to the same I2C bus for a total of 256 KB. Older AT24C256B versions have no A2 pin (pin 3 is not connected), so at most four chips can share a bus; the marking on the chip tells you which version your module carries. If you're not sure of your module's address, run an I2C scanner; that's covered in the What is I2C article.
| A2 | A1 | A0 | I2C address |
|---|---|---|---|
| GND | GND | GND | 0x50 |
| GND | GND | VCC | 0x51 |
| GND | VCC | GND | 0x52 |
| GND | VCC | VCC | 0x53 |
| VCC | GND | GND | 0x54 |
| VCC | GND | VCC | 0x55 |
| VCC | VCC | GND | 0x56 |
| VCC | VCC | VCC | 0x57 |
Wiring: Arduino Uno, ESP32 and Raspberry Pi Pico
| AT24C256 module | Arduino Uno / Nano | ESP32 | Raspberry Pi Pico |
|---|---|---|---|
| VCC | 5V | 3V3 | 3V3 (OUT) |
| GND | GND | GND | GND |
| SDA | A4 | GPIO 21 | GP4 (I2C0 SDA) |
| SCL | A5 | GPIO 22 | GP5 (I2C0 SCL) |
| WP | GND (writable) | GND | GND |
| A0, A1, A2 | GND (address 0x50) | GND | GND |
Page write and the 5 ms delay
You can write bytes to the AT24C256 one at a time, but you have to wait 5 ms for each: filling 32 KB byte by byte takes about 164 seconds. With a page write you send up to 64 bytes in one I2C transfer and still wait only once for 5 ms; the whole memory fills in 512 × 5 ms, about 2.6 seconds. There are two rules to watch. First, a page write can't cross a page boundary: if you start at address 50 and write 20 bytes, the last 6 bytes that don't fit wrap around not to address 64 but to the first byte of the same page (address 0) and overwrite the old data there. That's why the code splits every transfer at the page boundary. Second, the Arduino Uno's Wire library has a 32-byte buffer; since 2 bytes go to the address, you can send at most 30 data bytes per transfer. The code uses 16-byte chunks, which divide 64 evenly. The ESP32's Wire buffer is 128 bytes, so a full 64-byte page fits there. Instead of blindly waiting 5 ms you can also use ACK polling: the chip doesn't answer to its address until the internal write is done, and the moment it answers you move on to the next write.
| Method | Per write | Time to fill 32 KB | Note |
|---|---|---|---|
| Byte by byte | 1 byte + 5 ms | About 164 s | Simplest, slowest |
| 16-byte chunks on the Uno | 16 bytes + 5 ms | About 10 s | Fits the AVR Wire buffer |
| Full page on the ESP32 | 64 bytes + 5 ms | About 2.6 s | Wire buffer is 128 bytes |
| Reading (400 kHz) | No waiting | Under 1 s | The address increments automatically on sequential reads |
Arduino code: read and write without a library
1// AT24C256 kütüphanesiz okuma/yazma: sayfa sınırı ve ACK yoklaması (Arduino Uno)
2// AT24C256 read/write without a library: page boundary and ACK polling (Arduino Uno)
3#include <Wire.h>
4
5const uint8_t EEPROM_ADDR = 0x50; // A0 = A1 = A2 = GND
6const uint16_t PAGE_SIZE = 64; // AT24C256 sayfası 64 bayt / AT24C256 page is 64 bytes
7const uint8_t CHUNK = 16; // AVR Wire tamponu 32 bayt: 2 adres + en çok 30 veri / AVR Wire buffer is 32 bytes
8
9bool waitReady() { // ACK yoklaması: yazma bitince yonga cevap verir / ACK polling: chip answers when the write is done
10 for (uint8_t i = 0; i < 20; i++) {
11 Wire.beginTransmission(EEPROM_ADDR);
12 if (Wire.endTransmission() == 0) return true;
13 delay(1);
14 }
15 return false; // 20 ms içinde cevap yok / no answer within 20 ms
16}
17
18void writeBuffer(uint16_t addr, const uint8_t *data, uint16_t len) {
19 while (len > 0) {
20 uint16_t room = PAGE_SIZE - (addr % PAGE_SIZE); // bu sayfada kalan yer / space left in this page
21 uint8_t n = min((uint16_t)CHUNK, min(len, room));
22 Wire.beginTransmission(EEPROM_ADDR);
23 Wire.write((uint8_t)(addr >> 8)); // adresin yüksek baytı / address high byte
24 Wire.write((uint8_t)(addr & 0xFF)); // adresin düşük baytı / address low byte
25 Wire.write(data, n);
26 Wire.endTransmission();
27 waitReady(); // dahili yazma bitene kadar bekle / wait for the internal write
28 addr += n; data += n; len -= n;
29 }
30}
31
32void readBuffer(uint16_t addr, uint8_t *data, uint16_t len) {
33 while (len > 0) {
34 uint8_t n = min(len, (uint16_t)CHUNK);
35 Wire.beginTransmission(EEPROM_ADDR);
36 Wire.write((uint8_t)(addr >> 8));
37 Wire.write((uint8_t)(addr & 0xFF));
38 Wire.endTransmission();
39 Wire.requestFrom(EEPROM_ADDR, n);
40 for (uint8_t i = 0; i < n && Wire.available(); i++) data[i] = Wire.read();
41 addr += n; data += n; len -= n;
42 }
43}
44
45void setup() {
46 Serial.begin(9600);
47 Wire.begin();
48 Wire.setClock(400000); // 400 kHz hızlı mod / 400 kHz fast mode
49
50 Wire.beginTransmission(EEPROM_ADDR);
51 if (Wire.endTransmission() != 0) {
52 Serial.println(F("AT24C256 bulunamadi / not found"));
53 while (true) {}
54 }
55
56 const char text[] = "Merhaba BlueGrays! AT24C256 sayfa testi.";
57 uint16_t start = 50; // 64. bayttaki sayfa sınırını geçer / crosses the page boundary at byte 64
58 unsigned long t0 = millis();
59 writeBuffer(start, (const uint8_t *)text, sizeof(text));
60 Serial.print(F("Yazma suresi / Write time (ms): "));
61 Serial.println(millis() - t0);
62
63 char back[sizeof(text)];
64 readBuffer(start, (uint8_t *)back, sizeof(back));
65 Serial.print(F("Okunan / Read: "));
66 Serial.println(back);
67}
68
69void loop() {}In each pass writeBuffer() takes the smallest of three limits: the remaining data, the 16-byte chunk and the space left in that page. The 41-byte text in the example starts at address 50; the first transfer writes 14 bytes and stops at the 64 boundary, and the next transfers continue from address 64. After every transfer waitReady() calls the chip's address and waits until it answers; a typical chip is ready in 3–4 ms. readBuffer() first writes the address, then requests 16 bytes at a time with Wire.requestFrom(). The Serial Monitor shows the write time and the text read back. No library is needed; if you'd like to make things easier later, the "SparkFun External EEPROM" library or Rob Tillaart's "I2C_EEPROM" library in the Library Manager handle page splitting and waiting for you.
Storing settings: version, CRC and writing only on change
A device's settings (threshold, brightness, interval, device name) mustn't be lost when the power goes off. The cleanest approach is to collect the settings in a struct and write it in one go. But you have to make sure the data you read from the EEPROM is valid: a new chip comes filled with 0xFF, a power cut during a write can leave a half-written record, and if you update the firmware and add a field to the struct, the old data no longer fits the new layout. The code below uses three safeguards: a version byte, a CRC-8 checksum byte at the end of the struct and writing only on change. If the data fails the version or CRC check, the default settings are loaded and saved.
1// AT24C256 ile ayar saklama: sürüm, CRC ve yalnız değişince yazma (Arduino Uno)
2// Storing settings in an AT24C256: version, CRC and writing only on change (Arduino Uno)
3#include <Wire.h>
4
5const uint8_t EEPROM_ADDR = 0x50;
6const uint16_t SETTINGS_ADDR = 0; // ayarlar ilk sayfada / settings in the first page
7const uint8_t SETTINGS_VERSION = 2; // yapı değişince artır / increase when the struct changes
8
9struct Settings {
10 uint8_t version;
11 uint8_t brightness; // 0-255
12 int16_t threshold; // alarm eşiği / alarm threshold
13 uint16_t intervalSec; // ölçüm aralığı / measurement interval
14 char name[16]; // cihaz adı / device name
15 uint8_t crc; // en sonda / always last
16};
17
18Settings cfg;
19
20uint8_t crc8(const uint8_t *p, uint8_t len) { // Dallas/Maxim CRC-8
21 uint8_t crc = 0;
22 while (len--) {
23 uint8_t b = *p++;
24 for (uint8_t i = 0; i < 8; i++) {
25 uint8_t mix = (crc ^ b) & 0x01;
26 crc >>= 1;
27 if (mix) crc ^= 0x8C;
28 b >>= 1;
29 }
30 }
31 return crc;
32}
33
34void eepromWrite(uint16_t addr, const uint8_t *data, uint8_t len) { // ≤ 30 bayt, tek sayfa / ≤ 30 bytes, one page
35 Wire.beginTransmission(EEPROM_ADDR);
36 Wire.write((uint8_t)(addr >> 8));
37 Wire.write((uint8_t)(addr & 0xFF));
38 Wire.write(data, len);
39 Wire.endTransmission();
40 delay(5); // yazma çevrimi en çok 5 ms / write cycle max 5 ms
41}
42
43void eepromRead(uint16_t addr, uint8_t *data, uint8_t len) {
44 Wire.beginTransmission(EEPROM_ADDR);
45 Wire.write((uint8_t)(addr >> 8));
46 Wire.write((uint8_t)(addr & 0xFF));
47 Wire.endTransmission();
48 Wire.requestFrom(EEPROM_ADDR, len);
49 for (uint8_t i = 0; i < len && Wire.available(); i++) data[i] = Wire.read();
50}
51
52void setDefaults() {
53 cfg.version = SETTINGS_VERSION;
54 cfg.brightness = 128;
55 cfg.threshold = 500;
56 cfg.intervalSec = 60;
57 strncpy(cfg.name, "BlueGrays-1", sizeof(cfg.name));
58}
59
60void saveSettings() {
61 cfg.crc = crc8((const uint8_t *)&cfg, sizeof(cfg) - 1);
62 Settings old;
63 eepromRead(SETTINGS_ADDR, (uint8_t *)&old, sizeof(old));
64 if (memcmp(&old, &cfg, sizeof(cfg)) == 0) return; // aynıysa yazma, ömrü koru / skip if unchanged
65 eepromWrite(SETTINGS_ADDR, (const uint8_t *)&cfg, sizeof(cfg));
66 Serial.println(F("Kaydedildi / Saved"));
67}
68
69void loadSettings() {
70 eepromRead(SETTINGS_ADDR, (uint8_t *)&cfg, sizeof(cfg));
71 bool ok = cfg.version == SETTINGS_VERSION &&
72 cfg.crc == crc8((const uint8_t *)&cfg, sizeof(cfg) - 1);
73 if (!ok) { // boş, bozuk ya da eski sürüm / empty, corrupt or old version
74 Serial.println(F("Varsayilan ayarlar / Default settings"));
75 setDefaults();
76 saveSettings();
77 }
78}
79
80void printSettings() {
81 Serial.print(F("Esik / Threshold: ")); Serial.println(cfg.threshold);
82 Serial.print(F("Parlaklik / Brightness: ")); Serial.println(cfg.brightness);
83 Serial.print(F("Aralik / Interval (s): ")); Serial.println(cfg.intervalSec);
84 Serial.print(F("Ad / Name: ")); Serial.println(cfg.name);
85}
86
87void setup() {
88 Serial.begin(9600);
89 Wire.begin();
90 loadSettings();
91 printSettings();
92 Serial.println(F("Ornek / Example: t450 b200 i30"));
93}
94
95void loop() {
96 if (!Serial.available()) return;
97 char cmd = Serial.read();
98 long value = Serial.parseInt();
99 if (cmd == 't') cfg.threshold = value;
100 else if (cmd == 'b') cfg.brightness = constrain(value, 0, 255);
101 else if (cmd == 'i') cfg.intervalSec = constrain(value, 1, 3600);
102 else return;
103 saveSettings();
104 printSettings();
105}Type t450 in the Serial Monitor to set the threshold to 450, b200 to change the brightness and i30 to change the measurement interval; when you power the Arduino off and on, the values come back exactly. saveSettings() reads the current record before writing and skips the write if nothing changed; compared with code that rewrites the same settings at every boot, this greatly extends the chip's life. The struct is 23 bytes, so it fits in a single page and within the Uno's 30-byte limit. When you add a new field to the struct, increase SETTINGS_VERSION by one; the old record is then treated as invalid automatically. Note: structs can be aligned differently on different boards, so if you write the chip on an Uno and read it on an ESP32, write the fields byte by byte or fix the layout with __attribute__((packed)).
Data logging with the ESP32: a ring buffer
If you want to log a sensor once a minute, always writing to the same address wears it out quickly. A ring buffer solves this: records are written one after another from the start of the memory to the end, then it wraps around and the oldest record is overwritten. Each record is 8 bytes (4-byte sequence number, 2-byte measurement, 2 spare bytes), which fits 4096 records into 32 KB; since 8 divides 64 evenly, no record ever crosses a page boundary. Saving the next write address in a separate place would wear out that cell, so the code doesn't do that; at startup it reads all records and finds the largest sequence number, which takes about 1–2 seconds. With one record a minute each cell is written about once every 2.8 days; at that rate the 1,000,000-write endurance practically never runs out.
1// ESP32 + AT24C256 veri kaydedici: halka tampon, sıra numarası, CSV dökümü
2// ESP32 + AT24C256 data logger: ring buffer, sequence number, CSV dump
3#include <Wire.h>
4
5const uint8_t EEPROM_ADDR = 0x50;
6const int SDA_PIN = 21, SCL_PIN = 22; // ESP32 varsayılan I2C pinleri / ESP32 default I2C pins
7const int SENSOR = 34; // analog sensör (ADC1) / analog sensor (ADC1)
8const uint32_t MEM_SIZE = 32768; // 32 KB
9const uint8_t REC_SIZE = 8; // 8 bayt: sayfaya tam sığar / 8 bytes: fits a page exactly
10const uint16_t SLOTS = MEM_SIZE / REC_SIZE; // 4096 kayıt / 4096 records
11const uint32_t EMPTY = 0xFFFFFFFF; // silinmiş EEPROM 0xFF okur / erased EEPROM reads 0xFF
12const unsigned long PERIOD = 60000; // dakikada bir kayıt / one record per minute
13
14struct Record {
15 uint32_t seq; // artan sıra numarası / increasing sequence number
16 int16_t value; // ölçüm / measurement
17 uint16_t spare; // ileride kullanmak için / reserved
18};
19
20uint16_t nextSlot = 0;
21uint32_t nextSeq = 0;
22
23void waitReady() {
24 for (int i = 0; i < 20; i++) {
25 Wire.beginTransmission(EEPROM_ADDR);
26 if (Wire.endTransmission() == 0) return;
27 delay(1);
28 }
29}
30
31void writeRecord(uint16_t slot, const Record &r) {
32 uint16_t addr = slot * REC_SIZE;
33 Wire.beginTransmission(EEPROM_ADDR);
34 Wire.write((uint8_t)(addr >> 8));
35 Wire.write((uint8_t)(addr & 0xFF));
36 Wire.write((const uint8_t *)&r, REC_SIZE);
37 Wire.endTransmission();
38 waitReady();
39}
40
41void readRecord(uint16_t slot, Record &r) {
42 uint16_t addr = slot * REC_SIZE;
43 Wire.beginTransmission(EEPROM_ADDR);
44 Wire.write((uint8_t)(addr >> 8));
45 Wire.write((uint8_t)(addr & 0xFF));
46 Wire.endTransmission(false); // tekrarlanan başlangıç / repeated start
47 Wire.requestFrom(EEPROM_ADDR, REC_SIZE);
48 Wire.readBytes((uint8_t *)&r, REC_SIZE);
49}
50
51void findHead() { // en yeni kaydı bul / find the newest record
52 uint32_t best = EMPTY;
53 int bestSlot = -1;
54 Record r;
55 for (uint16_t s = 0; s < SLOTS; s++) {
56 readRecord(s, r);
57 if (r.seq != EMPTY && (best == EMPTY || r.seq > best)) { best = r.seq; bestSlot = s; }
58 }
59 if (bestSlot < 0) { nextSlot = 0; nextSeq = 0; }
60 else { nextSlot = (bestSlot + 1) % SLOTS; nextSeq = best + 1; }
61}
62
63void dumpCsv() { // eskiden yeniye CSV / oldest to newest as CSV
64 Record r;
65 readRecord(nextSlot, r);
66 uint16_t first = (r.seq == EMPTY) ? 0 : nextSlot; // doluysa en eski kayıt nextSlot'ta / if full, oldest is at nextSlot
67 Serial.println("seq;value");
68 for (uint16_t i = 0; i < SLOTS; i++) {
69 readRecord((first + i) % SLOTS, r);
70 if (r.seq == EMPTY) continue;
71 Serial.printf("%lu;%d\n", (unsigned long)r.seq, r.value);
72 }
73}
74
75void eraseAll() { // 512 sayfaya 0xFF yaz (~3 sn) / write 0xFF to 512 pages (~3 s)
76 uint8_t ff[64];
77 memset(ff, 0xFF, sizeof(ff));
78 for (uint32_t addr = 0; addr < MEM_SIZE; addr += 64) {
79 Wire.beginTransmission(EEPROM_ADDR);
80 Wire.write((uint8_t)(addr >> 8));
81 Wire.write((uint8_t)(addr & 0xFF));
82 Wire.write(ff, 64); // ESP32 Wire tamponu 128 bayt / ESP32 Wire buffer is 128 bytes
83 Wire.endTransmission();
84 waitReady();
85 }
86 nextSlot = 0; nextSeq = 0;
87}
88
89void setup() {
90 Serial.begin(115200);
91 Wire.begin(SDA_PIN, SCL_PIN, 400000);
92 findHead();
93 Serial.printf("Sonraki kayit / Next record: slot %u, seq %lu\n", nextSlot, (unsigned long)nextSeq);
94 Serial.println("Komutlar / Commands: d = dump, e = erase");
95}
96
97void loop() {
98 static unsigned long last = 0;
99 if (millis() - last >= PERIOD) {
100 last = millis();
101 Record r = {nextSeq, (int16_t)analogRead(SENSOR), 0};
102 writeRecord(nextSlot, r);
103 nextSlot = (nextSlot + 1) % SLOTS;
104 nextSeq++;
105 }
106 if (Serial.available()) {
107 char c = Serial.read();
108 if (c == 'd') dumpCsv();
109 if (c == 'e') { eraseAll(); Serial.println("Silindi / Erased"); }
110 }
111}On the ESP32, I2C is on GPIO 21 (SDA) and GPIO 22 (SCL) by default and is started at 400 kHz with Wire.begin(SDA_PIN, SCL_PIN, 400000). Type d in the Serial Monitor to dump the records from oldest to newest as semicolon-separated CSV; you can copy this output straight into a spreadsheet. The e command erases the whole memory in about 3 seconds by writing 0xFF in 64-byte pages. The endTransmission(false) used for reading performs a repeated start without sending a stop; the AT24C256 accepts both methods. If you also want to store the time, replace the spare field with a Unix time read from an RTC module and grow the record to 12 bytes; since that doesn't divide 64 evenly, rounding records up to 16 bytes is the easiest option.
AT24C256 with Raspberry Pi Pico and MicroPython
MicroPython's machine.I2C class has writeto_mem() and readfrom_mem() functions that support 16-bit memory addresses directly; the addrsize=16 parameter makes the address go out as two bytes. The Pico's I2C0 unit is on GP4 (SDA) and GP5 (SCL). MicroPython has no buffer limit, so you can write a full 64-byte page; you still have to split at the page boundary in your code. Waiting 6 ms after a write is simpler than ACK polling and safe on every chip.
1# Raspberry Pi Pico + AT24C256 (MicroPython): sayfa sınırına uyan yazma ve okuma
2# Raspberry Pi Pico + AT24C256 (MicroPython): page-aware write and read
3from machine import I2C, Pin
4import time
5
6i2c = I2C(0, sda=Pin(4), scl=Pin(5), freq=400000) # I2C0: GP4 = SDA, GP5 = SCL
7ADDR = 0x50
8PAGE = 64
9
10def eeprom_write(addr, data):
11 while data:
12 n = min(len(data), PAGE - addr % PAGE) # sayfa sınırını geçme / never cross a page
13 i2c.writeto_mem(ADDR, addr, data[:n], addrsize=16)
14 time.sleep_ms(6) # yazma çevrimi en çok 5 ms / write cycle max 5 ms
15 addr += n
16 data = data[n:]
17
18def eeprom_read(addr, n):
19 return i2c.readfrom_mem(ADDR, addr, n, addrsize=16)
20
21print("I2C:", [hex(a) for a in i2c.scan()]) # 0x50 görünmeli / 0x50 should appear
22eeprom_write(100, b"Pico + AT24C256")
23print(eeprom_read(100, 15))Internal EEPROM vs AT24C256 vs SD card
| Feature | Internal EEPROM (Uno) | ESP32 Preferences (flash) | AT24C256 | SD card |
|---|---|---|---|---|
| Capacity | 1 KB | Default NVS partition about 20 KB | 32 KB (256 KB with 8 chips) | Gigabytes |
| Endurance | 100,000 | About 100,000 erases per flash sector (NVS spreads wear) | 1,000,000 | Depends on the card, its controller levels wear |
| Connection | None, inside the processor | None, inside the flash | I2C, 2 wires | SPI, 4 wires |
| Write speed | About 3.3 ms per byte | Fast, but sector erase is slow | 5 ms per page | Fast, in blocks |
| Current | No extra draw | No extra draw | A few mA, µA in standby | 20–100 mA while writing |
| Power loss | Safe | NVS is safe | Safe (a half-written page is caught by the CRC) | File system can be corrupted |
| Reading on a PC | No | No | No (via the serial port) | Yes, as files |
| Best for | A few settings | Settings and small values on the ESP32 | Settings, counters, small logs | Long-term logging of large data |
In short: for a few bytes of settings, the board's own EEPROM or Preferences on the ESP32 is enough. If the internal memory is too small, if you write data often or want several boards to use the same memory, the AT24C256 is the right choice; it's robust and draws little current. If you'll collect readings every second for months or want to open the data as a file on a computer, an SD card module is a better fit. If you need very frequent writes (several times a second, for example), look at FRAM chips with the same pinout as the AT24C256 (such as the FM24C256): they have no write delay and their endurance is counted in trillions.
Common problems and fixes
| Problem | Likely cause | Fix |
|---|---|---|
| The I2C scanner finds nothing | SDA/SCL swapped, no pull-ups or no power | Check the wires, add 4.7 kΩ pull-ups, measure VCC |
| Address isn't 0x50 | A0, A1, A2 jumpers in a different position | Use the address the scanner shows or move the jumpers to GND |
| The end of a long text ended up at the start | Page boundary crossed, data wrapped to the start of the same page | Split writes at multiples of 64 |
| Writes longer than 30 bytes corrupt on the Uno | The Wire buffer is 32 bytes | Send the data in 16- or 30-byte chunks |
| Some bytes lost in consecutive writes | A new write was sent before the 5 ms had passed | delay(5) or ACK polling after each write |
| Nothing gets written, but reading works | WP pin at VCC | Connect WP to GND or remove the jumper on the module |
| Every value reads 255 | The chip is blank (0xFF) or the wrong address is read | Write a value first, check your address calculation |
| A struct written on the Uno reads wrong on the ESP32 | The two boards align structs differently | Write fields byte by byte or use a packed struct |
AT24C256 project ideas
- Idea: Build a safe that takes a password from a keypad; store the password and the failed attempt counter in the AT24C256 so the lock doesn't forget even after a power cut.
- Idea: Keep the list of authorized cards for an RFID RC522 in external EEPROM; thousands of card IDs fit in 32 KB.
- Idea: Collect the last 4096 readings of a weather station in a ring buffer and transfer them to a computer as CSV once a week.
- Idea: Make a counter that logs a machine's running hours and number of starts every minute; an LED lights up when maintenance is due.
- Idea: On a device with an LCD menu, store user settings in a struct with a CRC; when you update the firmware, reset old settings automatically with the version number.
- Idea: Connect two AT24C256 chips on the same bus (0x50 and 0x51) and use one for settings and the other for logs.
With two wires and a few lines of code, the AT24C256 adds 32 KB of robust memory to your project; as long as you respect the page boundary and the 5 ms wait, it will run trouble-free for years. If you'd like to try an I2C connection with a familiar module first, check the wiring diagrams and code of the "Using an LCD Display with I2C" and "DS1302 RTC Clock Module Setup" projects in the BlueGrays app, and for bigger examples that work with stored data the "Smart Electronic Safe" and "ESP32 Temperature Logger (DHT22 + DS1307 RTC + microSD + OLED)" projects, step by step.
Frequently asked questions
How many bytes can the AT24C256 store?
The AT24C256 is a 256-kilobit EEPROM, which equals 32,768 bytes, or 32 KB. The memory is split into 512 pages of 64 bytes. With the A0, A1 and A2 address pins you can put eight chips on the same I2C bus for a total of 256 KB.
What is the I2C address of the AT24C256?
With A0, A1 and A2 all tied to GND, the address is 0x50. These pins set the last three bits of the address, so it ranges from 0x50 to 0x57. If you're not sure, run an I2C scanner sketch to find your module's address.
Why do you need to wait 5 ms after writing to the AT24C256?
The chip first takes the incoming data into an internal buffer and programs the cells after the I2C transfer ends; this internal write cycle takes up to 5 ms. During that time the chip doesn't respond to new commands and writes sent in between are lost. delay(5), or polling the chip's address until it answers, solves this.
How is the AT24C256 different from the Arduino's internal EEPROM?
The Arduino Uno's internal EEPROM is 1 KB with an endurance of about 100,000 writes per cell. The AT24C256 offers 32 KB and 1,000,000 writes, connects over I2C and can be expanded with more chips. The internal EEPROM needs no extra wiring but is small and wears out sooner.
Can the AT24C256 be used with an ESP32?
Yes. Power the module from 3V3 and connect SDA to GPIO 21 and SCL to GPIO 22. Since the ESP32's Wire buffer is 128 bytes, you can write a full 64-byte page. The ESP32 has no real internal EEPROM, so using an AT24C256 for frequently written data instead of flash protects the flash's lifetime.
Why can't I write more than 30 bytes to the AT24C256?
The limit isn't in the chip but in the Arduino Uno's Wire library: its buffer is 32 bytes, 2 of which go to the address, leaving 30 data bytes. Split longer data into 16- or 30-byte chunks and make sure no chunk crosses a 64-byte page boundary.
Projects to build after reading this
See all projects
Using LCD Screen with I2C
Give your Arduino its own screen and make it write its first message. The two-line LCD screen hooks up with just a few wires; a greeting appears on the top line, then a second message on the bottom…

DS1302 RTC Clock Module Setup
You get a small clock module running that never forgets the time, even when the Arduino is switched off.

DS1302 RTC Clock with LCD Display
A little desk clock that keeps the time even when the power goes out. The DS1302 clock module keeps time thanks to its own tiny battery; every second the Arduino reads it and writes the time and date…

Digital Clock with ESP32 and DS1307 RTC (I2C + LCD)
In this project, we display the time and date on a 16x2 I2C LCD screen using the DS1307 real-time clock (RTC) module. The DS1307 is a battery-backed RTC that maintains the time even if the ESP32 is powered off. Both modules share the same I2C bus (SDA/SCL), allowing us to learn how to control multiple devices using just two signal wires. Through this project, you will gain practical knowledge of the I2C communication protocol, RTC module operation, and dynamic data display on an LCD screen.

ESP32 Temperature Data Logger (DHT22 + DS1307 RTC + microSD + OLED)
Build a timed temperature and humidity logger with the ESP32! A DHT22 sensor reads temperature and humidity once a minute, and each reading is saved to a microSD card in CSV format with a real-time stamp from the DS1307 RTC module. The OLED display shows the latest temperature, humidity, timestamp and total number of records live, in large text.

Smart Electronic Safe
A small safe for your valuables that opens with a code. You type your four-digit code on the keypad; if it is right, the servo motor opens the lock, the green light comes on and the screen shows the…

Password Lock with 4x4 Keypad and LCD
A small electronic door lock that keeps out anyone who doesn't know the code. You press the hash key and type the code on the keypad; if it is right, the screen says access granted, the green LED…

ESP32 I2C LCD Display (16x2)
In this project we connect a 16x2 character LCD to the ESP32 over I2C and display text. With I2C, just 2 data pins (SDA and SCL) control the screen, instead of the 6+ pins a classic parallel connection wastes. The code prints a fixed message on the first line and a counter that goes up every second on the second. At startup an I2C scanner also prints the display's address to the Serial Monitor (usually 0x27 or 0x3F).
More articles
BlueGrays app
Build this circuit step by step on your phone
Wiring diagram, code and parts list on one screen. 750+ Arduino, ESP32, ESP8266, Pico, mBot and micro:bit projects ready to build.
Scan with your phone
Point your camera at the code and your phone's app store opens.
or open the store

