Go back

Pico I2C EEPROM Read/Write: Simulate Non-Volatile Memory in Your Browser

Introduction

Have you ever wanted to store data that survives a power cycle? In embedded systems, EEPROM (Electrically Erasable Programmable Read-Only Memory) is the go‑to for non‑volatile storage. Today, we’ll simulate an I2C EEPROM read/write operation using the Raspberry Pi Pico—all inside your browser with Velxio. No hardware required!

We’ll write a few bytes to the EEPROM, read them back, and verify they match. Along the way, you’ll learn about the I2C protocol, the Wire library, and how to debug serial output. Let’s dive in!

Circuit Walkthrough

Open the example in Velxio and you’ll see the circuit on the canvas. The main components are:

Circuit diagram of pico-i2c-eeprom-rw on the Velxio simulator canvas

Wiring Details

From (Pico pin)To (Component)Wire Color
D12 (GPIO12)Red LED anodeRed (#ff4444)
D10 (GPIO10)Green LED anodeGreen (#00cc00)
Red LED cathodeGND.1Black (#000000)
Green LED cathodeGND.1Black (#000000)

Note: In this simulation, the I2C EEPROM is virtual—it’s built into the Velxio environment. The LEDs are used as visual indicators: the red LED blinks during a write, the green LED during a read. In a real circuit, you’d connect the EEPROM’s SDA and SCL lines to the Pico’s I2C pins (GPIO4 and GPIO5 by default, but here we use D12 and D10 for the LEDs).

Code Walkthrough

Let’s break down the Arduino sketch. The code uses the Wire library to communicate over I2C.

Includes and Definitions

#include <Wire.h>

#define EEPROM_ADDR 0x50

We include the Wire library and define the EEPROM’s I2C address as 0x50. This is a common address for 24LC series EEPROMs.

Helper Functions

void eepromWrite(byte memAddr, byte data) {
  Wire.beginTransmission(EEPROM_ADDR);
  Wire.write(memAddr);
  Wire.write(data);
  Wire.endTransmission();
  delay(5); // EEPROM write cycle
}

byte eepromRead(byte memAddr) {
  Wire.beginTransmission(EEPROM_ADDR);
  Wire.write(memAddr);
  Wire.endTransmission();
  Wire.requestFrom(EEPROM_ADDR, 1);
  return Wire.available() ? Wire.read() : 0xFF;
}

Setup

void setup() {
  Serial.begin(115200);
  delay(500);
  Wire.begin();
  Serial.println("=== Pico I2C EEPROM Test ===");
  Serial.println();

  // Write 8 bytes
  Serial.println("Writing 8 bytes...");
  byte testData[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xCA, 0xFE, 0xBA, 0xBE};
  for (int i = 0; i < 8; i++) {
    eepromWrite(i, testData[i]);
    Serial.print("  ["); Serial.print(i);
    Serial.print("] = 0x");
    if (testData[i] < 16) Serial.print('0');
    Serial.println(testData[i], HEX);
  }
  Serial.println();

  // Read back
  Serial.println("Reading back...");
  int pass = 0;
  for (int i = 0; i < 8; i++) {
    byte val = eepromRead(i);
    Serial.print("  ["); Serial.print(i);
    Serial.print("] = 0x");
    if (val < 16) Serial.print('0');
    Serial.print(val, HEX);
    if (val == testData[i]) {
      Serial.println(" OK");
      pass++;
    } else {
      Serial.print(" FAIL (expected 0x");
      Serial.print(testData[i], HEX);
      Serial.println(")");
    }
  }

  Serial.println();
  Serial.print("Result: ");
  Serial.print(pass);
  Serial.println("/8 passed");
}

Loop

void loop() {
  delay(10000);
}

Nothing to do repeatedly—the test runs once in setup(). The loop just delays to keep the serial output visible.

Key Concepts

Common Pitfalls & Debugging Tips

  1. Wrong I2C Address: Double‑check the EEPROM address. Common addresses are 0x50 to 0x57 (depending on A0/A1/A2 pins).
  2. Missing Pull‑up Resistors: In real hardware, SDA and SCL need pull‑up resistors (4.7kΩ). Velxio’s virtual EEPROM handles this internally.
  3. Serial Monitor Baud Rate: Ensure the serial monitor is set to 115200 baud. Mismatch causes gibberish.
  4. Write Cycle Timing: If you skip the delay(5), the EEPROM may not store the data correctly. Increase the delay if needed.
  5. LEDs Not Blinking: Check the wiring. The red LED is connected to D12, green to D10. Both cathodes go to GND.

Suggested Extensions

Try It Yourself!

Ready to experiment? Open the live example in Velxio:

Launch Pico I2C EEPROM R/W

Click the Run button in the editor toolbar to compile and simulate. Watch the serial output in the console—you should see all 8 bytes read back successfully.

Velxio editor toolbar with compile and run controls

Use the canvas toolbar to zoom, pan, and inspect the circuit.

Velxio canvas toolbar above the simulation viewport

Need to add more components? Open the component picker to browse parts.

Velxio component picker modal browsing parts by category

Happy simulating!


Share this post on:
David Montero

Written by

David Montero

Creator of Velxio, the open-source circuit and Arduino simulator.

GitHub velxio.dev

Related posts


Previous Post
Pico SPI Loopback: Test Your RP2040's Serial Communication
Next Post
Read a Virtual DS1307 RTC with Raspberry Pi Pico I2C