Writing and reading float using Arduino EEPROM

This post is just for a personal reminder after reading discussions from elsewhere about storing and reading float values to/from EEPROM with Arduino.


Writing negative float to EEPROM can be tricky, since EEPROM only recognises up to 8-bit values (see Tronixstuff  explanation), therefore it requires an additional algorithm to make it able to store negative and float.  the scheme is to use four bits of the ATmega328's EEPROM to store numerical parts of a float value. The function involved is union.

//union  value
typedef union{
  float flt;
  byte array[4];
} FloatConverter;

The code

You may grab the code here


Popular posts from this blog

Xeon LGA 771 di mobo LGA 775

LM35 Incubator with LCD 16x2 on Arduino