Arduino IDE Clear EEPROM on Upload?

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
HooctAwnFonix
 
Posts: 77
Joined: Tue Sep 13, 2011 11:47 am

Arduino IDE Clear EEPROM on Upload?

Post by HooctAwnFonix »

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.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Arduino IDE Clear EEPROM on Upload?

Post by adafruit_support_rick »

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.

HooctAwnFonix
 
Posts: 77
Joined: Tue Sep 13, 2011 11:47 am

Re: Arduino IDE Clear EEPROM on Upload?

Post by HooctAwnFonix »

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.

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

Re: Arduino IDE Clear EEPROM on Upload?

Post by mike31416 »

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

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”