Monday, August 01, 2016

Filled Under: , ,

EEPROM Read

EEPROM EEPROM Read library
The microcontroller on the Arduino boards have 512 bytes of EEPROM: memory whose values are kept when the board is turned off (like a tiny hard drive).

This example illustrates how to read the value of each byte EEPROM using the EEPROM.read() function, and how to print those values to the serial window of the Arduino Software (IDE).




Step 1: What You Need?

1 x Arduino Board ( Arduino UNO used in this tutorial) 


Don't have components? Don't worry. Just click the component's name. 



Step 2: Build Your Circuit.


Step 3: Upload The Code.

1. Select the Arduino board type: Select Tools >> Board >> Select your correct Arduino board used.

2. Find the port number by accessing device manager on Windows. See the section Port (COM&LPT) and look for an open port named "Arduino Uno (COMxx)". If you are using a different board, you will find a name accordingly. What matters is the xx in COMxx part. In my case, it's COM3. So my port number is 3.


Select the right port: Tools >> Port >> Select the port number.

3. You can find this code in the example of Arduino IDE.
Select File >> Examples >> EEPROM >> eeprom_read

Click press the "upload" button (see the button with right arrow mark).

/*
* EEPROM Read
*
* Reads the value of each byte of the EEPROM and prints it
* to the computer.
* This example code is in the public domain.
*/ #include <EEPROM.h> // start reading from the first byte (address 0) of the EEPROM
int address = 0;
byte value; 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
}
} 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(); /***
Advance to the next address, when at the end restart at the beginning. Larger AVR processors have larger EEPROM sizes, E.g:
- Arduno Duemilanove: 512b EEPROM storage.
- Arduino Uno: 1kb EEPROM storage.
- Arduino Mega: 4kb EEPROM storage. Rather than hard-coding the length, you should use the pre-provided length function.
This will make your code portable to all AVR processors.
***/
address = address + 1;
if (address == EEPROM.length()) {
address = 0;
} /***
As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an
EEPROM address is also doable by a bitwise and of the length - 1. ++address &= EEPROM.length() - 1;
***/ delay(500);
}


Download:





Sources:https://www.arduino.cc/en/Tutorial/EEPROMRead

Unknown

Author & Editor

My Robot Education Sdn. Bhd. (Robotedu.my) was founded in 2015 as the first robotics education centre in Malaysia to provide Arduino-based robotics courses for youths. Our vision is to be able to provide robotics education to every youth in Malaysia.

0 comments:

Post a Comment

 

  • Copyright © Arduino Tutorial ™ is a registered trademark.
    Designed by Templateism. Hosted on Blogger Templates.