Storing floats and double in the internal EEPROM of Arduino

In this beginner-friendly tutorial,
We will explore how to read and write different types of data to the internal EEPROM memory of an Arduino board (ATmega328P).

We'll use the EEPROM library available in the Arduino IDE. Specifically, we'll cover how to store and retrieve bytes, characters, text strings, floats, doubles, and other multi-byte data structures like structs.

Contents of the Article / Video

  1. Arduino EEPROM Structure
  2. Finding out Arduino EEPROM length
  3. Storing a byte in Arduino EEPROM
  4. Storing a Text String in Arduino EEPROM
  5. Storing a float/double value in Arduino EEPROM
  6. Storing a struct in Arduino EEPROM

Online Article + Source Codes

Reading and Writing Characters, Floats and structs to Internal EEPROM Memory of Arduino

By the end of this guide, you'll be able to easily interact with your Arduino’s EEPROM for saving data

Thanks for sharing (too bad it’s not readable right here).

You could improve your Arduino conformity by using camel case throughout your codes. That’s the recommended capitalization.

2 Likes

There's a little mistake on the web page:


On an Uno R3 (and AFAIK this is true for all 8 bit AVRs with Arduino IDE)

[Edit added the following]
This might mislead a beginner into thinking that loss of precision is caused by the use of EEPROM.

1 Like

good catch. That's totally wrong.

I usually use either PascalCase or c_style type variable names

thanks for finding the mistake,i corrected it

I have already written the article at my website and i also have a video.It was not possible to post the video here

I had a look and saw that you changed the size, but didn't change the paragraph about precision.

What's your rationale for saying what you say about loss of precision when storing floats?

My take on it is that what you say is true of floats in general, but has nothing to do with whether or not they are stored / retrieved from EEPROM. IMO that paragraph could be deleted with no information loss, and it would reduce the potential for beginner confusion. Am I missing something?

float(2bytes) -- do you mean that a variable declared as float will hold 16-bit (2bytes) data? If not, please clarify the meanig of: float(2bytes).

double(4bytes) -- do you mean that a variable declared as double (UNO Board) will hold 32-bit (2bytes) data? If not, please clarify the meaning of: double(4bytes).

Yeah,you are correct, i removed it

1 Like

you mean this is impossible then :slight_smile: ?

I think you are talking about this:

I didn't write that text. It's a screen snip of the website link in post #0.

1 Like

Nice tutorial. You should add a methode to identify cleared eeprom (everything is 0xff) or malformed eeprom (checksum does not match) --> default values, when eeprom content is invalid.

Ok!

I have understood now that you have not written that text. Sorry for the inconvenience.

it was a mistake on my part,the text is removed from the original article

I am new to this forum,some times youtube links remain as just links .Some forums have the ability to embed youtube videos in the menu bar itself.

I understand

It still feels that you just want to drive traffic to your website and away from the forum which is not so well regarded here.

You should consider giving a bit more of your tutorial here and for those who want to deep dive on your content then they would go see your site for example. Just a thought.

But the banner said that your last post was 2 years ago.

You might want to look at this How to get the best out of this forum before you proceed any further.

If this is indeed a tutorial then it should not be placed in the forum showcase section. It should be posted in the Software section and entitled something like "Proposed tutorial for how to read and write different types of data to the internal EEPROM".

Then you get feedback and modify your code until satisfied with it. Then you flag your post to the moderators and request it be transferred to the Tutorials section of the forum.

Note on an Arduino Uno, and many other AVR processors, there is no distinction between a float and a double, they are both the same thing.

that's what @Grumpy_Mike is talking about