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
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
which format is:
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:
Here the output of the command
Now see at the content of the file /tmp/eeprom.dump
that is exactly what you previously wrote in the EEPROM!