Gravity__I2C_EEPROM_Data_Storage_Module_SKU__DFR0117-DFRobot

Introduction

Arduino has a small amount of data storage space, The Arduino UNO has 32k. It doesn't have enough space if you want to store a lot of data. Therefore, we need to add an EEPROM Data Storage Module to increase its storage space. The EEPROM Data Storage Module transmit data to Arduino UNO using I2C Protocol. It used 24LC256 256K I2C CMOS Serial EEPROM provided by Microchip Techonogy Inc. 24LC256 is a 32K x 8(256Kbit) Serial Electrically Erasable Programmable Read - Only Memory. It can also be used with the Interface shield board by I2C on Board.

Specification

Pin Definition

Mark Name Function
+ VCC +2.5V to 5.5V
- GND Ground
C SCL I2C Serial Clock
D SDA I2C Serial Data

Address True Table

Gravity-I2C EEPROM Storage Module Address True Table

Connection Diagram

Gravity-I2C EEPROM Storage Module Connect Arduion UNO

Sample Code

/*
  *  Use the I2C bus with EEPROM 24LC64
  *  Sketch:    eeprom.pde
  *
  *  Author: hkhijhe
  *  Date: 01/10/2010
  *
  *
  */

  #include <Wire.h> //I2C library



  void i2c_eeprom_write_byte( int deviceaddress, unsigned int eeaddress, byte data ) {
    int rdata = data;
    Wire.beginTransmission(deviceaddress);
    Wire.write((int)(eeaddress >> 8)); // MSB
    Wire.write((int)(eeaddress & 0xFF)); // LSB
    Wire.write(rdata);
    Wire.endTransmission();
  }

  // WARNING: address is a page address, 6-bit end will wrap around
  // also, data can be maximum of about 30 bytes, because the Wire library has a buffer of 32 bytes
  void i2c_eeprom_write_page( int deviceaddress, unsigned int eeaddresspage, byte* data, byte length ) {
    Wire.beginTransmission(deviceaddress);
    Wire.write((int)(eeaddresspage >> 8)); // MSB
    Wire.write((int)(eeaddresspage & 0xFF)); // LSB
    byte c;
    for ( c = 0; c < length; c++)
      Wire.write(data[c]);
    Wire.endTransmission();
  }

  byte i2c_eeprom_read_byte( int deviceaddress, unsigned int eeaddress ) {
    byte rdata = 0xFF;
    Wire.beginTransmission(deviceaddress);
    Wire.write((int)(eeaddress >> 8)); // MSB
    Wire.write((int)(eeaddress & 0xFF)); // LSB
    Wire.endTransmission();
    Wire.requestFrom(deviceaddress,1);
    if (Wire.available()) rdata = Wire.read();
    return rdata;
  }

  // maybe let's not read more than 30 or 32 bytes at a time!
  void i2c_eeprom_read_buffer( int deviceaddress, unsigned int eeaddress, byte *buffer, int length ) {
    Wire.beginTransmission(deviceaddress);
    Wire.write((int)(eeaddress >> 8)); // MSB
    Wire.write((int)(eeaddress & 0xFF)); // LSB
    Wire.endTransmission();
    Wire.requestFrom(deviceaddress,length);
    int c = 0;
    for ( c = 0; c < length; c++ )
      if (Wire.available()) buffer[c] = Wire.read();
  }




  void setup()
  {
    char somedata[] = "this is data from the eeprom"; // data to write
    Wire.begin(); // initialise the connection
    Serial.begin(9600);
    i2c_eeprom_write_page(0x50, 0, (byte *)somedata, sizeof(somedata)); // write to EEPROM

    delay(10); //add a small delay

    Serial.println("Memory written");
  }

  void loop()
  {
    int addr=0; //first address
    byte b = i2c_eeprom_read_byte(0x50, 0); // access the first address from the memory

    while (b!=0)
    {
      Serial.print((char)b); //print content to serial port
      addr++; //increase address
      b = i2c_eeprom_read_byte(0x50, addr); //access an address from the memory
    }
    Serial.println(" ");
    delay(2000);

  }

Results

Gravity-I2C EEPROM Storage Module Code Decay Tdst Results

More Documents

FAQ

For any questions, advice or cool ideas to share, please visit the DFRobot Forum.