Loading...

How to read your Arduino built-in EEPROM

by

 

1. Introduction

In the Arduino UNO board, the MCU is an ATMega328P. Such as many other MCU,  it has a FLASH memory, an EEPROM memory and a SRAM.

The Flash memory is the place where your sketch is stored. Its size is 32 KB of which 0.5 KB used by bootloader.

The EEPROM is a like a tiny harddisk, where you can store information or settings that may be retrieved later by another sketch or between resets. Its size is 1KB

In this tutorial you'll learn how to read the Arduino UNO built-in EEPROM using Arduino ISP.

 

2. Write data in the built-in EEPROM

In order to read values from the EEPROM, you first need to write them!

You can use the EEPROM library, already present in the Arduino IDE, and upload the eeeprom_write example sketch. This sketch stores values read from Analog input 0 into the EEPROM.

We can also edit the sketch enabling Serial communication, so we can print out in the Serial Monitor the values read from A0.

 

3. Read the built-in EEPROM using a sketch

You can use a sketch to read the content of the built-in EEPROM of the ATMega328p itself.
As already done in the previous step, you can use the EEPROM library, and upload the eeprom_read  example sketch. 
After upload,  you can see on the serial monitor the value previously saved.

 

4. Read the built-in EEPROM using Arduino ISP

Another way to read the EEPROM of an ATMega328p on an Arduino UNO board, is to use the Arduino ISP. First of all we need to connect the Arduino ISP to the Arduino UNO board itself by the ICSP connector.

After that, you need to use the avrdude command.

In order to use the avrdude command, we need to supply the  full path to avrdude. It is located in the Arduino program folder:

  • for Linux and Windows: it is located in “hardware/tools/avr/bin” inside the Arduino folder
  • for Mac: it is located in “Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin”

‚ÄčExplanation of the parameters can be found here.

The relevant part is the one following the -U

-U eeprom:r:/tmp/eeprom.hex:i

 

which format is:

-U memtype:op:filename[:format]

 

you are telling to avrdude that you want to read (r) the EEPROM (eeprom) and write it to eeprom.hex file using Intel Hex format. You can use also other format, e.g. hexadecimal (:h), raw (:r), decimal (:d), and so on; more info about other format are available here

So if you want to read the EEPROM and write it in decimal format to eeprom.dump file, the complete command to use is:

avrdude -C ../etc/avrdude.conf -p m328p -c arduinoisp   -D -U eeprom:r:/tmp/eeprom.dump:d

 

Here the output of the command

avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.02s
avrdude: Device signature = 0x1e950f
avrdude: reading eeprom memory:
Reading | ################################################## | 100% 10.56s
avrdude: writing output file "/tmp/eeprom.dump"
avrdude: safemode: Fuses OK
avrdude done.  Thank you.

 

Now see at the content of the file /tmp/eeprom.dump

2,2,47,94,146,186,226,226,226,226,226,226,226,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2 .. [cut]..

 

that is exactly what you previously wrote in the EEPROM!