Chapter 16 – Experiment 09 – STORE DATA FOR LONG TERM

The EEPROM, Electrically Erasable Programmable Read-Only Memory, is a device that allows to save some data and avoid to erase them when the microcontroller is disconnected from the power source. In few words, we can store our data for a longer time.

With this experiment we will see how the EEPROM can be used to read data, write data and erase the EEPROM content. The only important thing that we have to consider is that the EEPROM used with the microcontroller has a life cycle of 10.000 erases, this means that we have to consider quite carefully how that device canshould be used. The most common use is to save configuration data of the program loaded in the microcontroller.

In one of the next experiments we will create a simple temperature data logger.

The experiment is composed of three parts, one for writing simple data to the EEPROM, one for reading the data that was written before and the last one to clean (literally erase) the memory of the EEPROM.

/*
* EEPROM Experiments – WMKIT Experiment n. 09
*
* This example code is in the public domain.
*
* clearEEPROM
* Sets all of the bytes of the EEPROM to 0.
*
* readEEPROM
* Read all of the bytes of the EEPROM from 0.
*
* writeEEPROM
* Write all of the bytes of the EEPROM from 0.
*
*/

#include <EEPROM.h>

void setup() {
Serial.begin(9600);

clearEEPROM();
writeEEPROM();
readEEPROM();

}

void readEEPROM() {
int i;

for (i = 0; i < 512; i++) {
value = EEPROM.read(i);

Serial.print(a);
Serial.print(“\t”);
Serial.print(valu e);
Serial.println();

delay(500);
}
}

void writeEEPROM()
{
int i;

for (i = 0; i < 512; i++) {
EEPROM.write(i, 0); // one byte can keep values from 0 to 255
}

// turn the LED on when we’re done
digitalWrite(13, HIGH);
}

void clearEEPROM()
{
// write a 0 to all 512 bytes of the EEPROM
for (int i = 0; i < 512; i++)
EEPROM.write(i, 0);

// turn the LED on when we’re done
digitalWrite(13, HIGH); // The led is on the microcontroller
}

void loop()
{
// There is nothing is here!!
}

1 comment

  1. [...] Chapter 14 – Experiment 07 – MATH IS FUN! Chapter 15 – Experiment 08 – INTERACTIVITY Chapter 16 – Experiment 09 – STORE DATA FOR LONG TERM Chapter 17 – Experiment 10 – FADING LEDS Chapter 19 – Experiment 11 – DISCO PARTY (RGB LED) [...]

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


istanbul evden eve nakliyat istanbul evden eve nakliyat istanbul evden eve nakliyat sarıyer evden eve nakliyat beylikdüzü evden eve nakliyat şişli evden eve nakliyat