How to Write float in external EEPROM

Hi,
I am doing one project with external EEPROM 24c32, where I want to read and write some float values in 24c32, I saw eeprom.put and eeprom.get but those are designed for internal eeprom and I want to write it on external one, so could any one can guide me what I should do?

so could any one can guide me what I should do?

Post the code you have so far. The process of storing a 4 byte float is barley more complicated than the process for storing a two byte int (which is barely more complicated than storing a single byte).

My entire code is too big its about 4000+ line, Basically with float storing , I am using our adc to read some values which get processed in arithmetic logic and generates current values which are in float! I want to use those float to draw a graph and store them! I can store analog values which i got after adc but this will force me to use those set of instructions 180 times (as graph I want to draw has 180 readings)and I think it will not be a great choice!
Again I didnt done code to store float as I dont no how to initiate it! I just have a array of float in my internal memory and want to free that space so using external eeprom!

Make a union and save the individual bytes:

union MyData{
  float myVar;
  byte theBytes[4];
};

Thanks bulldogLowell, I don't no how this union work I have to read some documentation about it, If you have any good links on it to study please refer them too, thanks for your help!

yatin:
Thanks bulldogLowell, I don't no how this union work I have to read some documentation about it, If you have any good links on it to study please refer them too, thanks for your help!

let's take the 32bit floating point format, you will recognize this binary number immediately:

01000000010010010000111111011011

yup you got it... it is 3.14159265359!!!

so run this code and see how the union works (bear in mind the endianness of the byte array and how I accommodated that in the for-loop)

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

void setup() 
{
  Serial.begin(9600);
  MyUnion myData;
  myData.f = 3.14159265359;  // I only ever assign a value to the float!
  Serial.println(myData.f);
  for (int i = 0; i < 4; i++)
  {
    printAllByte(myData.b[3-i]);  // but each element of the byte array has a value
  }
  Serial.println();

}

void loop() {
  // put your main code here, to run repeatedly:

}
void printAllByte(byte theByte)
{
  for(byte i = 0; i < 8; i++)
  {
    Serial.print(bitRead(theByte, 7-i)? "1" : "0");
  }
}

Bulldog is right on. The union is a great way to write non-byte data types to byte-oriented devices. It works well for sending floats or integers or longs across serial links as well.

The union is a great way to write non-byte data types to byte-oriented devices. It works well for sending floats or integers or longs across serial links as well.

In general, I prefer to use byte castes and multi byte writes with syntax like

xxxsend/write((uint8_t*)&whatever, size of(whatever))

However, in the case of writes to an external eeprom with page size considerations it is important to perform single byte writes unless page boundaries are taken into consideration. Here the union and the interation over the single bytes of the union is useful.

In the OP's case and Bulldog's formulation

for (byte i = 0; i < 4; i++)
  {
    writeByte(EEPROM_ADDRESS, i, myData.b[i]);
  }

where writeByte is a function to send a single byte to an address = i to a device address.

void writeByte(int device, unsigned int add, byte data)
{
  Wire.beginTransmission(device);
  Wire.write((int)(add >> 8)); // left-part of pointer address
  Wire.write((int)(add & 0xFF)); // and the right
  Wire.write(data);
  Wire.endTransmission();
  delay(5);//small delay for eeprom to save data
}

Libraries are often useful for multi byte writes to external eeproms which require page boundary management.
I use Jack Christensen's extEEPROM.h.

@BulldogLowell,@jrdoner,@cattledog
Thanks for such a awesome support and guidance from all of you! Now I was able to write these data as you mentioned with my existing library but now the question is how to read it in float form?
Cause if I write this code then i get overflow at serial! I didnt understand what I am missing?

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

void setup() 
{
  Serial.begin(9600);
  MyUnion myData;
  //myData.f = 3.14159265359;  // I only ever assign a value to the float!
  myData.b[0]=0b01000000;
   myData.b[1]=0b01001001;
    myData.b[2]=0b00001111;
     myData.b[3]=0b11011011;
     
  Serial.println(myData.f);
}

yatin:
@BulldogLowell,@jrdoner,@cattledog
Thanks for such a awesome support and guidance from all of you! Now I was able to write these data as you mentioned with my existing library but now the question is how to read it in float form?
Cause if I write this code then i get overflow at serial! I didnt understand what I am missing?

union MyUnion{

float f;
  byte b[4];
};

void setup()
{
  Serial.begin(9600);
  MyUnion myData;
  //myData.f = 3.14159265359;  // I only ever assign a value to the float!
  myData.b[0]=0b01000000;
  myData.b[1]=0b01001001;
    myData.b[2]=0b00001111;
    myData.b[3]=0b11011011;
   
  Serial.println(myData.f);
}

watch your endian-ness

  Serial.begin(9600);
  MyUnion myData;
  //myData.f = 3.14159265359;  // I only ever assign a value to the float!
  myData.b[3]=0b01000000
   myData.b[2]=0b01001001;
    myData.b[1]=0b00001111;
     myData.b[0]=0b11011011;
     
  Serial.println(myData.f, 6);  //EDITED

01000000010010010000111111011011

yup you got it... it is 3.14159265359!!!

Sorry if I am too noob but how you calculate a float in byte format?

yatin:
Sorry if I am too noob but how you calculate a float in byte format?

Well, it was a joke.

You have the union part understood, now?

Yes I understand that part but not how float represented in byte format!
Means how it get converted because even if we use decimal to binary conversion we need decimal point for these no. then how we convert these here?

then how we convert these here?

The union manages that. You don't have to convert anything.

All the union does is let you treat one set of bytes as another kind of bytes. It does no conversion or alteration of the data.

Yes I understand that part but not how float represented in byte format!

The format is controlled by a standard called IEEE 754. When you read these documents, you'll be happy that the
Arduino does all the work for you.

This document explains the IEEE 754 floating-point standard and there is always Wikipedia.

When you break the float into bytes, or reconstruct the float from bytes, the "endianess" is processor specific. The the 16 bit Arduino's are little endian.

Thanks @ cattledog for that awesome guide now I know exactly what happen inside it thanks to community for such a great help!

Guys, I have a group of variable that I want to store in EEprom like one word, ex current=12.32

ex current=12.32 ( float 4 byte), voltage=9960(2 byte), and IR=12.35(float 4 byte)

Now like we do in string if i merge all data and make one packet and send it same while receive it will make my code easy, but can I save these? will union do it for me or do I need to use some thing else?

yatin:
...will union do it for me or do I need to use some thing else?

You don't need to save the labels, the Arduino doesn't care at all about that. Just think about saving values to EEPROM addresses. Then retrieve values from EEPROM addresses.