loading
The arduino due lacks an eeprom. This instructable adds one and allows you to store values in non volatile memory that will survive an arduino firmware update.

Step 1: Breadboarding

There are some really good instructions here:

http://www.hobbytronics.co.uk/arduino-external-eeprom

I just followed them.

The photo shows the breadboarded circuit. pins 1 to 4 and pin 7 are grounded. pin 8 is connected to the 3.3V supply on the due board.

The yellow (pin 6) and white (pin 5) wires connected to the i2c SDA (data) and SCL (clock) pins on the due board (numbered 20 and 21).

Step 2: Code Time.

Here are some snippets of code that I use in my sketches.

Firstly, include the Wire library headers somewhere near the top of your sketch:

/* Use 24LC256 EEPROM to save settings */
#include <Wire.h>


Then add some functions to read and write bytes from the EEPROM (I only care about individual bytes but there is a page write feature in the chip too). Note there is a macro definition of 0x50.. this is the address of the chip on the i2c bus (you can connect more than one i2c thingies on an i2c bus and select which one you want to talk to by changing the address).

/* These two functions help us write to the 24LC256 EEPROM chip */
#define EEPROM_ADDR 0x50
void EEPROM_write(unsigned int addr,byte data) {
  int rdata = data;
  Wire.beginTransmission(EEPROM_ADDR);
  Wire.write((int)(addr >> 8));       // MSB
  Wire.write((int)(addr & 0xFF));     // LSB
  Wire.write(rdata);
  Wire.endTransmission();
  //Serial.print("EEPROM write: addr: ");
  //Serial.print(addr);
  //Serial.print(" ");
  //Serial.println(data);
  delay(5);
}

byte EEPROM_read(unsigned int addr) {
  byte data = 0xFF;
  Wire.beginTransmission(EEPROM_ADDR);
  Wire.write((int)(addr >> 8));       // MSB
  Wire.write((int)(addr & 0xFF));     // LSB
  Wire.endTransmission();
  Wire.requestFrom(EEPROM_ADDR,1);
  if (Wire.available()) data = Wire.read();
  //Serial.print("EEPROM read: addr: ");
  //Serial.print(addr);
  //Serial.print(" ");
  //Serial.println(data);
  delay(5);
  return data;
}



You can uncomment the Serial.print(...) lines if you want to see some debug output.

In arduinos setup() function you start the wire library and can read in initial values.
Here I read in two bytes (flags and max_cc), two words (lean_min and lean_max) and an array of words sd_max[3]:

    // read values saved in the EEPROM
    Wire.begin();
    flags=EEPROM_read(0);
    max_cc=EEPROM_read(1);
    lean_min=word(EEPROM_read(3),EEPROM_read(2));
    lean_max=word(EEPROM_read(5),EEPROM_read(4));
    for(int j=0;j<3;j ) {
      sd_max[j]=word(EEPROM_read(7 j*2),EEPROM_read(6 j*2));
    }


Here's the bit of code that writes them into the EEPROM:

         EEPROM_write(0,flags);
         EEPROM_write(1,max_cc);
         EEPROM_write(2,lowByte(lean_min));
         EEPROM_write(3,highByte(lean_min));
         EEPROM_write(4,lowByte(lean_max));
         EEPROM_write(5,highByte(lean_max));
         for(int j=0;j<3;j ) {
           EEPROM_write(6 j*2,lowByte(sd_max[j]));
           EEPROM_write(7 j*2,highByte(sd_max[j]));
         }


Thats about it really.
 

Step 3: Wire It Up

Wire it onto some veroboard to screw into an enclosure and the jobs done.
<p>Great news: EEPROM works out of the box with RADDS / DUE. Couldn't be much easier and cheaper (1US$)</p><p>Ordered this item: <a href="https://www.aliexpress.com/item/AT24C256-Serial-EEPROM-I2C-Interface-EEPROM-Data-Storage-Module-PIC-NEW/32484028731.html" rel="nofollow">https://www.aliexpress.com/item/AT24C256-Serial-EEPROM-I2C-Interface-EEPROM-Data-Storage-Module-PIC-NEW/32484028731.html</a><br>bridged WP, A0, A1, A2 with the jumpers and wired everything to the I2C (top right).</p>
Would it be possible to show the underside of the vero board, if it has any additional wires?
<p>I made perfboard schematic for it...</p>
I've put it inside something now. Sorry. From what I remember though the wiring is exactly the same as the breadboard picture but adapted for veroboard. Best wishes. Martin.
<p>Cool!</p><p>Here are some pictures of my horrible soldering...</p>
<p>Sweet, love it.</p>
<p>G'Day, - it is reccomended that i2c buses have pullup resistors (typically 2k2 - 10k range) installed on SDA and SCL. If anyone is having issues with copying the cabling shown in this instructable, the absence of pullup resistors could be one of the causes.</p>
Hi, yes I didn't wire any pull ups in. This is because I understood some pull ups to be built into the due board. However, there seems to be some controversy on if they are of the right value.

About This Instructable

15,243views

14favorites

License:

Bio: http://www.reverbnation.com/bizarre
More by mdtevans:DigiX/Arduino DUE ARM math library software setup Arduino Due Guitar ADC Input and DAC Output Mixer Adding an 24LC256 EEPROM to the Arduino Due 
Add instructable to: