Editorial Solution

After carefully reading the task and GIF, we have to print all values from EEPROM to the serial terminal.

Also, we have to print 16 values per row, with the address and value in hex format.

So first, we need to know the size of EEPROM in Arduino UNO, we can get it by using the EEPROM.h library with EEPROM.length() function.

Once we get the length, i.e. 1024 Bytes for Arduino UNO, we need to print all location data. Also as per the task, we have to ensure 

  • Print 16 bytes per row.
  • Display addresses and data in hexadecimal format

Code

#include <EEPROM.h>


// Define the size of EEPROM (varies depending on microcontroller)
const int EEPROM_SIZE = 512; // For Arduino Uno, update based on your board's EEPROM size.
const int BYTES_PER_ROW = 16; // Bytes to display per row


void setup() {
  Serial.begin(9600);
  while (!Serial);


  Serial.println("EEPROM Memory Map:");
  Serial.println("Address   | Data (in Hex)");
  Serial.println("-------------------------");
  printEEPROMMap();
}


void loop() {
  // No operations in the loop.
}


void printEEPROMMap() {
  for (int i = 0; i < EEPROM_SIZE; i += BYTES_PER_ROW) {
    // Print starting address of the row
    Serial.print("0x");
    if (i < 16) Serial.print("0"); // Formatting for single-digit addresses
    Serial.print(i, HEX);
    Serial.print("       | ");


    // Print the data in hexadecimal format
    for (int j = 0; j < BYTES_PER_ROW; j++) {
      if (i + j < EEPROM_SIZE) {
        byte data = EEPROM.read(i + j);
        if (data < 16) Serial.print("0"); // Ensure two digits
        Serial.print(data, HEX);
        Serial.print(" ");
      } else {
        // If out of bounds, print placeholder
        Serial.print("-- ");
      }
    }
    Serial.println();
  }
}


Code Explanation

As we can see in the code, we have added EEPROM.h to use EEPROM-based functions. 

EEPROM Mapping Logic: void printEEPROMMap()

  • Outer loop: Iterates in steps of 16 (row size).
  • Inner loop: Reads and prints individual bytes in each row, ensuring two-digit formatting. If values are one digit, then we are explicitly adding ‘0’ in the beginning in order to print the values as per the given format.

Output

The below output is of the EEPROM (after writing random values)

 

The below output is of the Formatted EEPROM. (Writing 0xFF to all EEPROM locations)

 

You can also try the following

  • You can write the code to randomly add values to the EEPROM, and then see how the memory is printed.
  • You can also try resetting the EEPROM by setting each address with 0xFF and watching the memory map.

Precautions:

  • Be careful while writing to EEPROM as it has limited write cycles.
  • Writing time is 3.3ms per byte, consider this while writing your code.



 


 

 

Submit Your Solution