Monday, August 01, 2016

Filled Under: , ,

EEPROM Put

EEPROM EEPROM Put 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).

The purpose of this example is to show the EEPROM.put() method that writes data on EEPROM using also the EEPROM.update() that writes data only if it is different from the previous content of the locations to be written. The number of bytes written is related to the datatype or custom structure of the variable to be written.


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_put

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


/***
eeprom_put example. This shows how to use the EEPROM.put() method.
Also, this sketch will pre-set the EEPROM data for the
example sketch eeprom_get. Note, unlike the single byte version EEPROM.write(),
the put method will use update semantics. As in a byte
will only be written to the EEPROM if the data is actually
different. Written by Christopher Andrews 2015
Released under MIT licence.
***/ #include <EEPROM.h> struct MyObject {
float field1;
byte field2;
char name[10];
}; void setup() { Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
} float f = 123.456f; //Variable to store in EEPROM.
int eeAddress = 0; //Location we want the data to be put. //One simple call, with the address first and the object second.
EEPROM.put(eeAddress, f); Serial.println("Written float data type!"); /** Put is designed for use with custom structures also. **/ //Data to store.
MyObject customVar = {
3.14f,
65,
"Working!"
}; eeAddress += sizeof(float); //Move address to the next byte after float 'f'. EEPROM.put(eeAddress, customVar);
Serial.print("Written custom data type! \n\nView the example sketch eeprom_get to see how you can retrieve the values!");
} void loop() {
/* Empty loop */
}

Download:





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

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.