EEPROM space still available

Hello,

I am new to all of this, so please bear with me.

Is there a way to find out how much EEPROM memory is still free after loading some stuff into it, so a decision can be made what else to load or leave out?

This question may have been answered already but I could only find answers for total size of memory.

Thanks
Skiddy

Nope, since you put it there, you should know how much is left.

Besides, any sketch can write any EEPROM bit, there is no management like in the stack.

Since you have to tell it what address of the EEPROM to write to, and you know how big the EEPROM is, wouldn't your code know this?

I mean, you can just read through the entire EEPROM looking for empty addresses (unwritten EEPROM locations read as 0xFF), but I don't see how that's useful - your code should know where it's been putting things...

I'm wondering if you're meaning to ask about some other form of memory?

Dump the content of the EEPROM and try to figure out.

const char pgString[] PROGMEM = "A string in PROGMEM";

void dump(byte* adr, unsigned int len = 0x80);
void dump_P(byte* adr, unsigned int len = 0x80);
void dump_E(byte* adr, unsigned int len = 0x80);

void setup() {
  Serial.begin(115200);
  dump_E((byte*)0, 0x0400); // 1K standard
//  Serial.println("");
//  dump_P((byte*)pgString, 128);
//  Serial.println("");
//  dump((byte*)0x100, 128);
}

void loop() {}

char hexNibble(byte val) {
  val &= 0xF;
  if (val > 9) {
    return val + 'A' - 10;
  } else {
    return val + '0';
  }
}

void hexByte(char* store, byte val) {
  store[1] = hexNibble(val);
  store[0] = hexNibble(val >> 4);
}

char* toHex(unsigned int val, byte adrTyp = 0) {
  static char textBuf[9];
  if (adrTyp) {
    switch (adrTyp) {
      case 1: textBuf[0] = ' '; break;
      case 2: textBuf[0] = 'r'; break;
      case 3: textBuf[0] = 'p'; break;
      case 4: textBuf[0] = 'e'; break;
    }
    textBuf[1] = ' ';
    hexByte(textBuf + 2, (byte)(val >> 8));
    hexByte(textBuf + 4, (byte)val);
    textBuf[6] = ':';
    textBuf[7] = ' ';
    textBuf[8] = 0;
  } else {
    hexByte(textBuf, (byte)val);
    textBuf[2] = ' ';
    textBuf[3] = 0;
  }
  return textBuf;
}

void dumpGen(byte (*func)(byte*), byte typ, byte* adr, unsigned int len) {
  int lines = (len + 15) >> 4;
  bool moreThanOneLine = (lines != 1);
  byte bytes;
  for (; lines--; adr += 16, len -= 16) {
    Serial.write(toHex((unsigned int)adr, typ));
    for (bytes = 0; bytes < 16; bytes++) {
      if (bytes < len) {
        Serial.write(toHex((*func)(&adr[bytes])));
      } else if (moreThanOneLine) {
        Serial.print(F("   "));
      }
    }
    Serial.print(F("'"));
    for (bytes = 0; bytes < 16; bytes++) {
      if (bytes < len) {
        byte cVal = (*func)(&adr[bytes]);
        Serial.write((cVal & 0x7F) < 0x20 ? '.' : cVal);
      }
    }
    Serial.print(F("'\r\n"));
  }
}

byte ramReadByte(byte* adr) {
  return *adr;
}

byte flashReadByte(byte* adr) {
  return pgm_read_byte_near(adr);
}
byte eepromReadByte(byte* adr) {
  return eeprom_read_byte(adr);
}

void dump(byte* adr, unsigned int len) {
  dumpGen(ramReadByte, 2, adr, len);
}

void dump_P(byte* adr, unsigned int len) {
  dumpGen(flashReadByte, 3, adr, len);
}

void dump_E(byte* adr, unsigned int len) {
  dumpGen(eepromReadByte, 4, adr, len);
}
e 0000: FF FF FF FF 00 FF FF FF FF FF FF FF FF FF FF FF 'ÿÿÿÿ.ÿÿÿÿÿÿÿÿÿÿÿ'
e 0010: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 'ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ'
e 0020: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 'ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ'
e 0030: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 'ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ'
e 0040: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 'ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ'