Arduino IDE Clear EEPROM on Upload?
Moderators: adafruit_support_bill, adafruit

Arduino IDE Clear EEPROM on Upload?

by HooctAwnFonix on Thu Jan 17, 2013 1:47 pm

I have a sketch that changes an EEPROM variable on first boot. I would like to reset that variable every time the code is uploaded from the Arduino IDE. Is there a way to do this? EEPROM is otherwise retained during uploads.

I'm trying to avoid uploading a separate sketch to clear EEPROM before uploading my real sketch.
HooctAwnFonix
 
Posts: 77
Joined: Tue Sep 13, 2011 11:47 am
Location: Cambridge, MA

Re: Arduino IDE Clear EEPROM on Upload?

by adafruit_support_rick on Thu Jan 17, 2013 8:01 pm

HooctAwnFonix wrote:EEPROM is otherwise retained during uploads.

Do you mean that you want to clear ONLY that one variable, and not the rest of eeprom?

I don't think that Arduino has an option for preserving/erasing eeprom on load. For that, you would have to use avrdude directly.

adafruit_support_rick
 
Posts: 13751
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: Arduino IDE Clear EEPROM on Upload?

by HooctAwnFonix on Thu Jan 17, 2013 11:38 pm

Ah too bad. I was writing code for someone who only uses the Arduino IDE and needed that functionality. I guess I'll just have them run the clear EEPROM sample sketch between uploads.

Thanks for the reply.
HooctAwnFonix
 
Posts: 77
Joined: Tue Sep 13, 2011 11:47 am
Location: Cambridge, MA

Re: Arduino IDE Clear EEPROM on Upload?

by mike31416 on Fri Jan 18, 2013 7:49 am

Hello,

The AVRDUDE option -y will use the last 4 bytes of the EEPROM to track the number of times a new sketch is uploaded. The -Y option lets you set the initial value of the tracking counter. Perhaps you can use the -y option in conjunction with another EEPROM value to detect that an upload has been performed (save the tracking value in another location and compare the two on application startup).

The AVRDUDE option -e will erase both the flash and EEPROM. Note, there is a bit in hfuse that will disable the EEPROM erase while using this option. I believe the default is set to allow the EEPROM erase.

Be aware that there is a finite number of times you can reprogram EEPROM. The atmega168 allows 10,000 flash and 100,000 EEPROM erases. Might seem to be a lot, but if your code goes wild it can wear it out.

Mike
User avatar
mike31416
 
Posts: 126
Joined: Wed Aug 26, 2009 12:06 pm