Hello!
When the Arduino tutorial on EEPROM said that the EEPROM can only sustain 100,000 writing cycles. Does that mean 100,000 writing cycles per cell, or the whole EEPROM? I have a code that stores IR signals in the EEPROM:
#include <Sleep_n0m1.h>
#include <avr/power.h>
#include <MomentaryButton.h>
#include <Streaming.h>
// Project 28 - IR Remote
#include <EEPROM.h>
#include <IRremote.h>
Sleep sleep;
int irRxPin = 9;
MomentaryButton button(7);
MomentaryButton sendButton(4);
int f = 38; // 40, 36, 38
IRrecv irrecv(irRxPin);
IRsend irsend;
typedef unsigned long dword;
dword prev = 0;
decode_results results;
int codeLength = 0;
int currentCode = 0;
void setup()
{
Serial.begin(9600);
Serial << "0-9 to set code memory, s - to send" << endl;
irrecv.enableIRIn();
setCodeMemory(0);
irrecv.blink13(1);
button.setup();
sendButton.setup();
}
void loop()
{
button.check();
sendButton.check();
f = map(analogRead(A1), 0, 1023, 36, 40);
if (button.wasClicked())
{
prev = millis();
char ch = map(analogRead(A0), 0, 1023, 0, 7) + 48;
if (ch >= '0' && ch <= '9')
{
setCodeMemory(ch - '0');
}
}
else if(sendButton.wasClicked())
{
sendIR();
}
if (irrecv.decode(&results))
{
prev = millis();
storeCode();
irrecv.resume();
}
//if (millis() - prev >= 30000) autoSleep();
}
void setCodeMemory(int x)
{
currentCode = x;
Serial << "Set current code memory to: " << currentCode << endl;
irrecv.resume();
}
void storeCode()
{
// write the code to EEPROM, first byte is length
int startIndex = currentCode * (RAWBUF + 1);
int len = results.rawlen - 1;
EEPROM.write(startIndex, (unsigned byte)len);
for (int i = 0; i < len; i++)
{
if (results.rawbuf[i] > 255)
{
EEPROM.write(startIndex + i + 1, 255);
}
else
{
EEPROM.write(startIndex + i + 1, results.rawbuf[i]);
}
}
Serial << "Saved code, length: " << len << endl;
Serial << "Code (usec on, usec off): " << endl;
printCode(results.rawbuf, results.rawlen);
}
void sendIR()
{
// construct a buffer from the saved data in EEPROM and send it
int startIndex = currentCode * (RAWBUF + 1);
int len = EEPROM.read(startIndex);
unsigned int code[RAWBUF];
for (int i = 0; i < len; i++)
{
int pulseLen = EEPROM.read(startIndex + i + 2);
if (i % 2)
{
code[i] = pulseLen * USECPERTICK + MARK_EXCESS;
}
else
{
code[i] = pulseLen * USECPERTICK - MARK_EXCESS;
}
}
irsend.sendRaw(code, len, f);
Serial << "Sent code length: " << len << endl;
}
void printCode(volatile word* code, byte length){
for(byte i = 0; i < length; i++){
if (i & 1) Serial << code[i] << ", ";
else if (!(i & 1) && i < length - 1) Serial << code[i] << "," << endl;
else if (!(i & 1) && i == length - 1) Serial << code[i] << endl;
}
}
void autoSleep(){
delay(100);
sleep.pwrDownMode(); //set sleep mode
ADCSRA = 0;
PRR = 255;
MCUCR = _BV (BODS) | _BV (BODSE); // turn on brown-out enable select
MCUCR = _BV (BODS); // this must be done within 4 clock cycles of above
sleep.sleepInterrupt(0, LOW);
power_all_enable();
delay(100);
}
I disconnected everything before uploading a new sketch for under a minute. When I removed everything, the LED on pin 13 was constantly lit (due to unconnected IR RX pin, and enabling the blink13). My code writes to the EEPROM every time it receives an IR signal. Does that mean my code was constantly writing to the EEPROM, and I could have destroyed forever (I did not test)?
Thanks!