Arduino “having11” Guy
Published © GPL3+

How to Use I2C EEPROM

Expand your board's storage with an I2C-enabled EEPROM chip.

BeginnerProtip1 hour5,479
How to Use I2C EEPROM

Things used in this project

Hardware components

Microchip AT24C02C 2KB I2C EEPROM
×1
Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1

Software apps and online services

Arduino IDE
Arduino IDE
Eagle

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
CNC Router

Story

Read more

Schematics

EEPROM

Pins

Code

Read and Write

C/C++
#include <Wire.h>

#define ADDR_Ax 0b000 //A2, A1, A0
#define ADDR (0b1010 << 3) + ADDR_Ax

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Wire.begin();
  writeI2CByte(0, 1);
  Serial.println(readI2CByte(0));
}

void loop() {
  // put your main code here, to run repeatedly:
  
}

void writeI2CByte(byte data_addr, byte data){
  Wire.beginTransmission(ADDR);
  Wire.write(data_addr);
  Wire.write(data);
  Wire.endTransmission();
}

byte readI2CByte(byte data_addr){
  byte data = NULL;
  Wire.beginTransmission(ADDR);
  Wire.write(data_addr);
  Wire.endTransmission();
  Wire.requestFrom(ADDR, 1); //retrieve 1 returned byte
  delay(1);
  if(Wire.available()){
    data = Wire.read();
  }
  return data;
}

Credits

Arduino “having11” Guy

Arduino “having11” Guy

70 projects • 443 followers
IoT and embedded systems enthusiast. Also an intern at Hackster.io who loves working on projects and sharing knowledge.

Comments