How to write a float value to an external EEPROM?

Hi Guys 'n Gals,

I finally figured out how to understand the process of writing to an external EEPROM.
I learned some more about functions and it feeds my needs to learn more. :slight_smile:

Unfortunately, I can only write byte sized variable to the EEPROM.
I have to write a Float sized variable and I've Googled somewhat without finding the right method.
However, I found information about the "union", apparently a way to split float/double sized variables into 4 byte sized parts. I am playing around with that but actually writing the 4 bytes the way I would do with one byte is not clear to me.
Do I have to repeat the write cycle 4 times? Or is it possible to use one write cycle, writing 4 bytes?

void writeEEPROM(int EPMaddress, byte DATA, int i2caddress) //variable "DATA" is beeing created

{ Wire.beginTransmission(i2caddress);
  Wire.write((int)(EPMaddress >> 8));      //writes the MSB
  Wire.write((int)(EPMaddress & 0xFF));    //writes the LSB
  Wire.write(DATA); //loads the provided variable DATA 8 bits)
  Wire.endTransmission();       //ends transmission to EEprom}

I found this page with a search for "arduino write float to external I2C eeprom".

Yes, I know that topic and I learned somewhat of everything mentioned.
(allong with other topics fot that matter.)
It doesn't cover it all.

I hate to leave loose ends.
Therefore;
I eventually found a way to save floats into an (external) 24LC256 EEPROM.
While giving up hope in finding the right solution, I looked for the alternative, saving Integers into the EEPROM.
Thereby I encountered this topic: How store int type on 24LC256 ? - Arduino Due - Arduino Forum which turned out to be the solution to my original problem. :slight_smile:
(which proves to me that googling with some phrases and words not always points in the right direction or solution, if other words were used)

In this topic, the libraries of MartinL, ExtEEPROM, and EEPROManything2 do the trick.

A good explanation along with the code helped me out.
I filtered out the unnecessary parts for my project and I'm off.

So the next time someone runs into issues writing a float to the external EEPROM 24LC256 and searches with those phrases, they might end up here...
And here's the deal.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.