Skip to content

Instantly share code, notes, and snippets.

@gutierrezps
Created April 26, 2017 16:45
Show Gist options
  • Save gutierrezps/08ad43695bf920d1c32c2c34328171ad to your computer and use it in GitHub Desktop.
Save gutierrezps/08ad43695bf920d1c32c2c34328171ad to your computer and use it in GitHub Desktop.
Arduino EEPROM test
/******************************************************
Arduino EEPROM Test
by Gutierrez PS 2017
http://github.com/gutierrezps
Based on John Boxall's idea of testing the lifespan
of Arduino's internal EEPROM:
http://tronixstuff.com/2011/05/11/discovering-arduinos-internal-eeprom-lifespan/
EEPROM is tested by writing a certain value to
all addresses, and then comparing the value read.
Three values are used: 170, 85 and 0 at last to
format it.
The program stops at the first mismatch, showing
the failed address and the value read.
******************************************************/
#include <EEPROM.h>
void eeprom_test()
{
unsigned int size = EEPROM.length();
unsigned int addr = 0;
unsigned char write_data = 0, read_data = 0, fail = 0;
Serial.println("Starting EEPROM test");
Serial.print("EEPROM size: ");
Serial.println(size);
for(char step = 1; step <= 3; step++)
{
switch(step)
{
case 1: write_data = 170; break;
case 2: write_data = 85; break;
default: write_data = 0;
}
Serial.print("Writing ");
Serial.println((int) write_data);
for(addr = 0; addr < size; addr++) EEPROM.write(addr, write_data);
for(addr = 0; addr < size; addr++)
{
read_data = EEPROM.read(addr);
if(read_data != write_data) break;
}
if(read_data != write_data)
{
Serial.print("FAIL at address ");
Serial.print(addr);
Serial.print(" - wrote ");
Serial.print((int) write_data);
Serial.print(", read ");
Serial.println((int) read_data);
return;
}
Serial.println("PASS");
}
Serial.println("EEPROM test finished without errors");
}
void setup()
{
Serial.begin(115200);
eeprom_test();
}
void loop()
{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment