Archivo de la categoría: ARDUINO

Writting and reading an EEPROM memory via I2C bus with Arduino

In this exercise I will show how to write and read an EEPROM memory by I2C interface with an Arduino Uno and simulating with Proteus.

First I had to download the Arduino Uno library for Proteus from the Arduino’s web site ( Now you can start simulating Arduino with Proteus.

In Proteus I’ve built the next scheme with the 24LC256 EEPROM memory of Microchip, the Arduino Uno and a LCD display to see the data stored in the memory:



Here is the source code I’ve compiled with the Arduino software to load in the microcontroller:

#include <LiquidCrystal.h>
#include <Wire.h>

LiquidCrystal lcd(6, 7, 8, 9, 10, 11);

void i2c_eeprom_write_page( int deviceaddress, unsigned int eeaddresspage, byte *data, byte length )

Wire.write((int)(eeaddresspage >> 8)); // MSB
Wire.write((int)(eeaddresspage & 0xFF)); // LSB
byte c;
for ( c = 0; c < length; c++)

byte i2c_eeprom_read_byte( int deviceaddress, unsigned int eeaddress )
byte rdata = 0xFF;
Wire.write((int)(eeaddress >> 8)); // MSB
Wire.write((int)(eeaddress & 0xFF)); // LSB
if (Wire.available()) rdata =;
return rdata;

void setup()
char somedata[] = “Hola CIFPN1”; //cadena a escribir
Wire.begin(); //es obligatorio inicializar la conexion
i2c_eeprom_write_page(0x50, 0, (byte *)somedata, sizeof(somedata)); //escribir la cadena al principio de la EEPROM; comentar esta linea para probar que la memoria es no volatil
delay(10); //pequeña pausa despues de escribir en la memoria
lcd.begin(16, 2);
void loop()
int addr=0; //direccion a leer
byte b = i2c_eeprom_read_byte(0x50, 0); //acceso a la primera posicion de memoria
while (b!=0)

Serial.print((char)b); //enviar al ordenador
addr++; //siguiente direccion
b = i2c_eeprom_read_byte(0x50, addr); //acceso a posicion de memoria

And there are some pics of the result of the simulation with Proteus.

First I show you the empty memory:


And then you can see the memory have loaded the data and those data are shown in the LCD and in the virtual terminal.



You can download all the files of this exercise clicking here:!zsICyC7Y!HekaH682jvVyeagJRkTSqHLSveKhMdabPSfDrVePfjo