Skip to content

AnduinoEEPROM

Brian Carbonette edited this page Feb 27, 2017 · 1 revision

AnduinoEEPROM The Anduino shield comes equipped with an M24256 32Kb I2C connected EEPROM and corresponding library to provide a simple interface for interacting with the additional storage. This is especially handy since the Arduino Due doesn't ship with onboard standard EEPROM like other Arduino models. Some stats at a glance...

  •  32Kb of EEPROM storage
    
  •  64byte Page size
    
  •  1Mhz bus speed
    
  •  4 million write cycles!
    

Installing the library includes some common operations and procedures around EEPROM and abstracts the details of communicating via I2C

In your sketch be sure to include the EEPROM Library by adding

#include "AnduinoEEPROM.h"

to the top of your sketch as well as

AnduinoEEPROM EEPROM = AnduinoEEPROM();
EEPROM.begin();

to properly create your EEPROM object and initialize the chip.

To get started quickly check out the example sketches available by navigating to the Arduino IDE toolbar, select File>>Examples>>AnduinoEEPROM.

begin()

  •  Initializes the I2C bus 
    
  •  The Anduino Shield is using SDA1 and SCL1 (Wire library utilizes 'Wire1')
    
  •  Sets bus speed to 1Mhz
    

write(unsigned int eeaddress, byte data)

  •  Writes one byte of data to address defined by eeaddress
    
  • The address range of the EEPROM is 0x0000 - 0x7FFF (0-32767)
EEPROM.write(3, 0xFF); //writes 0xFF to address 0x03

read(unsigned int eeaddress)

  • Returns one byte of data located at supplied address
Serial.print(EEPROM.read(3), HEX); //Prints the data stored at address 0x03 to terminal

writePage(unsigned int eeaddress, byte* buffer, int pageSize)

  • Writes one page sized chunk worth of data starting at the supplied address
    
  • To accomplish successive page writes just increase eeaddress in pageSize'd increments
    
  • 64byte maximum pageSize 
    
  • Just pass a pointer to your buffer[pageSize] of data to be written 
    
  • Faster than successive write() calls 
    
EEPROM.writePage(0, bufferPtr, 64);
 //writes all 64bytes contained in buffer pointed to by bufferPtr to page at address 0

readPage(unsigned int eeaddress, byte buffer[], int pageSize)

  •  Reads one page sized chunk worth of data starting at supplied address
    
  •  Pass the destination buffer[pageSize]
    
  •  64byte maximum PageSize
    
  •  Faster than successive read() calls
    
/*read each page and store in bufferPage, inc to next page in memory
starting at eeaddress until the requsted numPages have been read*/
for(int i=eeaddress; i<numPages*PAGE_SIZE; i+=PAGE_SIZE)
{       
    readPage(i, bufferPage, PAGE_SIZE);
}

printToTerm(unsigned int eeaddress, int numPages)

  •  Prints 64byte wide pages of EEPROM to terminal 
    
  •  Starts at supplied eeaddress 
    
  •  Prints successive pages to terminal for supplied numPages - 512max
    
  •     EEPROM.printToTerm(0, numPages);
        Abbreviated output:
    
    
        0x0-0x3F:   0x0  0x1  0x2  0x3  0x4  0x5  0x6  0x7  0x8  0x9  0xA  0x...   
        0x40-0x7F:  0x0  0x0  0x0  0x0  0x0  0x0  0x0  0x0  0x0  0x0  0x0  0x...  
        0x80-0xBF:  0x0  0x0  0x0  0x0  0x0  0x0  0x0  0x0  0x0  0x0  0x0  0x...   
        0xC0-0xFF:  0x0  0x0  0x0  0x0  0x0  0x0  0x0  0x0  0x0  0x0  0x0  0x...
        0x...
    

eraseContents(unsigned int eeaddress, int numPages)

  • Initializes successive pages starting at supplied eeaddress to all 0's

     eraseContents(0, 512); //erases entire EEPROM initializing all data to 0x00
    

storeImg(unsigned int eeaddress)

  • Stores an image supplied in GIMP format to EEPROM parsing the image pixel by pixel
  • loadLogoEEPROM example sketch in ArduinoIDE will read the image from EEPROM and display on LCD display