- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to read data from EEPROM in Arduino?
Arduino Uno has 1 kB of EEPROM storage. EEPROM is a type of non-volatile memory, i.e., its contents are preserved even after power-down. Therefore, it can be used to store data that you want to be unchanged across power cycles. Configurations or settings are examples of such data.
Example
We will see how to read data from EEPROM in this example. We will be walking through an inbuilt example in Arduino. The EEPROM examples can be accessed from − File → Examples → EEPROM.
We will look at the eeprom_read example. It is quite straightforward, thanks to the EEPROM library.
We begin with the inclusion of the library.
#include <EEPROM.h>
Next, some global variables are defined.
int address = 0; byte value;
Within the setup, we just initialize Serial.
void setup() { // initialize serial and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for native USB port only } }
In the loop, we use the EEPROM.read() function to read one byte of data. We print that byte on the Serial Monitor, and then increment the address to read the next byte. If we reach the end of EEPROM memory, we go back to the beginning (address = 0).
void loop() { // read a byte from the current address of the EEPROM value = EEPROM.read(address); Serial.print(address); Serial.print("\t"); Serial.print(value, DEC); Serial.println(); address = address + 1; if (address == EEPROM.length()) { address = 0; } delay(500); }
As you can see, this was quite straightforward. If you need to read value from a specific address, you can just provide that address as the argument in EEPROM.read(). The only limitation of EEPROM.read() is that it can read only one byte of data at a time, and therefore, you need to iterate in order to get the required number of bytes.
- Related Articles
- How to write data into EEPROM with Arduino?
- How to update existing data in EEPROM with Arduino?
- How to get data of any size from the EEPROM with Arduino?
- How to put data of any size in the EEPROM using Arduino?
- How to clear the EEPROM with Arduino?
- Read a file from SD Card connected to Arduino
- How to read data from .csv file in Java?
- Digital Read in Arduino
- How to read the data from a file in Java?
- How to read/write data from/to .properties file in Java?
- How to read data from scanner to an array in java?
- How to read data from *.CSV file using JavaScript?
- How to read data from a file using FileInputStream?
- How to read data from JSON array using JavaScript?
- How to read data in from a file to String using java?
