Friday, January 13, 2012

sensorNET - utility to initialize arduino EEPROM

On the sensorNEt project I'm saving data to EEPROM and, during development, I have the need to test programming with the EEPROM as it comes from factory, i.e. with all bytes set to 0xFF. because I write and clear the memory meny times, I needed a fast program to re-initialize the EEPROM to 0xFF. Yes it's simple but it's always a good sketch to keep on the utilities folder (besides, it displays a nice progress line on the serial monitor!!.

Here it goes:

/*this sketch initializes EEPROM with 255 for all addresses*/
/*for atMEGA 328P */
#include <EEPROM.h>
void setup(){
  int counter = 0;
  //write a new "." every counter_step
  int counter_step = 32;
  int current_step = 32;
  for (int i = 0; i < 1024; i++){
    EEPROM.write(i, 0xFF);
    if (counter == current_step){
      current_step = current_step + counter_step;
  Serial.println("Complete! EEPROM reinitialized!");
void loop(){
//nothing to do here! 

1 comment:

fatmi said...
This comment has been removed by a blog administrator.