Simple float to EEPROM question?

Hi ya'll. I'm having a hard time trying to take a number like 30.89 and break it up into two chunks so that I can write it to two different addresses in EEPROM. I've tried playing all sorts of games with it like multiplying it by 100 then mapping between 0-255. I'm losing resolution that way.

I figure when I go to get it out of EEPROM I'll just take the contents of the first address and add it to the contents of the next divided by 100.

Any suggestions?

I used union:
Store:

      union split_float {
         uint16_t tegri[2];
         float    loatf;
       } sf;   

      for(uint8_t i = 0; i < 3; i++)
       {
        coeff[i] = ( arr[i][3] / arr[i][i]);
        sf.loatf = coeff[i];
        store_entry(( 20 + 2 * i), sf.tegri[0] );
        store_entry(( 21 + 2 * i), sf.tegri[1] );
       }

Recall:

           union split_float {
               uint16_t tegri[2];
               float    loatf;
             } sf;   

            for( uint8_t i = 0; i < 3; i++)
             {
              sf.tegri[0]  = recall_entry( 20 + 2 * i);   // HIGH WORD;
              sf.tegri[1]  = recall_entry( 21 + 2 * i);   // LOW WORD;

               Serial.print("\n\t");
               Serial.print(F("  A"));
               Serial.print( i, DEC);
               Serial.print(F(" =\t"));
               Serial.print( sf.loatf, 8);
             }

I will give it a try! I'll try to understand it too! It's more complicated than I thought but thank you so much.

Actually... I'm not to sure how to get that working. Where does my original number go? Please keep in mind I am really new to this. What is actually going on with union?

You could try looking at this page, there is an easier way to do it. http://playground.arduino.cc/Code/EEPROMLoadAndSaveSettings

That does seem easier. I'm trying it now.

Easier than previous post... yes. Anyone have a real simple way of just writing a single float to eeprom and then reading it back?

KellieFins: Easier than previous post... yes. Anyone have a real simple way of just writing a single float to eeprom and then reading it back?

I may be talking out of my sit-upon, but since float (and on Arduino double) are just 4 byte values, is there some way (bit or byte masking?) of just handling it as 4 bytes of data instead of a float value during the EEPROM write and read? I'm not familiar with the EEPROM library. What datatype are read() and write() expecting?

I'm not familiar with the EEPROM library. What datatype are read() and write() expecting?

Bytes. And the union IS the easiest way, but not Magician's union.

union stuff { float f; byte b[4]; }

stuff myStuff;

myStuff.f = 30.89;

Write mySyff.b to 4 addresses in EEPROM, and read them back out. Use myStuff.f.

Thanks to everyone for helping me out.

This is what I came up with…

#include <EEPROMEx.h>

void setup(){
  Serial.begin(115200);   
  delay(2000);
  
  Serial.print("Old coordinates: ");
  Serial.print(EEPROM.readFloat(0));
  Serial.print(", ");
  Serial.println(EEPROM.readFloat(4));
  Serial.println();

  EEPROM.writeFloat(0,34.10);
  EEPROM.writeFloat(4, -118.41);

  Serial.print("New coordinates: ");
  Serial.print(EEPROM.readFloat(0));
  Serial.print(", ");
  Serial.println(EEPROM.readFloat(4));
}

void loop(){
}